Skip to content

Commit 21ac9fa

Browse files
author
Aidan Lee
committed
recursive mutex for special object and state change locks
1 parent 862b923 commit 21ac9fa

1 file changed

Lines changed: 25 additions & 25 deletions

File tree

src/hx/gc/Immix.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ static int sgTimeToNextTableUpdate = 1;
393393

394394

395395

396-
HxMutex *gThreadStateChangeLock=0;
397-
HxMutex *gSpecialObjectLock=0;
396+
std::recursive_mutex *gThreadStateChangeLock=nullptr;
397+
std::recursive_mutex *gSpecialObjectLock=nullptr;
398398

399399
class LocalAllocator;
400400
enum LocalAllocState { lasNew, lasRunning, lasStopped, lasWaiting, lasTerminal };
@@ -2500,7 +2500,7 @@ InternalFinalizer::InternalFinalizer(hx::Object *inObj, finalizer inFinalizer)
25002500
mFinalizer = inFinalizer;
25012501

25022502
// Ensure this survives generational collect
2503-
AutoLock lock(*gSpecialObjectLock);
2503+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
25042504
sgFinalizers->push(this);
25052505
}
25062506

@@ -2797,7 +2797,7 @@ void GCSetFinalizer( hx::Object *obj, hx::finalizer f )
27972797
if (((unsigned int *)obj)[-1] & HX_GC_CONST_ALLOC_BIT)
27982798
throw Dynamic(HX_CSTRING("set_finalizer - invalid const object"));
27992799

