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

Function ChangeState

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

main thread state control

Source from the content-addressed store, hash-verified

229
230// main thread state control
231static void ChangeState(WebPWorker* const worker, WebPWorkerStatus new_status) {
232 // No-op when attempting to change state on a thread that didn't come up.
233 // Checking status_ without acquiring the lock first would result in a data
234 // race.
235 WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl_;
236 if (impl == NULL) return;
237
238 pthread_mutex_lock(&impl->mutex_);
239 if (worker->status_ >= OK) {
240 // wait for the worker to finish
241 while (worker->status_ != OK) {
242 pthread_cond_wait(&impl->condition_, &impl->mutex_);
243 }
244 // assign new status and release the working thread if needed
245 if (new_status != OK) {
246 worker->status_ = new_status;
247 // Note the associated mutex does not need to be held when signaling the
248 // condition. Unlocking the mutex first may improve performance in some
249 // implementations, avoiding the case where the waiting thread can't
250 // reacquire the mutex when woken.
251 pthread_mutex_unlock(&impl->mutex_);
252 pthread_cond_signal(&impl->condition_);
253 return;
254 }
255 }
256 pthread_mutex_unlock(&impl->mutex_);
257}
258
259#endif // WEBP_USE_THREAD
260

Callers 3

SyncFunction · 0.70
LaunchFunction · 0.70
EndFunction · 0.70

Calls 4

pthread_mutex_lockFunction · 0.85
pthread_cond_waitFunction · 0.85
pthread_mutex_unlockFunction · 0.85
pthread_cond_signalFunction · 0.85

Tested by

no test coverage detected