| Index: third_party/libwebp/utils/thread.c
|
| diff --git a/third_party/libwebp/utils/thread.c b/third_party/libwebp/utils/thread.c
|
| index b1615d0fb8d311666b2fa4561076c62d72c2e3ff..a9e3fae8dec537286de4720d23000eb65a8a8609 100644
|
| --- a/third_party/libwebp/utils/thread.c
|
| +++ b/third_party/libwebp/utils/thread.c
|
| @@ -15,10 +15,6 @@
|
| #include <string.h> // for memset()
|
| #include "./thread.h"
|
|
|
| -#if defined(__cplusplus) || defined(c_plusplus)
|
| -extern "C" {
|
| -#endif
|
| -
|
| #ifdef WEBP_USE_THREAD
|
|
|
| #if defined(_WIN32)
|
| @@ -126,14 +122,14 @@ static int pthread_cond_wait(pthread_cond_t* const condition,
|
| return !ok;
|
| }
|
|
|
| -#else // _WIN32
|
| +#else // !_WIN32
|
| # define THREADFN void*
|
| # define THREAD_RETURN(val) val
|
| -#endif
|
| +#endif // _WIN32
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| -static THREADFN WebPWorkerThreadLoop(void *ptr) { // thread loop
|
| +static THREADFN ThreadLoop(void* ptr) {
|
| WebPWorker* const worker = (WebPWorker*)ptr;
|
| int done = 0;
|
| while (!done) {
|
| @@ -142,9 +138,7 @@ static THREADFN WebPWorkerThreadLoop(void *ptr) { // thread loop
|
| 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;
|
| @@ -157,8 +151,8 @@ static THREADFN WebPWorkerThreadLoop(void *ptr) { // thread loop
|
| }
|
|
|
| // main thread state control
|
| -static void WebPWorkerChangeState(WebPWorker* const worker,
|
| - WebPWorkerStatus new_status) {
|
| +static void ChangeState(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;
|
|
|
| @@ -175,7 +169,7 @@ static void WebPWorkerChangeState(WebPWorker* const worker,
|
| pthread_mutex_unlock(&worker->mutex_);
|
| }
|
|
|
| -#endif
|
| +#endif // WEBP_USE_THREAD
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| @@ -186,7 +180,7 @@ void WebPWorkerInit(WebPWorker* const worker) {
|
|
|
| int WebPWorkerSync(WebPWorker* const worker) {
|
| #ifdef WEBP_USE_THREAD
|
| - WebPWorkerChangeState(worker, OK);
|
| + ChangeState(worker, OK);
|
| #endif
|
| assert(worker->status_ <= OK);
|
| return !worker->had_error;
|
| @@ -202,7 +196,7 @@ int WebPWorkerReset(WebPWorker* const worker) {
|
| return 0;
|
| }
|
| pthread_mutex_lock(&worker->mutex_);
|
| - ok = !pthread_create(&worker->thread_, NULL, WebPWorkerThreadLoop, worker);
|
| + ok = !pthread_create(&worker->thread_, NULL, ThreadLoop, worker);
|
| if (ok) worker->status_ = OK;
|
| pthread_mutex_unlock(&worker->mutex_);
|
| #else
|
| @@ -215,19 +209,24 @@ 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
|
| - WebPWorkerChangeState(worker, WORK);
|
| + ChangeState(worker, WORK);
|
| #else
|
| - if (worker->hook)
|
| - worker->had_error |= !worker->hook(worker->data1, worker->data2);
|
| + WebPWorkerExecute(worker);
|
| #endif
|
| }
|
|
|
| void WebPWorkerEnd(WebPWorker* const worker) {
|
| if (worker->status_ >= OK) {
|
| #ifdef WEBP_USE_THREAD
|
| - WebPWorkerChangeState(worker, NOT_OK);
|
| + ChangeState(worker, NOT_OK);
|
| pthread_join(worker->thread_, NULL);
|
| pthread_mutex_destroy(&worker->mutex_);
|
| pthread_cond_destroy(&worker->condition_);
|
| @@ -240,6 +239,3 @@ void WebPWorkerEnd(WebPWorker* const worker) {
|
|
|
| //------------------------------------------------------------------------------
|
|
|
| -#if defined(__cplusplus) || defined(c_plusplus)
|
| -} // extern "C"
|
| -#endif
|
|
|