2800-
AutoLock lock(*gSpecialObjectLock);
2800+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28012801
if (f==0)
28022802
{
28032803
FinalizerMap::iterator i = sFinalizerMap.find(obj);
@@ -2817,7 +2817,7 @@ void GCSetHaxeFinalizer( hx::Object *obj, HaxeFinalizer f )
28172817
if (((unsigned int *)obj)[-1] & HX_GC_CONST_ALLOC_BIT)
28182818
throw Dynamic(HX_CSTRING("set_finalizer - invalid const object"));
28192819

2820-
AutoLock lock(*gSpecialObjectLock);
2820+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28212821
if (f==0)
28222822
{
28232823
HaxeFinalizerMap::iterator i = sHaxeFinalizerMap.find(obj);
@@ -2835,13 +2835,13 @@ void GCDoNotKill(hx::Object *inObj)
28352835
if (((unsigned int *)inObj)[-1] & HX_GC_CONST_ALLOC_BIT)
28362836
throw Dynamic(HX_CSTRING("doNotKill - invalid const object"));
28372837

2838-
AutoLock lock(*gSpecialObjectLock);
2838+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28392839
sMakeZombieSet.insert(inObj);
28402840
}
28412841

28422842
hx::Object *GCGetNextZombie()
28432843
{
2844-
AutoLock lock(*gSpecialObjectLock);
2844+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28452845
if (sZombieList.empty())
28462846
return 0;
28472847
hx::Object *result = sZombieList.pop();
@@ -2850,13 +2850,13 @@ hx::Object *GCGetNextZombie()
28502850

28512851
void RegisterWeakHash(HashBase<String> *inHash)
28522852
{
2853-
AutoLock lock(*gSpecialObjectLock);
2853+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28542854
sWeakHashList.push(inHash);
28552855
}
28562856

28572857
void RegisterWeakHash(HashBase<Dynamic> *inHash)
28582858
{
2859-
AutoLock lock(*gSpecialObjectLock);
2859+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
28602860
sWeakHashList.push(inHash);
28612861
}
28622862

@@ -3153,12 +3153,12 @@ class GlobalAllocator
31533153
{
31543154
if (!gThreadStateChangeLock)
31553155
{
3156-
gThreadStateChangeLock = new HxMutex();
3157-
gSpecialObjectLock = new HxMutex();
3156+
gThreadStateChangeLock = new std::recursive_mutex();
3157+
gSpecialObjectLock = new std::recursive_mutex();
31583158
}
31593159
// Until we add ourselves, the collector will not wait
31603160
// on us - ie, we are assumed ot be in a GC free zone.
3161-
AutoLock lock(*gThreadStateChangeLock);
3161+
std::lock_guard<std::recursive_mutex> lock(*gThreadStateChangeLock);
31623162
mLocalAllocs.push(inAlloc);
31633163
// TODO Attach debugger
31643164
}
@@ -3181,7 +3181,7 @@ class GlobalAllocator
31813181

31823182
LocalAllocator *GetPooledAllocator()
31833183
{
3184-
AutoLock lock(*gThreadStateChangeLock);
3184+
std::lock_guard<std::recursive_mutex> lock(*gThreadStateChangeLock);
31853185
for(int p=0;p<LOCAL_POOL_SIZE;p++)
31863186
{
31873187
if (mLocalPool[p])
@@ -3614,7 +3614,7 @@ class GlobalAllocator
36143614

36153615
#ifndef HXCPP_SINGLE_THREADED_APP
36163616
hx::EnterGCFreeZone();
3617-
gThreadStateChangeLock->Lock();
3617+
gThreadStateChangeLock->lock();
36183618
hx::ExitGCFreeZoneLocked();
36193619

36203620
result = GetNextFree(inRequiredBytes);
@@ -3663,7 +3663,7 @@ class GlobalAllocator
36633663
mCurrentRowsInUse += result->GetFreeRows();
36643664

36653665
#ifndef HXCPP_SINGLE_THREADED_APP
3666-
gThreadStateChangeLock->Unlock();
3666+
gThreadStateChangeLock->unlock();
36673667
#endif
36683668

36693669

@@ -4214,15 +4214,15 @@ class GlobalAllocator
42144214

42154215
void *GetIDObject(int inIndex)
42164216
{
4217-
AutoLock lock(*gSpecialObjectLock);
4217+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
42184218
if (inIndex<0 || inIndex>hx::sIdObjectMap.size())
42194219
return 0;
42204220
return hx::sIdObjectMap[inIndex];
42214221
}
42224222

42234223
int GetObjectID(void * inPtr)
42244224
{
4225-
AutoLock lock(*gSpecialObjectLock);
4225+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
42264226
hx::ObjectIdMap::iterator i = hx::sObjectIdMap.find( (hx::Object *)inPtr );
42274227
if (i!=hx::sObjectIdMap.end())
42284228
return i->second;
@@ -4864,12 +4864,12 @@ class GlobalAllocator
48644864
{
48654865
if (inLocked)
48664866
{
4867-
gThreadStateChangeLock->Unlock();
4867+
gThreadStateChangeLock->unlock();
48684868

48694869
hx::PauseForCollect();
48704870

48714871
hx::EnterGCFreeZone();
4872-
gThreadStateChangeLock->Lock();
4872+
gThreadStateChangeLock->lock();
48734873
hx::ExitGCFreeZoneLocked();
48744874
}
48754875
else
@@ -4888,7 +4888,7 @@ class GlobalAllocator
48884888
this_local = (LocalAllocator *)(hx::ImmixAllocator *)hx::tlsStackContext;
48894889

48904890
if (!inLocked)
4891-
gThreadStateChangeLock->Lock();
4891+
gThreadStateChangeLock->lock();
48924892

48934893
for(int i=0;i<mLocalAllocs.size();i++)
48944894
if (mLocalAllocs[i]!=this_local)
@@ -5406,7 +5406,7 @@ class GlobalAllocator
54065406
}
54075407

54085408
if (!inLocked)
5409-
gThreadStateChangeLock->Unlock();
5409+
gThreadStateChangeLock->unlock();
54105410
#else
54115411
#ifdef HXCPP_SCRIPTABLE
54125412
hx::gMainThreadContext->byteMarkId = hx::gByteMarkID;
@@ -5900,7 +5900,7 @@ class LocalAllocator : public hx::StackContext
59005900
EnterGCFreeZone();
59015901
#endif
59025902

5903-
AutoLock lock(*gThreadStateChangeLock);
5903+
std::lock_guard<std::recursive_mutex> lock(*gThreadStateChangeLock);
59045904

59055905
#ifdef HX_WINDOWS
59065906
mID = 0;
@@ -6127,7 +6127,7 @@ class LocalAllocator : public hx::StackContext
61276127
if (!mGCFreeZone)
61286128
CriticalGCError("GCFree Zone mismatch");
61296129

6130-
AutoLock lock(*gThreadStateChangeLock);
6130+
std::lock_guard<std::recursive_mutex> lock(*gThreadStateChangeLock);
61316131
mReadyForCollect.Reset();
61326132
mGCFreeZone = false;
61336133
#endif
@@ -7039,13 +7039,13 @@ void __hxcpp_set_finalizer(Dynamic inObj, void *inFunc)
70397039

70407040
void __hxcpp_add_member_finalizer(hx::Object *inObject, _hx_member_finalizer f, bool inPin)
70417041
{
7042-
AutoLock lock(*gSpecialObjectLock);
7042+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
70437043
hx::sFinalizableList.push( hx::Finalizable(inObject, f, inPin) );
70447044
}
70457045

70467046
void __hxcpp_add_alloc_finalizer(void *inAlloc, _hx_alloc_finalizer f, bool inPin)
70477047
{
7048-
AutoLock lock(*gSpecialObjectLock);
7048+
std::lock_guard<std::recursive_mutex> lock(*gSpecialObjectLock);
70497049
hx::sFinalizableList.push( hx::Finalizable(inAlloc, f, inPin) );
70507050
}
70517051

0 commit comments

Comments
 (0)