mirror of
				https://github.com/webmproject/libwebp.git
				synced 2025-10-31 02:15:42 +01:00 
			
		
		
		
	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:
		| @@ -142,9 +142,7 @@ static THREADFN ThreadLoop(void* ptr) { | |||||||
|       pthread_cond_wait(&worker->condition_, &worker->mutex_); |       pthread_cond_wait(&worker->condition_, &worker->mutex_); | ||||||
|     } |     } | ||||||
|     if (worker->status_ == WORK) { |     if (worker->status_ == WORK) { | ||||||
|       if (worker->hook) { |       WebPWorkerExecute(worker); | ||||||
|         worker->had_error |= !worker->hook(worker->data1, worker->data2); |  | ||||||
|       } |  | ||||||
|       worker->status_ = OK; |       worker->status_ = OK; | ||||||
|     } else if (worker->status_ == NOT_OK) {   // finish the worker |     } else if (worker->status_ == NOT_OK) {   // finish the worker | ||||||
|       done = 1; |       done = 1; | ||||||
| @@ -175,7 +173,7 @@ static void ChangeState(WebPWorker* const worker, | |||||||
|   pthread_mutex_unlock(&worker->mutex_); |   pthread_mutex_unlock(&worker->mutex_); | ||||||
| } | } | ||||||
|  |  | ||||||
| #endif | #endif  // WEBP_USE_THREAD | ||||||
|  |  | ||||||
| //------------------------------------------------------------------------------ | //------------------------------------------------------------------------------ | ||||||
|  |  | ||||||
| @@ -215,12 +213,17 @@ int WebPWorkerReset(WebPWorker* const worker) { | |||||||
|   return ok; |   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) { | void WebPWorkerLaunch(WebPWorker* const worker) { | ||||||
| #ifdef WEBP_USE_THREAD | #ifdef WEBP_USE_THREAD | ||||||
|   ChangeState(worker, WORK); |   ChangeState(worker, WORK); | ||||||
| #else | #else | ||||||
|   if (worker->hook) |   WebPWorkerExecute(worker); | ||||||
|     worker->had_error |= !worker->hook(worker->data1, worker->data2); |  | ||||||
| #endif | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -79,6 +79,11 @@ int WebPWorkerSync(WebPWorker* const worker); | |||||||
| // hook/data1/data2 can be changed at any time before calling this function, | // hook/data1/data2 can be changed at any time before calling this function, | ||||||
| // but not be changed afterward until the next call to WebPWorkerSync(). | // but not be changed afterward until the next call to WebPWorkerSync(). | ||||||
| void WebPWorkerLaunch(WebPWorker* const worker); | 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 | // Kill the thread and terminate the object. To use the object again, one | ||||||
| // must call WebPWorkerReset() again. | // must call WebPWorkerReset() again. | ||||||
| void WebPWorkerEnd(WebPWorker* const worker); | void WebPWorkerEnd(WebPWorker* const worker); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user