Commit 3a992f84 authored by clang-format's avatar clang-format Committed by Yaowu Xu

vpx_util/: apply clang-format

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