| 202 | //------------------------------------------------------------------------------ |
| 203 | |
| 204 | static 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 |
| 231 | static void ChangeState(WebPWorker* const worker, WebPWorkerStatus new_status) { |
nothing calls this directly
no test coverage detected