MCPcopy Create free account
hub / github.com/beefytech/Beef / Proc

Method Proc

BeefySysLib/util/ThreadPool.cpp:19–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void ThreadPool::Thread::Proc()
20{
21 bool isWorking = true;
22
23 BpSetThreadName("ThreadPoolProc");
24 BfpThread_SetName(NULL, "ThreadPoolProc", NULL);
25
26 gPoolParent = mThreadPool;
27
28 while (true)
29 {
30 Job* job = NULL;
31 //
32 {
33 AutoCrit autoCrit(mThreadPool->mCritSect);
34 if (!mThreadPool->mJobs.IsEmpty())
35 {
36 job = mThreadPool->mJobs[0];
37 job->mProcessing = true;
38 mThreadPool->mJobs.RemoveAt(0);
39 }
40
41 mActiveJob = job;
42 if (job == NULL)
43 mCurJobThreadId = -1;
44 else
45 mCurJobThreadId = job->mFromThreadId;
46
47 bool hasWork = job != NULL;
48 if (hasWork != isWorking)
49 {
50 isWorking = hasWork;
51 if (isWorking)
52 mThreadPool->mFreeThreads--;
53 else
54 mThreadPool->mFreeThreads++;
55 }
56 }
57
58 if ((job == NULL) && (mThreadPool->mShuttingDown))
59 {
60 break;
61 }
62
63 bool didCancel = false;
64 if ((mThreadPool->mShuttingDown) && (job->Cancel()))
65 didCancel = true;
66
67 if (job == NULL)
68 {
69 mThreadPool->mEvent.WaitFor();
70 continue;
71 }
72
73 if (!didCancel)
74 {
75 BP_ZONE("ThreadProc:Job");
76 job->Perform();

Callers 1

BFP_CALLTYPE WorkerProcFunction · 0.45

Calls 7

BpSetThreadNameFunction · 0.85
WaitForMethod · 0.80
BfpThread_SetNameFunction · 0.50
IsEmptyMethod · 0.45
RemoveAtMethod · 0.45
CancelMethod · 0.45
PerformMethod · 0.45

Tested by

no test coverage detected