thread: remove harmless race on status_ in End()

if a thread was still doing work when End() was called there'd be a race
on worker->status_. in these cases, however, the specific value is
meaningless as it would be >= OK and the thread would have been shut
down properly, but we'll check 'impl_' instead to avoid any potential
TSan/DRD reports.

Change-Id: Ib93cbc226a099f07761f7bad765549dffb8054b1
This commit is contained in:
James Zern 2014-07-08 19:53:28 -07:00
parent 5a1a7264fc
commit 46fd44c104

View File

@ -269,18 +269,19 @@ static void Launch(WebPWorker* const worker) {
} }
static void End(WebPWorker* const worker) { static void End(WebPWorker* const worker) {
if (worker->status_ >= OK) {
#ifdef WEBP_USE_THREAD #ifdef WEBP_USE_THREAD
if (worker->impl_ != NULL) {
ChangeState(worker, NOT_OK); ChangeState(worker, NOT_OK);
pthread_join(worker->impl_->thread_, NULL); pthread_join(worker->impl_->thread_, NULL);
pthread_mutex_destroy(&worker->impl_->mutex_); pthread_mutex_destroy(&worker->impl_->mutex_);
pthread_cond_destroy(&worker->impl_->condition_); pthread_cond_destroy(&worker->impl_->condition_);
#else WebPSafeFree(worker->impl_);
worker->status_ = NOT_OK; worker->impl_ = NULL;
#endif
} }
WebPSafeFree(worker->impl_); #else
worker->impl_ = NULL; worker->status_ = NOT_OK;
assert(worker->impl_ == NULL);
#endif
assert(worker->status_ == NOT_OK); assert(worker->status_ == NOT_OK);
} }