mirror of
https://github.com/webmproject/libwebp.git
synced 2025-08-30 07:42:27 +02:00
dec/dsp/enc/utils,cosmetics: rm struct member '_' suffix
This is a follow up to:
ee8e8c62
Fix member naming for VP8LHistogram
This better matches Google style and clears some clang-tidy warnings.
This is the final change in this set. It is rather large due to the
shared dependencies between dec/enc.
Change-Id: I89de06b5653ae0bb627f904fa6060334831f7e3b
This commit is contained in:
@@ -29,9 +29,9 @@ typedef CRITICAL_SECTION pthread_mutex_t;
|
||||
typedef CONDITION_VARIABLE pthread_cond_t;
|
||||
#else
|
||||
typedef struct {
|
||||
HANDLE waiting_sem_;
|
||||
HANDLE received_sem_;
|
||||
HANDLE signal_event_;
|
||||
HANDLE waiting_sem;
|
||||
HANDLE received_sem;
|
||||
HANDLE signal_event;
|
||||
} pthread_cond_t;
|
||||
#endif // _WIN32_WINNT >= 0x600
|
||||
|
||||
@@ -51,9 +51,9 @@ typedef struct {
|
||||
#endif // _WIN32
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t mutex_;
|
||||
pthread_cond_t condition_;
|
||||
pthread_t thread_;
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t condition;
|
||||
pthread_t thread;
|
||||
} WebPWorkerImpl;
|
||||
|
||||
#if defined(_WIN32)
|
||||
@@ -133,9 +133,9 @@ static int pthread_cond_destroy(pthread_cond_t* const condition) {
|
||||
#ifdef USE_WINDOWS_CONDITION_VARIABLE
|
||||
(void)condition;
|
||||
#else
|
||||
ok &= (CloseHandle(condition->waiting_sem_) != 0);
|
||||
ok &= (CloseHandle(condition->received_sem_) != 0);
|
||||
ok &= (CloseHandle(condition->signal_event_) != 0);
|
||||
ok &= (CloseHandle(condition->waiting_sem) != 0);
|
||||
ok &= (CloseHandle(condition->received_sem) != 0);
|
||||
ok &= (CloseHandle(condition->signal_event) != 0);
|
||||
#endif
|
||||
return !ok;
|
||||
}
|
||||
@@ -145,12 +145,12 @@ static int pthread_cond_init(pthread_cond_t* const condition, void* cond_attr) {
|
||||
#ifdef USE_WINDOWS_CONDITION_VARIABLE
|
||||
InitializeConditionVariable(condition);
|
||||
#else
|
||||
condition->waiting_sem_ = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
condition->received_sem_ = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
condition->signal_event_ = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (condition->waiting_sem_ == NULL ||
|
||||
condition->received_sem_ == NULL ||
|
||||
condition->signal_event_ == NULL) {
|
||||
condition->waiting_sem = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
condition->received_sem = CreateSemaphore(NULL, 0, 1, NULL);
|
||||
condition->signal_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (condition->waiting_sem == NULL ||
|
||||
condition->received_sem == NULL ||
|
||||
condition->signal_event == NULL) {
|
||||
pthread_cond_destroy(condition);
|
||||
return 1;
|
||||
}
|
||||
@@ -163,12 +163,12 @@ static int pthread_cond_signal(pthread_cond_t* const condition) {
|
||||
#ifdef USE_WINDOWS_CONDITION_VARIABLE
|
||||
WakeConditionVariable(condition);
|
||||
#else
|
||||
if (WaitForSingleObject(condition->waiting_sem_, 0) == WAIT_OBJECT_0) {
|
||||
if (WaitForSingleObject(condition->waiting_sem, 0) == WAIT_OBJECT_0) {
|
||||
// a thread is waiting in pthread_cond_wait: allow it to be notified
|
||||
ok = SetEvent(condition->signal_event_);
|
||||
ok = SetEvent(condition->signal_event);
|
||||
// wait until the event is consumed so the signaler cannot consume
|
||||
// the event via its own pthread_cond_wait.
|
||||
ok &= (WaitForSingleObject(condition->received_sem_, INFINITE) !=
|
||||
ok &= (WaitForSingleObject(condition->received_sem, INFINITE) !=
|
||||
WAIT_OBJECT_0);
|
||||
}
|
||||
#endif
|
||||
@@ -183,12 +183,12 @@ static int pthread_cond_wait(pthread_cond_t* const condition,
|
||||
#else
|
||||
// note that there is a consumer available so the signal isn't dropped in
|
||||
// pthread_cond_signal
|
||||
if (!ReleaseSemaphore(condition->waiting_sem_, 1, NULL)) return 1;
|
||||
if (!ReleaseSemaphore(condition->waiting_sem, 1, NULL)) return 1;
|
||||
// now unlock the mutex so pthread_cond_signal may be issued
|
||||
pthread_mutex_unlock(mutex);
|
||||
ok = (WaitForSingleObject(condition->signal_event_, INFINITE) ==
|
||||
ok = (WaitForSingleObject(condition->signal_event, INFINITE) ==
|
||||
WAIT_OBJECT_0);
|
||||
ok &= ReleaseSemaphore(condition->received_sem_, 1, NULL);
|
||||
ok &= ReleaseSemaphore(condition->received_sem, 1, NULL);
|
||||
pthread_mutex_lock(mutex);
|
||||
#endif
|
||||
return !ok;
|
||||
@@ -203,17 +203,17 @@ static int pthread_cond_wait(pthread_cond_t* const condition,
|
||||
|
||||
static THREADFN ThreadLoop(void* ptr) {
|
||||
WebPWorker* const worker = (WebPWorker*)ptr;
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl_;
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl;
|
||||
int done = 0;
|
||||
while (!done) {
|
||||
pthread_mutex_lock(&impl->mutex_);
|
||||
while (worker->status_ == OK) { // wait in idling mode
|
||||
pthread_cond_wait(&impl->condition_, &impl->mutex_);
|
||||
pthread_mutex_lock(&impl->mutex);
|
||||
while (worker->status == OK) { // wait in idling mode
|
||||
pthread_cond_wait(&impl->condition, &impl->mutex);
|
||||
}
|
||||
if (worker->status_ == WORK) {
|
||||
if (worker->status == WORK) {
|
||||
WebPGetWorkerInterface()->Execute(worker);
|
||||
worker->status_ = OK;
|
||||
} else if (worker->status_ == NOT_OK) { // finish the worker
|
||||
worker->status = OK;
|
||||
} else if (worker->status == NOT_OK) { // finish the worker
|
||||
done = 1;
|
||||
}
|
||||
// signal to the main thread that we're done (for Sync())
|
||||
@@ -221,8 +221,8 @@ static THREADFN ThreadLoop(void* ptr) {
|
||||
// condition. Unlocking the mutex first may improve performance in some
|
||||
// implementations, avoiding the case where the waiting thread can't
|
||||
// reacquire the mutex when woken.
|
||||
pthread_mutex_unlock(&impl->mutex_);
|
||||
pthread_cond_signal(&impl->condition_);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
pthread_cond_signal(&impl->condition);
|
||||
}
|
||||
return THREAD_RETURN(NULL); // Thread is finished
|
||||
}
|
||||
@@ -230,30 +230,30 @@ static THREADFN ThreadLoop(void* ptr) {
|
||||
// main thread state control
|
||||
static void ChangeState(WebPWorker* const worker, WebPWorkerStatus new_status) {
|
||||
// No-op when attempting to change state on a thread that didn't come up.
|
||||
// Checking status_ without acquiring the lock first would result in a data
|
||||
// Checking 'status' without acquiring the lock first would result in a data
|
||||
// race.
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl_;
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl;
|
||||
if (impl == NULL) return;
|
||||
|
||||
pthread_mutex_lock(&impl->mutex_);
|
||||
if (worker->status_ >= OK) {
|
||||
pthread_mutex_lock(&impl->mutex);
|
||||
if (worker->status >= OK) {
|
||||
// wait for the worker to finish
|
||||
while (worker->status_ != OK) {
|
||||
pthread_cond_wait(&impl->condition_, &impl->mutex_);
|
||||
while (worker->status != OK) {
|
||||
pthread_cond_wait(&impl->condition, &impl->mutex);
|
||||
}
|
||||
// assign new status and release the working thread if needed
|
||||
if (new_status != OK) {
|
||||
worker->status_ = new_status;
|
||||
worker->status = new_status;
|
||||
// Note the associated mutex does not need to be held when signaling the
|
||||
// condition. Unlocking the mutex first may improve performance in some
|
||||
// implementations, avoiding the case where the waiting thread can't
|
||||
// reacquire the mutex when woken.
|
||||
pthread_mutex_unlock(&impl->mutex_);
|
||||
pthread_cond_signal(&impl->condition_);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
pthread_cond_signal(&impl->condition);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&impl->mutex_);
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
}
|
||||
|
||||
#endif // WEBP_USE_THREAD
|
||||
@@ -262,54 +262,54 @@ static void ChangeState(WebPWorker* const worker, WebPWorkerStatus new_status) {
|
||||
|
||||
static void Init(WebPWorker* const worker) {
|
||||
memset(worker, 0, sizeof(*worker));
|
||||
worker->status_ = NOT_OK;
|
||||
worker->status = NOT_OK;
|
||||
}
|
||||
|
||||
static int Sync(WebPWorker* const worker) {
|
||||
#ifdef WEBP_USE_THREAD
|
||||
ChangeState(worker, OK);
|
||||
#endif
|
||||
assert(worker->status_ <= OK);
|
||||
assert(worker->status <= OK);
|
||||
return !worker->had_error;
|
||||
}
|
||||
|
||||
static int Reset(WebPWorker* const worker) {
|
||||
int ok = 1;
|
||||
worker->had_error = 0;
|
||||
if (worker->status_ < OK) {
|
||||
if (worker->status < OK) {
|
||||
#ifdef WEBP_USE_THREAD
|
||||
WebPWorkerImpl* const impl =
|
||||
(WebPWorkerImpl*)WebPSafeCalloc(1, sizeof(WebPWorkerImpl));
|
||||
worker->impl_ = (void*)impl;
|
||||
if (worker->impl_ == NULL) {
|
||||
worker->impl = (void*)impl;
|
||||
if (worker->impl == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (pthread_mutex_init(&impl->mutex_, NULL)) {
|
||||
if (pthread_mutex_init(&impl->mutex, NULL)) {
|
||||
goto Error;
|
||||
}
|
||||
if (pthread_cond_init(&impl->condition_, NULL)) {
|
||||
pthread_mutex_destroy(&impl->mutex_);
|
||||
if (pthread_cond_init(&impl->condition, NULL)) {
|
||||
pthread_mutex_destroy(&impl->mutex);
|
||||
goto Error;
|
||||
}
|
||||
pthread_mutex_lock(&impl->mutex_);
|
||||
ok = !pthread_create(&impl->thread_, NULL, ThreadLoop, worker);
|
||||
if (ok) worker->status_ = OK;
|
||||
pthread_mutex_unlock(&impl->mutex_);
|
||||
pthread_mutex_lock(&impl->mutex);
|
||||
ok = !pthread_create(&impl->thread, NULL, ThreadLoop, worker);
|
||||
if (ok) worker->status = OK;
|
||||
pthread_mutex_unlock(&impl->mutex);
|
||||
if (!ok) {
|
||||
pthread_mutex_destroy(&impl->mutex_);
|
||||
pthread_cond_destroy(&impl->condition_);
|
||||
pthread_mutex_destroy(&impl->mutex);
|
||||
pthread_cond_destroy(&impl->condition);
|
||||
Error:
|
||||
WebPSafeFree(impl);
|
||||
worker->impl_ = NULL;
|
||||
worker->impl = NULL;
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
worker->status_ = OK;
|
||||
worker->status = OK;
|
||||
#endif
|
||||
} else if (worker->status_ > OK) {
|
||||
} else if (worker->status > OK) {
|
||||
ok = Sync(worker);
|
||||
}
|
||||
assert(!ok || (worker->status_ == OK));
|
||||
assert(!ok || (worker->status == OK));
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -329,20 +329,20 @@ static void Launch(WebPWorker* const worker) {
|
||||
|
||||
static void End(WebPWorker* const worker) {
|
||||
#ifdef WEBP_USE_THREAD
|
||||
if (worker->impl_ != NULL) {
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl_;
|
||||
if (worker->impl != NULL) {
|
||||
WebPWorkerImpl* const impl = (WebPWorkerImpl*)worker->impl;
|
||||
ChangeState(worker, NOT_OK);
|
||||
pthread_join(impl->thread_, NULL);
|
||||
pthread_mutex_destroy(&impl->mutex_);
|
||||
pthread_cond_destroy(&impl->condition_);
|
||||
pthread_join(impl->thread, NULL);
|
||||
pthread_mutex_destroy(&impl->mutex);
|
||||
pthread_cond_destroy(&impl->condition);
|
||||
WebPSafeFree(impl);
|
||||
worker->impl_ = NULL;
|
||||
worker->impl = NULL;
|
||||
}
|
||||
#else
|
||||
worker->status_ = NOT_OK;
|
||||
assert(worker->impl_ == NULL);
|
||||
worker->status = NOT_OK;
|
||||
assert(worker->impl == NULL);
|
||||
#endif
|
||||
assert(worker->status_ == NOT_OK);
|
||||
assert(worker->status == NOT_OK);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user