summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Android (Google) Code Review <android-gerrit@google.com> 2009-07-15 01:06:13 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2009-07-15 01:06:13 -0700
commit1f872d4e8675b918dafdd730100df7e865d9ce0b (patch)
tree3cbb80fead4f79e2ba97ad173e6183ba396c5c98
parent03cc558144138365d69ac8c29d9b77c508136efd (diff)
parentfb4f266a1b9f6a20e256d192a940ae4ccc510fad (diff)
Merge change 7067
* changes: 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
-rw-r--r--include/private/ui/SharedState.h2
-rw-r--r--include/utils/threads.h17
-rw-r--r--media/libmedia/AudioTrack.cpp2
3 files changed, 20 insertions, 1 deletions
diff --git a/include/private/ui/SharedState.h b/include/private/ui/SharedState.h
index 3bc7979ca810..c9f6b5edb9ab 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 5c0396596074..e9b0788895e2 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);
}
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index af7dae5f502f..7b9eda76d820 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -891,7 +891,7 @@ void AudioTrack::AudioTrackThread::onFirstRef()
// =========================================================================
audio_track_cblk_t::audio_track_cblk_t()
- : user(0), server(0), userBase(0), serverBase(0), buffers(0), frameCount(0),
+ : lock(Mutex::SHARED), user(0), server(0), userBase(0), serverBase(0), buffers(0), frameCount(0),
loopStart(UINT_MAX), loopEnd(UINT_MAX), loopCount(0), volumeLR(0), flowControlFlag(1), forceReady(0)
{
}