Merge "Kill HAVE_PTHREADS."

This commit is contained in:
Yabin Cui 2015-01-27 22:33:28 +00:00 committed by Gerrit Code Review
commit e862350bb2
15 changed files with 103 additions and 142 deletions

View file

@ -29,7 +29,7 @@ extern "C" {
/***********************************************************************/ /***********************************************************************/
/***********************************************************************/ /***********************************************************************/
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
@ -42,7 +42,7 @@ typedef struct {
#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 } #define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
#elif defined HAVE_WIN32_THREADS #else // !defined(_WIN32)
#include <windows.h> #include <windows.h>
@ -56,9 +56,7 @@ typedef struct {
#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} } #define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
#else #endif // !defined(_WIN32)
# error "no thread_store_t implementation for your platform !!"
#endif
typedef void (*thread_store_destruct_t)(void* value); typedef void (*thread_store_destruct_t)(void* value);
@ -76,7 +74,7 @@ extern void thread_store_set(thread_store_t* store,
/***********************************************************************/ /***********************************************************************/
/***********************************************************************/ /***********************************************************************/
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
typedef pthread_mutex_t mutex_t; typedef pthread_mutex_t mutex_t;
@ -98,9 +96,9 @@ static __inline__ void mutex_destroy(mutex_t* lock)
{ {
pthread_mutex_destroy(lock); pthread_mutex_destroy(lock);
} }
#endif
#ifdef HAVE_WIN32_THREADS #else // !defined(_WIN32)
typedef struct { typedef struct {
int init; int init;
CRITICAL_SECTION lock[1]; CRITICAL_SECTION lock[1];
@ -137,7 +135,7 @@ static __inline__ void mutex_destroy(mutex_t* lock)
DeleteCriticalSection(lock->lock); DeleteCriticalSection(lock->lock);
} }
} }
#endif #endif // !defined(_WIN32)
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -28,14 +28,12 @@
#ifndef _LIBS_LOG_LOG_H #ifndef _LIBS_LOG_LOG_H
#define _LIBS_LOG_LOG_H #define _LIBS_LOG_LOG_H
#include <sys/types.h>
#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <log/logd.h> #include <log/logd.h>
#include <log/uio.h> #include <log/uio.h>

View file

@ -23,16 +23,17 @@
#include <android/log.h> #include <android/log.h>
/* the rest is only used internally by the system */ /* the rest is only used internally by the system */
#include <time.h> #if !defined(_WIN32)
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#ifdef HAVE_PTHREADS
#include <pthread.h> #include <pthread.h>
#endif #endif
#include <log/uio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <log/uio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -20,7 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif

View file

@ -21,7 +21,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif
@ -74,7 +74,7 @@ public:
void broadcast(); void broadcast();
private: private:
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
pthread_cond_t mCond; pthread_cond_t mCond;
#else #else
void* mState; void* mState;
@ -83,7 +83,7 @@ private:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
inline Condition::Condition() { inline Condition::Condition() {
pthread_cond_init(&mCond, NULL); pthread_cond_init(&mCond, NULL);
@ -149,7 +149,7 @@ inline void Condition::broadcast() {
pthread_cond_broadcast(&mCond); pthread_cond_broadcast(&mCond);
} }
#endif // HAVE_PTHREADS #endif // !defined(_WIN32)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
}; // namespace android }; // namespace android

View file

@ -21,7 +21,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif
@ -87,7 +87,7 @@ private:
Mutex(const Mutex&); Mutex(const Mutex&);
Mutex& operator = (const Mutex&); Mutex& operator = (const Mutex&);
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
pthread_mutex_t mMutex; pthread_mutex_t mMutex;
#else #else
void _init(); void _init();
@ -97,7 +97,7 @@ private:
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
inline Mutex::Mutex() { inline Mutex::Mutex() {
pthread_mutex_init(&mMutex, NULL); pthread_mutex_init(&mMutex, NULL);
@ -138,7 +138,7 @@ inline status_t Mutex::timedLock(nsecs_t timeoutNs) {
} }
#endif #endif
#endif // HAVE_PTHREADS #endif // !defined(_WIN32)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View file

@ -20,7 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif
@ -31,7 +31,7 @@
namespace android { namespace android {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
/* /*
* Simple mutex class. The implementation is system-dependent. * Simple mutex class. The implementation is system-dependent.
@ -117,7 +117,7 @@ inline void RWLock::unlock() {
pthread_rwlock_unlock(&mRWLock); pthread_rwlock_unlock(&mRWLock);
} }
#endif // HAVE_PTHREADS #endif // !defined(_WIN32)
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
}; // namespace android }; // namespace android

View file

@ -21,7 +21,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <time.h> #include <time.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif

View file

@ -16,7 +16,7 @@
#include <cutils/threads.h> #include <cutils/threads.h>
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
void* thread_store_get( thread_store_t* store ) void* thread_store_get( thread_store_t* store )
{ {
if (!store->has_tls) if (!store->has_tls)
@ -42,9 +42,7 @@ extern void thread_store_set( thread_store_t* store,
pthread_setspecific( store->tls, value ); pthread_setspecific( store->tls, value );
} }
#endif #else /* !defined(_WIN32) */
#ifdef HAVE_WIN32_THREADS
void* thread_store_get( thread_store_t* store ) void* thread_store_get( thread_store_t* store )
{ {
if (!store->has_tls) if (!store->has_tls)
@ -79,4 +77,4 @@ void thread_store_set( thread_store_t* store,
TlsSetValue( store->tls, value ); TlsSetValue( store->tls, value );
} }
#endif #endif /* !defined(_WIN32) */

View file

@ -29,7 +29,7 @@
#include <log/logd.h> #include <log/logd.h>
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -88,7 +88,7 @@ typedef struct LogState {
} LogState; } LogState;
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
/* /*
* Locking. Since we're emulating a device, we need to be prepared * Locking. Since we're emulating a device, we need to be prepared
* to have multiple callers at the same time. This lock is used * to have multiple callers at the same time. This lock is used
@ -106,10 +106,10 @@ static void unlock()
{ {
pthread_mutex_unlock(&fakeLogDeviceLock); pthread_mutex_unlock(&fakeLogDeviceLock);
} }
#else // !HAVE_PTHREADS #else // !defined(_WIN32)
#define lock() ((void)0) #define lock() ((void)0)
#define unlock() ((void)0) #define unlock() ((void)0)
#endif // !HAVE_PTHREADS #endif // !defined(_WIN32)
/* /*

View file

@ -15,7 +15,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
#include <pthread.h> #include <pthread.h>
#endif #endif
#include <stdarg.h> #include <stdarg.h>
@ -50,7 +50,7 @@
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr); static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init; static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif #endif
@ -259,11 +259,11 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
if (ret == -ENOTCONN) { if (ret == -ENOTCONN) {
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
pthread_mutex_lock(&log_init_lock); pthread_mutex_lock(&log_init_lock);
#endif #endif
ret = __write_to_log_initialize(); ret = __write_to_log_initialize();
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
pthread_mutex_unlock(&log_init_lock); pthread_mutex_unlock(&log_init_lock);
#endif #endif
@ -306,7 +306,7 @@ const char *android_log_id_to_name(log_id_t log_id)
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{ {
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
pthread_mutex_lock(&log_init_lock); pthread_mutex_lock(&log_init_lock);
#endif #endif
@ -315,7 +315,7 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
ret = __write_to_log_initialize(); ret = __write_to_log_initialize();
if (ret < 0) { if (ret < 0) {
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
pthread_mutex_unlock(&log_init_lock); pthread_mutex_unlock(&log_init_lock);
#endif #endif
return ret; return ret;
@ -324,7 +324,7 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
write_to_log = __write_to_log_kernel; write_to_log = __write_to_log_kernel;
} }
#ifdef HAVE_PTHREADS #if !defined(_WIN32)
pthread_mutex_unlock(&log_init_lock); pthread_mutex_unlock(&log_init_lock);
#endif #endif

View file

@ -16,9 +16,7 @@
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef HAVE_PTHREADS
#include <pthread.h> #include <pthread.h>
#endif
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -28,9 +26,7 @@
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef __BIONIC__
#include <android/set_abort_message.h> #include <android/set_abort_message.h>
#endif
#include <log/log.h> #include <log/log.h>
#include <log/logd.h> #include <log/logd.h>
@ -43,23 +39,14 @@
#define LOG_BUF_SIZE 1024 #define LOG_BUF_SIZE 1024
#if FAKE_LOG_DEVICE
/* This will be defined when building for the host. */
#include "fake_log_device.h"
#define log_open(pathname, flags) fakeLogOpen(pathname, flags)
#define log_writev(filedes, vector, count) fakeLogWritev(filedes, vector, count)
#define log_close(filedes) fakeLogClose(filedes)
#else
#define log_open(pathname, flags) open(pathname, (flags) | O_CLOEXEC) #define log_open(pathname, flags) open(pathname, (flags) | O_CLOEXEC)
#define log_writev(filedes, vector, count) writev(filedes, vector, count) #define log_writev(filedes, vector, count) writev(filedes, vector, count)
#define log_close(filedes) close(filedes) #define log_close(filedes) close(filedes)
#endif
static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr); static int __write_to_log_init(log_id_t, struct iovec *vec, size_t nr);
static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init; static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_log_init;
#ifdef HAVE_PTHREADS
static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
#ifndef __unused #ifndef __unused
#define __unused __attribute__((__unused__)) #define __unused __attribute__((__unused__))
@ -119,9 +106,7 @@ static int __write_to_log_kernel(log_id_t log_id, struct iovec *vec, size_t nr)
static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr) static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
{ {
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&log_init_lock); pthread_mutex_lock(&log_init_lock);
#endif
if (write_to_log == __write_to_log_init) { if (write_to_log == __write_to_log_init) {
log_fds[LOG_ID_MAIN] = log_open("/dev/"LOGGER_LOG_MAIN, O_WRONLY); log_fds[LOG_ID_MAIN] = log_open("/dev/"LOGGER_LOG_MAIN, O_WRONLY);
@ -147,9 +132,7 @@ static int __write_to_log_init(log_id_t log_id, struct iovec *vec, size_t nr)
} }
} }
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&log_init_lock); pthread_mutex_unlock(&log_init_lock);
#endif
return write_to_log(log_id, vec, nr); return write_to_log(log_id, vec, nr);
} }
@ -179,11 +162,9 @@ int __android_log_write(int prio, const char *tag, const char *msg)
tag = tmp_tag; tag = tmp_tag;
} }
#if __BIONIC__
if (prio == ANDROID_LOG_FATAL) { if (prio == ANDROID_LOG_FATAL) {
android_set_abort_message(msg); android_set_abort_message(msg);
} }
#endif
vec[0].iov_base = (unsigned char *) &prio; vec[0].iov_base = (unsigned char *) &prio;
vec[0].iov_len = 1; vec[0].iov_len = 1;

