main thread state control
| 229 | |
| 230 | // main thread state control |
| 231 | static 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 |
no test coverage detected