mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Implemented IsBackground. Added GC.Disable
This commit is contained in:
parent
af783bec7e
commit
c21be1eea1
6 changed files with 69 additions and 24 deletions
|
@ -2180,6 +2180,12 @@ void BFGC::AddPendingThread(BfInternalThread* internalThread)
|
|||
mPendingThreads.TryAdd(internalThread->mThreadId, internalThread);
|
||||
}
|
||||
|
||||
void BFGC::Disable()
|
||||
{
|
||||
StopCollecting();
|
||||
mGracelessShutdown = true;
|
||||
}
|
||||
|
||||
void BFGC::Shutdown()
|
||||
{
|
||||
if (mShutdown)
|
||||
|
@ -2896,6 +2902,11 @@ void GC::RemoveStackMarkableObject(Object* obj)
|
|||
gBFGC.RemoveStackMarkableObject(obj);
|
||||
}
|
||||
|
||||
void GC::Disable()
|
||||
{
|
||||
gBFGC.Disable();
|
||||
}
|
||||
|
||||
void GC::Shutdown()
|
||||
{
|
||||
gBFGC.Shutdown();
|
||||
|
|
|
@ -397,6 +397,7 @@ public:
|
|||
void AddStackMarkableObject(bf::System::Object* obj);
|
||||
void RemoveStackMarkableObject(bf::System::Object* obj);
|
||||
void AddPendingThread(BfInternalThread* internalThread);
|
||||
void Disable();
|
||||
void Shutdown();
|
||||
void InitDebugDump();
|
||||
void EndDebugDump();
|
||||
|
@ -474,7 +475,8 @@ namespace bf
|
|||
BFRT_EXPORT static void AddPendingThread(void* internalThreadInfo);
|
||||
|
||||
public:
|
||||
BFRT_EXPORT static void Shutdown();
|
||||
BFRT_EXPORT static void Disable();
|
||||
BFRT_EXPORT static void Shutdown();
|
||||
BFRT_EXPORT static void Collect(bool async);
|
||||
BFRT_EXPORT static void Report();
|
||||
BFRT_EXPORT static void Mark(Object* obj);
|
||||
|
|
|
@ -17,6 +17,7 @@ BF_TLS_DECLSPEC Thread* Thread::sCurrentThread;
|
|||
#endif
|
||||
|
||||
static volatile int gLiveThreadCount;
|
||||
static volatile int gBackgroundThreadCount;
|
||||
static Beefy::SyncEvent gThreadsDoneEvent;
|
||||
|
||||
#ifdef BF_PLATFORM_WINDOWS
|
||||
|
@ -132,8 +133,12 @@ static void BF_CALLTYPE CStartProc(void* threadParam)
|
|||
|
||||
bool isAutoDelete = gBfRtCallbacks.Thread_IsAutoDelete(thread);
|
||||
gBfRtCallbacks.Thread_ThreadProc(thread);
|
||||
bool isLastThread = BfpSystem_InterlockedExchangeAdd32((uint32*)&gLiveThreadCount, -1) == 1;
|
||||
|
||||
if (internalThread->mIsBackground)
|
||||
BfpSystem_InterlockedExchangeAdd32((uint32*)&gBackgroundThreadCount, -1);
|
||||
|
||||
bool isLastThread = (int32)BfpSystem_InterlockedExchangeAdd32((uint32*)&gLiveThreadCount, -1) <= gBackgroundThreadCount + 1;
|
||||
|
||||
//printf("Stopping thread\n");
|
||||
|
||||
bool wantsDelete = false;
|
||||
|
@ -158,7 +163,7 @@ static void BF_CALLTYPE CStartProc(void* threadParam)
|
|||
delete internalThread;
|
||||
|
||||
if (isLastThread)
|
||||
gThreadsDoneEvent.Set(false);
|
||||
gThreadsDoneEvent.Set(false);
|
||||
|
||||
//printf("Thread stopped\n");
|
||||
}
|
||||
|
@ -168,7 +173,7 @@ void BfInternalThread::WaitForAllDone()
|
|||
if ((gBfRtFlags & BfRtFlags_NoThreadExitWait) != 0)
|
||||
return;
|
||||
|
||||
while (gLiveThreadCount != 0)
|
||||
while (gLiveThreadCount > gBackgroundThreadCount)
|
||||
{
|
||||
// Clear out any old done events
|
||||
gThreadsDoneEvent.WaitFor();
|
||||
|
@ -303,12 +308,23 @@ void Thread::InternalFinalize()
|
|||
|
||||
bool Thread::IsBackgroundNative()
|
||||
{
|
||||
return false;
|
||||
auto internalThread = GetInternalThread();
|
||||
if (internalThread == NULL)
|
||||
return false;
|
||||
return internalThread->mIsBackground;
|
||||
}
|
||||
|
||||
void Thread::SetBackgroundNative(bool isBackground)
|
||||
{
|
||||
auto internalThread = GetInternalThread();
|
||||
if (internalThread == NULL)
|
||||
return;
|
||||
|
||||
if (isBackground != internalThread->mIsBackground)
|
||||
{
|
||||
internalThread->mIsBackground = isBackground;
|
||||
BfpSystem_InterlockedExchangeAdd32((uint32*)&gBackgroundThreadCount, isBackground ? 1 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
int Thread::GetThreadStateNative()
|
||||
|
|
|
@ -111,6 +111,7 @@ public:
|
|||
bool mStarted;
|
||||
bool mJoinOnDelete;
|
||||
bool mIsManualInit;
|
||||
bool mIsBackground;
|
||||
BfpThread* mThreadHandle;
|
||||
intptr mThreadId;
|
||||
Beefy::CritSect mCritSect;
|
||||
|
@ -126,6 +127,7 @@ public:
|
|||
mIsSuspended = false;
|
||||
mJoinOnDelete = true;
|
||||
mIsManualInit = false;
|
||||
mIsBackground = false;
|
||||
mStackStart = 0;
|
||||
mThreadId = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue