add WebPWorkerExecute() for convenient bypass

This is mainly for re-using the worker structs without using the
thread.

Change-Id: I8e1be29e53874ef425b15c192fb68036b4c0a359
This commit is contained in:
Pascal Massimino 2013-08-02 11:15:16 -07:00
parent 06e24987e7
commit 988b70844e
2 changed files with 14 additions and 6 deletions

View File

@ -142,9 +142,7 @@ static THREADFN ThreadLoop(void* ptr) {
pthread_cond_wait(&worker->condition_, &worker->mutex_);
}
if (worker->status_ == WORK) {
if (worker->hook) {
worker->had_error |= !worker->hook(worker->data1, worker->data2);
}
WebPWorkerExecute(worker);
worker->status_ = OK;
} else if (worker->status_ == NOT_OK) { // finish the worker
done = 1;
@ -175,7 +173,7 @@ static void ChangeState(WebPWorker* const worker,
pthread_mutex_unlock(&worker->mutex_);
}
#endif
#endif // WEBP_USE_THREAD
//------------------------------------------------------------------------------
@ -215,12 +213,17 @@ int WebPWorkerReset(WebPWorker* const worker) {
return ok;
}
void WebPWorkerExecute(WebPWorker* const worker) {
if (worker->hook != NULL) {
worker->had_error |= !worker->hook(worker->data1, worker->data2);
}
}
void WebPWorkerLaunch(WebPWorker* const worker) {
#ifdef WEBP_USE_THREAD
ChangeState(worker, WORK);
#else
if (worker->hook)
worker->had_error |= !worker->hook(worker->data1, worker->data2);
WebPWorkerExecute(worker);
#endif
}

View File

@ -79,6 +79,11 @@ int WebPWorkerSync(WebPWorker* const worker);
// hook/data1/data2 can be changed at any time before calling this function,
// but not be changed afterward until the next call to WebPWorkerSync().
void WebPWorkerLaunch(WebPWorker* const worker);
// This function is similar to WebPWorkerLaunch() except that it calls the
// hook directly instead of using a thread. Convenient to bypass the thread
// mechanism while still using the WebPWorker structs. WebPWorkerSync() must
// still be called afterward (for error reporting).
void WebPWorkerExecute(WebPWorker* const worker);
// Kill the thread and terminate the object. To use the object again, one
// must call WebPWorkerReset() again.
void WebPWorkerEnd(WebPWorker* const worker);