fix hang on thread creation failure

with assertions enabled the code would abort in
WebPWorkerChangeState with:
Assertion `worker->status_ >= OK'

without them the code would hang in the _cond_wait.

this change makes WebPWorkerChangeState a no-op in this case.

Change-Id: Iea855568bbdef2865ae61ab54473b3a7c230e91a
This commit is contained in:
James Zern 2011-08-05 12:57:57 -07:00
parent a31f843a9f
commit 473ae95324

View File

@ -44,8 +44,10 @@ static void *WebPWorkerThreadLoop(void *ptr) { // thread loop
// main thread state control
static void WebPWorkerChangeState(WebPWorker* const worker,
WebPWorkerStatus new_status) {
// no-op when attempting to change state on a thread that didn't come up
if (worker->status_ < OK) return;
pthread_mutex_lock(&worker->mutex_);
assert(worker->status_ >= OK);
// wait for the worker to finish
while (worker->status_ != OK) {
pthread_cond_wait(&worker->condition_, &worker->mutex_);
@ -71,7 +73,7 @@ int WebPWorkerSync(WebPWorker* const worker) {
#ifdef WEBP_USE_THREAD
WebPWorkerChangeState(worker, OK);
#endif
assert(worker->status_ == OK);
assert(worker->status_ <= OK);
return !worker->had_error;
}