88#include < hx/Telemetry.h>
99#include < hx/Unordered.h>
1010#include < hx/OS.h>
11+ #include < mutex>
1112
1213
1314#if defined(HXCPP_CATCH_SEGV) && !defined(_MSC_VER)
@@ -45,7 +46,7 @@ namespace hx
4546const char * EXTERN_CLASS_NAME = " extern" ;
4647
4748#ifdef HXCPP_STACK_IDS
48- static HxMutex sStackMapMutex ;
49+ static std::mutex sStackMapMutex ;
4950typedef UnorderedMap<int , StackContext *> StackMap;
5051static StackMap sStackMap ;
5152#endif
@@ -245,9 +246,10 @@ void StackContext::onThreadAttach()
245246 #ifdef HXCPP_STACK_IDS
246247 mThreadId = __hxcpp_GetCurrentThreadNumber ();
247248
248- sStackMapMutex .Lock ();
249- sStackMap [mThreadId ] = this ;
250- sStackMapMutex .Unlock ();
249+ {
250+ std::lock_guard<std::mutex> guard (sStackMapMutex );
251+ sStackMap [mThreadId ] = this ;
252+ }
251253 #endif
252254
253255 #ifdef HXCPP_DEBUGGER
@@ -302,9 +304,10 @@ void StackContext::onThreadDetach()
302304 #endif
303305
304306 #ifdef HXCPP_STACK_IDS
305- sStackMapMutex .Lock ();
306- sStackMap .erase (mThreadId );
307- sStackMapMutex .Unlock ();
307+ {
308+ std::lock_guard<std::mutex> guard (sStackMapMutex );
309+ sStackMap .erase (mThreadId );
310+ }
308311 mThreadId = 0 ;
309312 #endif
310313
@@ -317,18 +320,17 @@ void StackContext::onThreadDetach()
317320void StackContext::getAllStackIds ( QuickVec<int > &outIds )
318321{
319322 outIds.clear ();
320- sStackMapMutex .Lock ();
323+
324+ std::lock_guard<std::mutex> guard (sStackMapMutex );
325+
321326 for (StackMap::iterator i=sStackMap .begin (); i!=sStackMap .end (); ++i)
322327 outIds.push (i->first );
323- sStackMapMutex .Unlock ();
324328}
325329
326330StackContext *StackContext::getStackForId (int id)
327331{
328- sStackMapMutex .Lock ();
329- StackContext *result = sStackMap [id];
330- sStackMapMutex .Unlock ();
331- return result;
332+ std::lock_guard<std::mutex> guard (sStackMapMutex );
333+ return sStackMap [id];
332334}
333335#endif
334336
0 commit comments