shithub: libvpx

Download patch

ref: 6565c17f24d71ab6d4cf1af68bd818045bbbc83d
parent: 099bd7f07e510a4ea26acd9c1f2820be7785a510
author: clang-format <[email protected]>
date: Mon Jul 25 18:33:21 EDT 2016

vpx_util: apply clang-format

Change-Id: Ie7eab608e2906b9a2b3533db95292ebc430ad377

--- a/vpx_util/endian_inl.h
+++ b/vpx_util/endian_inl.h
@@ -17,21 +17,20 @@
 #include "vpx/vpx_integer.h"
 
 #if defined(__GNUC__)
-# define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
-# define LOCAL_GCC_PREREQ(maj, min) \
-    (LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
+#define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
+#define LOCAL_GCC_PREREQ(maj, min) (LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
 #else
-# define LOCAL_GCC_VERSION 0
-# define LOCAL_GCC_PREREQ(maj, min) 0
+#define LOCAL_GCC_VERSION 0
+#define LOCAL_GCC_PREREQ(maj, min) 0
 #endif
 
 // handle clang compatibility
 #ifndef __has_builtin
-# define __has_builtin(x) 0
+#define __has_builtin(x) 0
 #endif
 
 // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
-#if !defined(WORDS_BIGENDIAN) && \
+#if !defined(WORDS_BIGENDIAN) &&                   \
     (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \
      (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))
 #define WORDS_BIGENDIAN
@@ -80,12 +79,11 @@
 static INLINE uint32_t BSwap32(uint32_t x) {
 #if defined(VPX_USE_MIPS32_R2)
   uint32_t ret;
-  __asm__ volatile (
-    "wsbh   %[ret], %[x]          \n\t"
-    "rotr   %[ret], %[ret],  16   \n\t"
-    : [ret]"=r"(ret)
-    : [x]"r"(x)
-  );
+  __asm__ volatile(
+      "wsbh   %[ret], %[x]          \n\t"
+      "rotr   %[ret], %[ret],  16   \n\t"
+      : [ret] "=r"(ret)
+      : [x] "r"(x));
   return ret;
 #elif defined(HAVE_BUILTIN_BSWAP32)
   return __builtin_bswap32(x);
@@ -109,10 +107,10 @@
   return swapped_bytes;
 #elif defined(_MSC_VER)
   return (uint64_t)_byteswap_uint64(x);
-#else  // generic code for swapping 64-bit values (suggested by bdb@)
+#else   // generic code for swapping 64-bit values (suggested by bdb@)
   x = ((x & 0xffffffff00000000ull) >> 32) | ((x & 0x00000000ffffffffull) << 32);
   x = ((x & 0xffff0000ffff0000ull) >> 16) | ((x & 0x0000ffff0000ffffull) << 16);
-  x = ((x & 0xff00ff00ff00ff00ull) >>  8) | ((x & 0x00ff00ff00ff00ffull) <<  8);
+  x = ((x & 0xff00ff00ff00ff00ull) >> 8) | ((x & 0x00ff00ff00ff00ffull) << 8);
   return x;
 #endif  // HAVE_BUILTIN_BSWAP64
 }
--- a/vpx_util/vpx_thread.c
+++ b/vpx_util/vpx_thread.c
@@ -13,7 +13,7 @@
 //  https://chromium.googlesource.com/webm/libwebp
 
 #include <assert.h>
-#include <string.h>   // for memset()
+#include <string.h>  // for memset()
 #include "./vpx_thread.h"
 #include "vpx_mem/vpx_mem.h"
 
@@ -21,8 +21,8 @@
 
 struct VPxWorkerImpl {
   pthread_mutex_t mutex_;
-  pthread_cond_t  condition_;
-  pthread_t       thread_;
+  pthread_cond_t condition_;
+  pthread_t thread_;
 };
 
 //------------------------------------------------------------------------------
@@ -30,17 +30,17 @@
 static void execute(VPxWorker *const worker);  // Forward declaration.
 
 static THREADFN thread_loop(void *ptr) {
-  VPxWorker *const worker = (VPxWorker*)ptr;
+  VPxWorker *const worker = (VPxWorker *)ptr;
   int done = 0;
   while (!done) {
     pthread_mutex_lock(&worker->impl_->mutex_);
-    while (worker->status_ == OK) {   // wait in idling mode
+    while (worker->status_ == OK) {  // wait in idling mode
       pthread_cond_wait(&worker->impl_->condition_, &worker->impl_->mutex_);
     }
     if (worker->status_ == WORK) {
       execute(worker);
       worker->status_ = OK;
-    } else if (worker->status_ == NOT_OK) {   // finish the worker
+    } else if (worker->status_ == NOT_OK) {  // finish the worker
       done = 1;
     }
     // signal to the main thread that we're done (for sync())
@@ -47,12 +47,11 @@
     pthread_cond_signal(&worker->impl_->condition_);
     pthread_mutex_unlock(&worker->impl_->mutex_);
   }
-  return THREAD_RETURN(NULL);    // Thread is finished
+  return THREAD_RETURN(NULL);  // Thread is finished
 }
 
 // main thread state control
-static void change_state(VPxWorker *const worker,
-                         VPxWorkerStatus new_status) {
+static void change_state(VPxWorker *const worker, VPxWorkerStatus 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
   // race.
@@ -95,7 +94,7 @@
   worker->had_error = 0;
   if (worker->status_ < OK) {
 #if CONFIG_MULTITHREAD
-    worker->impl_ = (VPxWorkerImpl*)vpx_calloc(1, sizeof(*worker->impl_));
+    worker->impl_ = (VPxWorkerImpl *)vpx_calloc(1, sizeof(*worker->impl_));
     if (worker->impl_ == NULL) {
       return 0;
     }
@@ -113,7 +112,7 @@
     if (!ok) {
       pthread_mutex_destroy(&worker->impl_->mutex_);
       pthread_cond_destroy(&worker->impl_->condition_);
- Error:
+    Error:
       vpx_free(worker->impl_);
       worker->impl_ = NULL;
       return 0;
@@ -161,15 +160,14 @@
 
 //------------------------------------------------------------------------------
 
-static VPxWorkerInterface g_worker_interface = {
-  init, reset, sync, launch, execute, end
-};
+static VPxWorkerInterface g_worker_interface = { init,   reset,   sync,
+                                                 launch, execute, end };
 
-int vpx_set_worker_interface(const VPxWorkerInterface* const winterface) {
-  if (winterface == NULL ||
-      winterface->init == NULL || winterface->reset == NULL ||
-      winterface->sync == NULL || winterface->launch == NULL ||
-      winterface->execute == NULL || winterface->end == NULL) {
+int vpx_set_worker_interface(const VPxWorkerInterface *const winterface) {
+  if (winterface == NULL || winterface->init == NULL ||
+      winterface->reset == NULL || winterface->sync == NULL ||
+      winterface->launch == NULL || winterface->execute == NULL ||
+      winterface->end == NULL) {
     return 0;
   }
   g_worker_interface = *winterface;
--- a/vpx_util/vpx_thread.h
+++ b/vpx_util/vpx_thread.h
@@ -28,7 +28,7 @@
 #if CONFIG_MULTITHREAD
 
 #if defined(_WIN32) && !HAVE_PTHREAD_H
-#include <errno.h>  // NOLINT
+#include <errno.h>    // NOLINT
 #include <process.h>  // NOLINT
 #include <windows.h>  // NOLINT
 typedef HANDLE pthread_t;
@@ -66,24 +66,20 @@
   WaitForSingleObjectEx(obj, timeout, FALSE /*bAlertable*/)
 #endif
 
-static INLINE int pthread_create(pthread_t* const thread, const void* attr,
-                                 unsigned int (__stdcall *start)(void*),
-                                 void* arg) {
+static INLINE int pthread_create(pthread_t *const thread, const void *attr,
+                                 unsigned int(__stdcall *start)(void *),
+                                 void *arg) {
   (void)attr;
 #ifdef USE_CREATE_THREAD
-  *thread = CreateThread(NULL,   /* lpThreadAttributes */
-                         0,      /* dwStackSize */
-                         start,
-                         arg,
-                         0,      /* dwStackSize */
-                         NULL);  /* lpThreadId */
+  *thread = CreateThread(NULL,          /* lpThreadAttributes */
+                         0,             /* dwStackSize */
+                         start, arg, 0, /* dwStackSize */
+                         NULL);         /* lpThreadId */
 #else
-  *thread = (pthread_t)_beginthreadex(NULL,   /* void *security */
-                                      0,      /* unsigned stack_size */
-                                      start,
-                                      arg,
-                                      0,      /* unsigned initflag */
-                                      NULL);  /* unsigned *thrdaddr */
+  *thread = (pthread_t)_beginthreadex(NULL,          /* void *security */
+                                      0,             /* unsigned stack_size */
+                                      start, arg, 0, /* unsigned initflag */
+                                      NULL);         /* unsigned *thrdaddr */
 #endif
   if (*thread == NULL) return 1;
   SetThreadPriority(*thread, THREAD_PRIORITY_ABOVE_NORMAL);
@@ -90,7 +86,7 @@
   return 0;
 }
 
-static INLINE int pthread_join(pthread_t thread, void** value_ptr) {
+static INLINE int pthread_join(pthread_t thread, void **value_ptr) {
   (void)value_ptr;
   return (WaitForSingleObject(thread, INFINITE) != WAIT_OBJECT_0 ||
           CloseHandle(thread) == 0);
@@ -98,7 +94,7 @@
 
 // Mutex
 static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex,
-                                     void* mutexattr) {
+                                     void *mutexattr) {
   (void)mutexattr;
 #if _WIN32_WINNT >= 0x0600  // Windows Vista / Server 2008 or greater
   InitializeCriticalSectionEx(mutex, 0 /*dwSpinCount*/, 0 /*Flags*/);
@@ -141,7 +137,7 @@
 }
 
 static INLINE int pthread_cond_init(pthread_cond_t *const condition,
-                                    void* cond_attr) {
+                                    void *cond_attr) {
   (void)cond_attr;
 #ifdef USE_WINDOWS_CONDITION_VARIABLE
   InitializeConditionVariable(condition);
@@ -149,8 +145,7 @@
   condition->waiting_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL);
   condition->received_sem_ = CreateSemaphore(NULL, 0, MAX_DECODE_THREADS, NULL);
   condition->signal_event_ = CreateEvent(NULL, FALSE, FALSE, NULL);
-  if (condition->waiting_sem_ == NULL ||
-      condition->received_sem_ == NULL ||
+  if (condition->waiting_sem_ == NULL || condition->received_sem_ == NULL ||
       condition->signal_event_ == NULL) {
     pthread_cond_destroy(condition);
     return 1;
@@ -184,8 +179,7 @@
 #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) ==
@@ -197,11 +191,11 @@
 }
 #elif defined(__OS2__)
 #define INCL_DOS
-#include <os2.h>    // NOLINT
+#include <os2.h>  // NOLINT
 
-#include <errno.h>  // NOLINT
-#include <stdlib.h> // NOLINT
-#include <sys/builtin.h> // NOLINT
+#include <errno.h>        // NOLINT
+#include <stdlib.h>       // NOLINT
+#include <sys/builtin.h>  // NOLINT
 
 #define pthread_t TID
 #define pthread_mutex_t HMTX
@@ -219,11 +213,11 @@
 #define THREAD_RETURN(val) (val)
 
 typedef struct {
-  void* (*start_)(void*);
-  void* arg_;
+  void *(*start_)(void *);
+  void *arg_;
 } thread_arg;
 
-static void thread_start(void* arg) {
+static void thread_start(void *arg) {
   thread_arg targ = *(thread_arg *)arg;
   free(arg);
 
@@ -230,9 +224,8 @@
   targ.start_(targ.arg_);
 }
 
-static INLINE int pthread_create(pthread_t* const thread, const void* attr,
-                                 void* (*start)(void*),
-                                 void* arg) {
+static INLINE int pthread_create(pthread_t *const thread, const void *attr,
+                                 void *(*start)(void *), void *arg) {
   int tid;
   thread_arg *targ = (thread_arg *)malloc(sizeof(*targ));
   if (targ == NULL) return 1;
@@ -251,7 +244,7 @@
   return 0;
 }
 
-static INLINE int pthread_join(pthread_t thread, void** value_ptr) {
+static INLINE int pthread_join(pthread_t thread, void **value_ptr) {
   (void)value_ptr;
   return DosWaitThread(&thread, DCWW_WAIT) != 0;
 }
@@ -258,7 +251,7 @@
 
 // Mutex
 static INLINE int pthread_mutex_init(pthread_mutex_t *const mutex,
-                                     void* mutexattr) {
+                                     void *mutexattr) {
   (void)mutexattr;
   return DosCreateMutexSem(NULL, mutex, 0, FALSE) != 0;
 }
@@ -288,12 +281,12 @@
 }
 
 static INLINE int pthread_cond_init(pthread_cond_t *const condition,
-                                    void* cond_attr) {
+                                    void *cond_attr) {
   int ok = 1;
   (void)cond_attr;
 
-  ok &= DosCreateEventSem(NULL, &condition->event_sem_, DCE_POSTONE, FALSE)
-          == 0;
+  ok &=
+      DosCreateEventSem(NULL, &condition->event_sem_, DCE_POSTONE, FALSE) == 0;
   ok &= DosCreateEventSem(NULL, &condition->ack_sem_, DCE_POSTONE, FALSE) == 0;
   if (!ok) {
     pthread_cond_destroy(condition);
@@ -318,7 +311,7 @@
   int ok = 1;
 
   while (!__atomic_cmpxchg32(&condition->wait_count_, 0, 0))
-      ok &= pthread_cond_signal(condition) == 0;
+    ok &= pthread_cond_signal(condition) == 0;
 
   return !ok;
 }
@@ -341,10 +334,10 @@
 
   return !ok;
 }
-#else  // _WIN32
-#include <pthread.h> // NOLINT
-# define THREADFN void*
-# define THREAD_RETURN(val) val
+#else                 // _WIN32
+#include <pthread.h>  // NOLINT
+#define THREADFN void *
+#define THREAD_RETURN(val) val
 #endif
 
 #endif  // CONFIG_MULTITHREAD
@@ -351,14 +344,14 @@
 
 // State of the worker thread object
 typedef enum {
-  NOT_OK = 0,   // object is unusable
-  OK,           // ready to work
-  WORK          // busy finishing the current task
+  NOT_OK = 0,  // object is unusable
+  OK,          // ready to work
+  WORK         // busy finishing the current task
 } VPxWorkerStatus;
 
 // Function to be called by the worker thread. Takes two opaque pointers as
 // arguments (data1 and data2), and should return false in case of error.
-typedef int (*VPxWorkerHook)(void*, void*);
+typedef int (*VPxWorkerHook)(void *, void *);
 
 // Platform-dependent implementation details for the worker.
 typedef struct VPxWorkerImpl VPxWorkerImpl;
@@ -367,10 +360,10 @@
 typedef struct {
   VPxWorkerImpl *impl_;
   VPxWorkerStatus status_;
-  VPxWorkerHook hook;     // hook to call
-  void *data1;            // first argument passed to 'hook'
-  void *data2;            // second argument passed to 'hook'
-  int had_error;          // return value of the last call to 'hook'
+  VPxWorkerHook hook;  // hook to call
+  void *data1;         // first argument passed to 'hook'
+  void *data2;         // second argument passed to 'hook'
+  int had_error;       // return value of the last call to 'hook'
 } VPxWorker;
 
 // The interface for all thread-worker related functions. All these functions
@@ -411,7 +404,7 @@
 //------------------------------------------------------------------------------
 
 #ifdef __cplusplus
-}    // extern "C"
+}  // extern "C"
 #endif
 
 #endif  // VPX_THREAD_H_