From ab4dcf243a4664e4d72ae2fcfc594d2f5c25bf7c Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 5 Nov 2018 11:27:36 -0800 Subject: [PATCH] Add a mutex around Lime Bytes --- project/src/utils/Bytes.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/project/src/utils/Bytes.cpp b/project/src/utils/Bytes.cpp index b5aeab134..5d063b80c 100644 --- a/project/src/utils/Bytes.cpp +++ b/project/src/utils/Bytes.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,6 +13,7 @@ namespace lime { static bool useBuffer = false; static std::map hadValue; static std::map usingValue; + static Mutex mutex; inline void _initializeBytes () { @@ -60,6 +62,8 @@ namespace lime { Bytes::~Bytes () { + mutex.Lock (); + if (hadValue.find (this) != hadValue.end ()) { hadValue.erase (this); @@ -78,6 +82,8 @@ namespace lime { } + mutex.Unlock (); + } @@ -111,6 +117,8 @@ namespace lime { if (size != length || (length > 0 && !b)) { + mutex.Lock (); + if (size <= 0) { if (b) { @@ -159,6 +167,8 @@ namespace lime { } + mutex.Unlock (); + } } @@ -166,6 +176,8 @@ namespace lime { void Bytes::Set (value bytes) { + mutex.Lock (); + if (val_is_null (bytes)) { if (usingValue.find (this) != usingValue.end ()) { @@ -206,6 +218,8 @@ namespace lime { } + mutex.Unlock (); + } @@ -220,12 +234,16 @@ namespace lime { } else { + mutex.Lock (); + if (usingValue.find (this) != usingValue.end ()) { usingValue.erase (this); } + mutex.Unlock (); + b = 0; length = 0; @@ -278,7 +296,9 @@ namespace lime { } + mutex.Lock (); hadValue[this] = true; + mutex.Unlock (); return bytes;