diff options
author | Mathias Agopian <mathias@google.com> | 2009-07-13 21:59:37 -0700 |
---|---|---|
committer | Mathias Agopian <mathias@google.com> | 2009-07-13 22:06:36 -0700 |
commit | eb9fd685f8c02384305d57d17b1bca428c7b2dd9 (patch) | |
tree | c51aec2db43e9c53229feed8f532a1703863f68c /include | |
parent | b8eccd86603448a618978a92727a9b948d9f62ed (diff) | |
download | frameworks_native-eb9fd685f8c02384305d57d17b1bca428c7b2dd9.zip frameworks_native-eb9fd685f8c02384305d57d17b1bca428c7b2dd9.tar.gz frameworks_native-eb9fd685f8c02384305d57d17b1bca428c7b2dd9.tar.bz2 |
add a ctor to Mutex to specify the type, which can be shared. This is used by sf and af an soon will allow some optimization in the kernel for non shared mutexes
Diffstat (limited to 'include')
-rw-r--r-- | include/private/ui/SharedState.h | 2 | ||||
-rw-r--r-- | include/utils/threads.h | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/include/private/ui/SharedState.h b/include/private/ui/SharedState.h index 3bc7979..c9f6b5e 100644 --- a/include/private/ui/SharedState.h +++ b/include/private/ui/SharedState.h @@ -98,6 +98,8 @@ struct layer_cblk_t // (128 bytes) struct per_client_cblk_t // 4KB max { + per_client_cblk_t() : lock(Mutex::SHARED) { } + Mutex lock; Condition cv; layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32))); diff --git a/include/utils/threads.h b/include/utils/threads.h index 5c03965..e9b0788 100644 --- a/include/utils/threads.h +++ b/include/utils/threads.h @@ -190,8 +190,14 @@ inline thread_id_t getThreadId() { */ class Mutex { public: + enum { + NORMAL = 0, + SHARED = 1 + }; + Mutex(); Mutex(const char* name); + Mutex(int type, const char* name = NULL); ~Mutex(); // lock or unlock the mutex @@ -235,6 +241,17 @@ inline Mutex::Mutex() { inline Mutex::Mutex(const char* name) { pthread_mutex_init(&mMutex, NULL); } +inline Mutex::Mutex(int type, const char* name) { + if (type == SHARED) { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_mutex_init(&mMutex, &attr); + pthread_mutexattr_destroy(&attr); + } else { + pthread_mutex_init(&mMutex, NULL); + } +} inline Mutex::~Mutex() { pthread_mutex_destroy(&mMutex); } |