MCPcopy Create free account
hub / github.com/ZDoom/Raze / ThreadLoop

Function ThreadLoop

libraries/webp/src/utils/thread_utils.c:204–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202//------------------------------------------------------------------------------
203
204static THREADFN ThreadLoop(void* ptr) {
205 WebPWorker* const worker = (WebPWorker*)ptr;
206 WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl_;
207 int done = 0;
208 while (!done) {
209 pthread_mutex_lock(&impl->mutex_);
210 while (worker->status_ == OK) { // wait in idling mode
211 pthread_cond_wait(&impl->condition_, &impl->mutex_);
212 }
213 if (worker->status_ == WORK) {
214 WebPGetWorkerInterface()->Execute(worker);
215 worker->status_ = OK;
216 } else if (worker->status_ == NOT_OK) { // finish the worker
217 done = 1;
218 }
219 // signal to the main thread that we're done (for Sync())
220 // Note the associated mutex does not need to be held when signaling the
221 // condition. Unlocking the mutex first may improve performance in some
222 // implementations, avoiding the case where the waiting thread can't
223 // reacquire the mutex when woken.
224 pthread_mutex_unlock(&impl->mutex_);
225 pthread_cond_signal(&impl->condition_);
226 }
227 return THREAD_RETURN(NULL); // Thread is finished
228}
229
230// main thread state control
231static void ChangeState(WebPWorker* const worker, WebPWorkerStatus new_status) {

Callers

nothing calls this directly

Calls 6

pthread_mutex_lockFunction · 0.85
pthread_cond_waitFunction · 0.85
WebPGetWorkerInterfaceFunction · 0.85
pthread_mutex_unlockFunction · 0.85
pthread_cond_signalFunction · 0.85
ExecuteMethod · 0.45

Tested by

no test coverage detected