Merge "libcutils: remove rather than fix the mutex."
This commit is contained in:
commit
39e7a1c981
|
@ -29,16 +29,16 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/***********************************************************************/
|
//
|
||||||
/***********************************************************************/
|
// Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows.
|
||||||
/***** *****/
|
//
|
||||||
/***** local thread storage *****/
|
|
||||||
/***** *****/
|
|
||||||
/***********************************************************************/
|
|
||||||
/***********************************************************************/
|
|
||||||
|
|
||||||
extern pid_t gettid();
|
extern pid_t gettid();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Deprecated: use `_Thread_local` in C or `thread_local` in C++.
|
||||||
|
//
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -70,77 +70,6 @@ extern void thread_store_set(thread_store_t* store,
|
||||||
void* value,
|
void* value,
|
||||||
thread_store_destruct_t destroy);
|
thread_store_destruct_t destroy);
|
||||||
|
|
||||||
/***********************************************************************/
|
|
||||||
/***********************************************************************/
|
|
||||||
/***** *****/
|
|
||||||
/***** mutexes *****/
|
|
||||||
/***** *****/
|
|
||||||
/***********************************************************************/
|
|
||||||
/***********************************************************************/
|
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
|
||||||
|
|
||||||
typedef pthread_mutex_t mutex_t;
|
|
||||||
|
|
||||||
#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
|
|
||||||
|
|
||||||
static __inline__ void mutex_lock(mutex_t* lock)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(lock);
|
|
||||||
}
|
|
||||||
static __inline__ void mutex_unlock(mutex_t* lock)
|
|
||||||
{
|
|
||||||
pthread_mutex_unlock(lock);
|
|
||||||
}
|
|
||||||
static __inline__ int mutex_init(mutex_t* lock)
|
|
||||||
{
|
|
||||||
return pthread_mutex_init(lock, NULL);
|
|
||||||
}
|
|
||||||
static __inline__ void mutex_destroy(mutex_t* lock)
|
|
||||||
{
|
|
||||||
pthread_mutex_destroy(lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // !defined(_WIN32)
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int init;
|
|
||||||
CRITICAL_SECTION lock[1];
|
|
||||||
} mutex_t;
|
|
||||||
|
|
||||||
#define MUTEX_INITIALIZER { 0, {{ NULL, 0, 0, NULL, NULL, 0 }} }
|
|
||||||
|
|
||||||
static __inline__ void mutex_lock(mutex_t* lock)
|
|
||||||
{
|
|
||||||
if (!lock->init) {
|
|
||||||
lock->init = 1;
|
|
||||||
InitializeCriticalSection( lock->lock );
|
|
||||||
lock->init = 2;
|
|
||||||
} else while (lock->init != 2)
|
|
||||||
Sleep(10);
|
|
||||||
|
|
||||||
EnterCriticalSection(lock->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ void mutex_unlock(mutex_t* lock)
|
|
||||||
{
|
|
||||||
LeaveCriticalSection(lock->lock);
|
|
||||||
}
|
|
||||||
static __inline__ int mutex_init(mutex_t* lock)
|
|
||||||
{
|
|
||||||
InitializeCriticalSection(lock->lock);
|
|
||||||
lock->init = 2;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static __inline__ void mutex_destroy(mutex_t* lock)
|
|
||||||
{
|
|
||||||
if (lock->init) {
|
|
||||||
lock->init = 0;
|
|
||||||
DeleteCriticalSection(lock->lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // !defined(_WIN32)
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue