aom: Add AVX_WORKER_STATUS_ to values of global-scope status enum.

From e4d1f5463855eeb95c5cc34b22b072c3bd7050b3 Mon Sep 17 00:00:00 2001
From: Peter Kasting <[EMAIL REDACTED]>
Date: Mon, 12 Feb 2024 16:13:31 -0800
Subject: [PATCH] Add AVX_WORKER_STATUS_ to values of global-scope status enum.

This helps prevent name clashes if code e.g. #includes headers from both
libvpx and libaom.

Bug: none
Change-Id: I53814af640e2db1418a6c18d9c860dabdeb7cec3
---
 aom_util/aom_thread.c | 51 ++++++++++++++++++++++---------------------
 aom_util/aom_thread.h |  6 ++---
 2 files changed, 29 insertions(+), 28 deletions(-)

diff --git a/aom_util/aom_thread.c b/aom_util/aom_thread.c
index 501827ddd..a353b523d 100644
--- a/aom_util/aom_thread.c
+++ b/aom_util/aom_thread.c
@@ -82,24 +82,25 @@ static THREADFN thread_loop(void *ptr) {
 #endif
   pthread_mutex_lock(&worker->impl_->mutex_);
   for (;;) {
-    while (worker->status_ == OK) {  // wait in idling mode
+    while (worker->status_ == AVX_WORKER_STATUS_OK) {  // wait in idling mode
       pthread_cond_wait(&worker->impl_->condition_, &worker->impl_->mutex_);
     }
-    if (worker->status_ == WORK) {
-      // When worker->status_ is WORK, the main thread doesn't change
-      // worker->status_ and will wait until the worker changes worker->status_
-      // to OK. See change_state(). So the worker can safely call execute()
-      // without holding worker->impl_->mutex_. When the worker reacquires
-      // worker->impl_->mutex_, worker->status_ must still be WORK.
+    if (worker->status_ == AVX_WORKER_STATUS_WORKING) {
+      // When worker->status_ is AVX_WORKER_STATUS_WORKING, the main thread
+      // doesn't change worker->status_ and will wait until the worker changes
+      // worker->status_ to AVX_WORKER_STATUS_OK. See change_state(). So the
+      // worker can safely call execute() without holding worker->impl_->mutex_.
+      // When the worker reacquires worker->impl_->mutex_, worker->status_ must
+      // still be AVX_WORKER_STATUS_WORKING.
       pthread_mutex_unlock(&worker->impl_->mutex_);
       execute(worker);
       pthread_mutex_lock(&worker->impl_->mutex_);
-      assert(worker->status_ == WORK);
-      worker->status_ = OK;
+      assert(worker->status_ == AVX_WORKER_STATUS_WORKING);
+      worker->status_ = AVX_WORKER_STATUS_OK;
       // signal to the main thread that we're done (for sync())
       pthread_cond_signal(&worker->impl_->condition_);
     } else {
-      assert(worker->status_ == NOT_OK);  // finish the worker
+      assert(worker->status_ == AVX_WORKER_STATUS_NOT_OK);  // finish the worker
       break;
     }
   }
@@ -115,13 +116,13 @@ static void change_state(AVxWorker *const worker, AVxWorkerStatus new_status) {
   if (worker->impl_ == NULL) return;
 
   pthread_mutex_lock(&worker->impl_->mutex_);
-  if (worker->status_ >= OK) {
+  if (worker->status_ >= AVX_WORKER_STATUS_OK) {
     // wait for the worker to finish
-    while (worker->status_ != OK) {
+    while (worker->status_ != AVX_WORKER_STATUS_OK) {
       pthread_cond_wait(&worker->impl_->condition_, &worker->impl_->mutex_);
     }
     // assign new status and release the working thread if needed
-    if (new_status != OK) {
+    if (new_status != AVX_WORKER_STATUS_OK) {
       worker->status_ = new_status;
       pthread_cond_signal(&worker->impl_->condition_);
     }
@@ -135,21 +136,21 @@ static void change_state(AVxWorker *const worker, AVxWorkerStatus new_status) {
 
 static void init(AVxWorker *const worker) {
   memset(worker, 0, sizeof(*worker));
-  worker->status_ = NOT_OK;
+  worker->status_ = AVX_WORKER_STATUS_NOT_OK;
 }
 
 static int sync(AVxWorker *const worker) {
 #if CONFIG_MULTITHREAD
-  change_state(worker, OK);
+  change_state(worker, AVX_WORKER_STATUS_OK);
 #endif
-  assert(worker->status_ <= OK);
+  assert(worker->status_ <= AVX_WORKER_STATUS_OK);
   return !worker->had_error;
 }
 
 static int reset(AVxWorker *const worker) {
   int ok = 1;
   worker->had_error = 0;
-  if (worker->status_ < OK) {
+  if (worker->status_ < AVX_WORKER_STATUS_OK) {
 #if CONFIG_MULTITHREAD
     worker->impl_ = (AVxWorkerImpl *)aom_calloc(1, sizeof(*worker->impl_));
     if (worker->impl_ == NULL) {
@@ -181,7 +182,7 @@ static int reset(AVxWorker *const worker) {
 #endif
     pthread_mutex_lock(&worker->impl_->mutex_);
     ok = !pthread_create(&worker->impl_->thread_, &attr, thread_loop, worker);
-    if (ok) worker->status_ = OK;
+    if (ok) worker->status_ = AVX_WORKER_STATUS_OK;
     pthread_mutex_unlock(&worker->impl_->mutex_);
     pthread_attr_destroy(&attr);
     if (!ok) {
@@ -194,12 +195,12 @@ static int reset(AVxWorker *const worker) {
       return 0;
     }
 #else
-    worker->status_ = OK;
+    worker->status_ = AVX_WORKER_STATUS_OK;
 #endif
-  } else if (worker->status_ > OK) {
+  } else if (worker->status_ > AVX_WORKER_STATUS_OK) {
     ok = sync(worker);
   }
-  assert(!ok || (worker->status_ == OK));
+  assert(!ok || (worker->status_ == AVX_WORKER_STATUS_OK));
   return ok;
 }
 
@@ -211,7 +212,7 @@ static void execute(AVxWorker *const worker) {
 
 static void launch(AVxWorker *const worker) {
 #if CONFIG_MULTITHREAD
-  change_state(worker, WORK);
+  change_state(worker, AVX_WORKER_STATUS_WORKING);
 #else
   execute(worker);
 #endif
@@ -220,7 +221,7 @@ static void launch(AVxWorker *const worker) {
 static void end(AVxWorker *const worker) {
 #if CONFIG_MULTITHREAD
   if (worker->impl_ != NULL) {
-    change_state(worker, NOT_OK);
+    change_state(worker, AVX_WORKER_STATUS_NOT_OK);
     pthread_join(worker->impl_->thread_, NULL);
     pthread_mutex_destroy(&worker->impl_->mutex_);
     pthread_cond_destroy(&worker->impl_->condition_);
@@ -228,10 +229,10 @@ static void end(AVxWorker *const worker) {
     worker->impl_ = NULL;
   }
 #else
-  worker->status_ = NOT_OK;
+  worker->status_ = AVX_WORKER_STATUS_NOT_OK;
   assert(worker->impl_ == NULL);
 #endif
-  assert(worker->status_ == NOT_OK);
+  assert(worker->status_ == AVX_WORKER_STATUS_NOT_OK);
 }
 
 //------------------------------------------------------------------------------
diff --git a/aom_util/aom_thread.h b/aom_util/aom_thread.h
index db454e78c..92e162f12 100644
--- a/aom_util/aom_thread.h
+++ b/aom_util/aom_thread.h
@@ -25,9 +25,9 @@ extern "C" {
 
 // State of the worker thread object
 typedef enum {
-  NOT_OK = 0,  // object is unusable
-  OK,          // ready to work
-  WORK         // busy finishing the current task
+  AVX_WORKER_STATUS_NOT_OK = 0,  // object is unusable
+  AVX_WORKER_STATUS_OK,          // ready to work
+  AVX_WORKER_STATUS_WORKING      // busy finishing the current task
 } AVxWorkerStatus;
 
 // Function to be called by the worker thread. Takes two opaque pointers as