Skip to main content

Module thread_utils

Module thread_utils 

Source
Expand description

Translation of src/utils/thread_utils.c and src/utils/thread_utils.h from libwebp v1.6.0.

Work package: WP1 (types, memory, workers).

WebPWorkerInterface, WebPSetWorkerInterface and WebPGetWorkerInterface are not translated (ADR 0003, decided 2026-11-06). Callers use the worker methods directly, and no public header declares the replacement table.

Every worker starts a std::thread on reset, as the reference configuration with WEBP_USE_THREAD does. The thread and the caller share one Mutex with one Condvar. The job (hook and two data values) moves to the thread at launch and comes back at sync or end; while the worker is working, the caller has no access to the data, which the borrow checker enforces.

§Deviations from upstream

Changes of representation that the ADRs allow, or behavior that the Rust side cannot reproduce exactly. Each records the reason.

  1. Worker allocation. The shared synchronization object is allocated in WebPWorker::init (C: Init) rather than in Reset, so a failed allocation cannot make Reset return false. A failed spawn still does: Reset returns false and the status stays NOT_OK, as ADR 0003 requires.

Structs§

WebPWorker
A worker that runs one hook on its job, on a thread or on the caller’s thread (C: WebPWorker).
WebPWorkerStatus
State of a worker (C: WebPWorkerStatus); the values keep the C order.

Type Aliases§

WebPWorkerHook
The function a worker runs on its two data values. It returns false on error (C: WebPWorkerHook, which returns int).