summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/Android.bp2
-rw-r--r--libcutils/hashmap.cpp12
-rw-r--r--libcutils/include/cutils/threads.h85
3 files changed, 14 insertions, 85 deletions
diff --git a/libcutils/Android.bp b/libcutils/Android.bp
index 58e59d6d9..37afb9867 100644
--- a/libcutils/Android.bp
+++ b/libcutils/Android.bp
@@ -20,6 +20,7 @@
libcutils_nonwindows_sources = [
"android_get_control_file.cpp",
"fs.cpp",
+ "hashmap.cpp",
"multiuser.cpp",
"socket_inaddr_any_server_unix.cpp",
"socket_local_client_unix.cpp",
@@ -61,7 +62,6 @@ cc_library {
"config_utils.cpp",
"fs_config.cpp",
"canned_fs_config.cpp",
- "hashmap.cpp",
"iosched_policy.cpp",
"load_file.cpp",
"native_handle.cpp",
diff --git a/libcutils/hashmap.cpp b/libcutils/hashmap.cpp
index 2a4a52e1a..57d60067c 100644
--- a/libcutils/hashmap.cpp
+++ b/libcutils/hashmap.cpp
@@ -18,7 +18,7 @@
#include <assert.h>
#include <errno.h>
-#include <cutils/threads.h>
+#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -36,7 +36,7 @@ struct Hashmap {
size_t bucketCount;
int (*hash)(void* key);
bool (*equals)(void* keyA, void* keyB);
- mutex_t lock;
+ pthread_mutex_t lock;
size_t size;
};
@@ -69,7 +69,7 @@ Hashmap* hashmapCreate(size_t initialCapacity,
map->hash = hash;
map->equals = equals;
- mutex_init(&map->lock);
+ pthread_mutex_init(&map->lock, nullptr);
return map;
}
@@ -129,11 +129,11 @@ static void expandIfNecessary(Hashmap* map) {
}
void hashmapLock(Hashmap* map) {
- mutex_lock(&map->lock);
+ pthread_mutex_lock(&map->lock);
}
void hashmapUnlock(Hashmap* map) {
- mutex_unlock(&map->lock);
+ pthread_mutex_unlock(&map->lock);
}
void hashmapFree(Hashmap* map) {
@@ -147,7 +147,7 @@ void hashmapFree(Hashmap* map) {
}
}
free(map->buckets);
- mutex_destroy(&map->lock);
+ pthread_mutex_destroy(&map->lock);
free(map);
}
diff --git a/libcutils/include/cutils/threads.h b/libcutils/include/cutils/threads.h
index 572749407..ba4846e33 100644
--- a/libcutils/include/cutils/threads.h
+++ b/libcutils/include/cutils/threads.h
@@ -29,16 +29,16 @@
extern "C" {
#endif
-/***********************************************************************/
-/***********************************************************************/
-/***** *****/
-/***** local thread storage *****/
-/***** *****/
-/***********************************************************************/
-/***********************************************************************/
+//
+// Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows.
+//
extern pid_t gettid();
+//
+// Deprecated: use `_Thread_local` in C or `thread_local` in C++.
+//
+
#if !defined(_WIN32)
typedef struct {
@@ -70,77 +70,6 @@ extern void thread_store_set(thread_store_t* store,
void* value,
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
}
#endif