View file

@ -24,11 +24,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
# include <sched.h> # include <sched.h>
# include <sys/resource.h> # include <sys/resource.h>
#elif defined(HAVE_WIN32_THREADS) #else
# include <windows.h> # include <windows.h>
# include <stdint.h> # include <stdint.h>
# include <process.h> # include <process.h>
@ -59,7 +59,7 @@
using namespace android; using namespace android;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/* /*
@ -188,7 +188,7 @@ android_thread_id_t androidGetThreadId()
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#elif defined(HAVE_WIN32_THREADS) #else // !defined(_WIN32)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/* /*
@ -268,9 +268,7 @@ android_thread_id_t androidGetThreadId()
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#else #endif // !defined(_WIN32)
#error "Threads not supported"
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -308,7 +306,7 @@ int androidSetThreadPriority(pid_t tid, int pri)
{ {
int rc = 0; int rc = 0;
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
int lasterr = 0; int lasterr = 0;
if (pri >= ANDROID_PRIORITY_BACKGROUND) { if (pri >= ANDROID_PRIORITY_BACKGROUND) {
@ -332,7 +330,7 @@ int androidSetThreadPriority(pid_t tid, int pri)
} }
int androidGetThreadPriority(pid_t tid) { int androidGetThreadPriority(pid_t tid) {
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
return getpriority(PRIO_PROCESS, tid); return getpriority(PRIO_PROCESS, tid);
#else #else
return ANDROID_PRIORITY_NORMAL; return ANDROID_PRIORITY_NORMAL;
@ -349,9 +347,9 @@ namespace android {
* =========================================================================== * ===========================================================================
*/ */
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
// implemented as inlines in threads.h // implemented as inlines in threads.h
#elif defined(HAVE_WIN32_THREADS) #else
Mutex::Mutex() Mutex::Mutex()
{ {
@ -413,9 +411,7 @@ status_t Mutex::tryLock()
return (dwWaitResult == WAIT_OBJECT_0) ? 0 : -1; return (dwWaitResult == WAIT_OBJECT_0) ? 0 : -1;
} }
#else #endif // !defined(_WIN32)
#error "Somebody forgot to implement threads for this platform."
#endif
/* /*
@ -424,9 +420,9 @@ status_t Mutex::tryLock()
* =========================================================================== * ===========================================================================
*/ */
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
// implemented as inlines in threads.h // implemented as inlines in threads.h
#elif defined(HAVE_WIN32_THREADS) #else
/* /*
* Windows doesn't have a condition variable solution. It's possible * Windows doesn't have a condition variable solution. It's possible
@ -647,9 +643,7 @@ void Condition::broadcast()
ReleaseMutex(condState->internalMutex); ReleaseMutex(condState->internalMutex);
} }
#else #endif // !defined(_WIN32)
#error "condition variables not supported on this platform"
#endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View file

@ -18,19 +18,10 @@
// Timer functions. // Timer functions.
// //
#include <utils/Timers.h> #include <utils/Timers.h>
#include <utils/Log.h>
#include <stdlib.h> #include <limits.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <errno.h>
#include <limits.h>
#ifdef HAVE_WIN32_THREADS
#include <windows.h>
#endif
#if defined(HAVE_ANDROID_OS) #if defined(HAVE_ANDROID_OS)
nsecs_t systemTime(int clock) nsecs_t systemTime(int clock)

View file

@ -27,7 +27,7 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
# include <pthread.h> # include <pthread.h>
#endif #endif
@ -42,13 +42,13 @@ struct sysprop_change_callback_info {
int priority; int priority;
}; };
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
static pthread_mutex_t gSyspropMutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t gSyspropMutex = PTHREAD_MUTEX_INITIALIZER;
static Vector<sysprop_change_callback_info>* gSyspropList = NULL; static Vector<sysprop_change_callback_info>* gSyspropList = NULL;
#endif #endif
void add_sysprop_change_callback(sysprop_change_callback cb, int priority) { void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
pthread_mutex_lock(&gSyspropMutex); pthread_mutex_lock(&gSyspropMutex);
if (gSyspropList == NULL) { if (gSyspropList == NULL) {
gSyspropList = new Vector<sysprop_change_callback_info>(); gSyspropList = new Vector<sysprop_change_callback_info>();
@ -72,7 +72,7 @@ void add_sysprop_change_callback(sysprop_change_callback cb, int priority) {
} }
void report_sysprop_change() { void report_sysprop_change() {
#if defined(HAVE_PTHREADS) #if !defined(_WIN32)
pthread_mutex_lock(&gSyspropMutex); pthread_mutex_lock(&gSyspropMutex);
Vector<sysprop_change_callback_info> listeners; Vector<sysprop_change_callback_info> listeners;
if (gSyspropList != NULL) { if (gSyspropList != NULL) {