From 988b70844e03efcfcc075a9bc25d846670494f36 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Fri, 2 Aug 2013 11:15:16 -0700 Subject: [PATCH] add WebPWorkerExecute() for convenient bypass This is mainly for re-using the worker structs without using the thread. Change-Id: I8e1be29e53874ef425b15c192fb68036b4c0a359 --- src/utils/thread.c | 15 +++++++++------ src/utils/thread.h | 5 +++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/utils/thread.c b/src/utils/thread.c index b5b059b3..c0d318ae 100644 --- a/src/utils/thread.c +++ b/src/utils/thread.c @@ -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 } diff --git a/src/utils/thread.h b/src/utils/thread.h index 32d59307..c2b92c9f 100644 --- a/src/utils/thread.h +++ b/src/utils/thread.h @@ -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);