MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / xnSchedulerThreadFunc

Function xnSchedulerThreadFunc

Source/OpenNI/XnScheduler.cpp:90–152  ·  view source on GitHub ↗

This is the actual scheduler function. It is being run in its own thread. */

Source from the content-addressed store, hash-verified

88
89/* This is the actual scheduler function. It is being run in its own thread. */
90XN_THREAD_PROC xnSchedulerThreadFunc(XN_THREAD_PARAM pThreadParam)
91{
92 XnScheduler* pScheduler = (XnScheduler*)pThreadParam;
93
94 XnUInt64 nNow;
95 while (!pScheduler->bStopThread)
96 {
97 // check when next task should be executed
98 XnUInt64 nWait = XN_WAIT_INFINITE;
99
100 XnScheduledTask* pTask = NULL;
101 XnTaskCallbackFuncPtr pCallback = NULL;
102 void* pCallbackArg = NULL;
103
104 // check if something is in the list
105 if (pScheduler->pFirst != NULL)
106 {
107 // enter critical section
108 xnOSEnterCriticalSection(&pScheduler->hCriticalSection);
109
110 pTask = pScheduler->pFirst;
111 if (pTask != NULL)
112 {
113 xnOSGetTimeStamp(&nNow);
114 if (pTask->nNextTime < nNow)
115 {
116 // task should be executed
117 pCallback = pTask->pCallback;
118 pCallbackArg = pTask->pCallbackArg;
119
120 // remove it from the list
121 pScheduler->pFirst = pTask->pNextTask;
122
123 // calculate next time
124 pTask->nNextTime += pTask->nInterval;
125
126 // add it to the list again
127 xnSchedulerAddTaskInternal(pScheduler, pTask);
128 }
129 else
130 {
131 nWait = pTask->nNextTime - nNow;
132 }
133 }
134
135 // leave critical section
136 xnOSLeaveCriticalSection(&pScheduler->hCriticalSection);
137
138 if (pCallback != NULL)
139 {
140 // execute task (outside critical section)
141 pCallback(pCallbackArg);
142 // no need to wait (we don't know how much time did callback take)
143 nWait = 0;
144 }
145 }
146
147 // wait for a change of the list, or the time of the next task

Callers

nothing calls this directly

Calls 5

xnOSEnterCriticalSectionFunction · 0.50
xnOSGetTimeStampFunction · 0.50
xnOSLeaveCriticalSectionFunction · 0.50
xnOSWaitEventFunction · 0.50

Tested by

no test coverage detected