diff options
| author | Mathias Agopian <mathias@google.com> | 2010-03-19 16:14:13 -0700 |
|---|---|---|
| committer | Mathias Agopian <mathias@google.com> | 2010-03-19 16:16:43 -0700 |
| commit | a729f97e8bfba67a94b1cde26d0d78d84528de85 (patch) | |
| tree | 348c44f823825856df69b8b8e640bc86146a438f | |
| parent | 078fd47e91d495175927d1a4a8b9aad039a7ba4e (diff) | |
| download | frameworks_base-a729f97e8bfba67a94b1cde26d0d78d84528de85.zip frameworks_base-a729f97e8bfba67a94b1cde26d0d78d84528de85.tar.gz frameworks_base-a729f97e8bfba67a94b1cde26d0d78d84528de85.tar.bz2 | |
libutils Condition are now PRIVATE by default
Condition must be initialized with SHARED for the old behavior, where
they can be used accross processes.
Updated the two places android that require SHARED conditions.
PRIVATE conditions (and mutexes) use more efficient syscalls.
Change-Id: I9a281a4b88206e92ac559c66554e886b9c62db3a
| -rw-r--r-- | include/utils/threads.h | 19 | ||||
| -rw-r--r-- | libs/surfaceflinger_client/SharedBufferStack.cpp | 2 | ||||
| -rw-r--r-- | media/libmedia/AudioTrack.cpp | 6 |
3 files changed, 23 insertions, 4 deletions
diff --git a/include/utils/threads.h b/include/utils/threads.h index 130d83c..5ac0c5e 100644 --- a/include/utils/threads.h +++ b/include/utils/threads.h @@ -209,7 +209,7 @@ inline thread_id_t getThreadId() { class Mutex { public: enum { - NORMAL = 0, + PRIVATE = 0, SHARED = 1 }; @@ -305,7 +305,13 @@ typedef Mutex::Autolock AutoMutex; */ class Condition { public: + enum { + PRIVATE = 0, + SHARED = 1 + }; + Condition(); + Condition(int type); ~Condition(); // Wait on the condition variable. Lock the mutex before calling. status_t wait(Mutex& mutex); @@ -329,6 +335,17 @@ private: inline Condition::Condition() { pthread_cond_init(&mCond, NULL); } +inline Condition::Condition(int type) { + if (type == SHARED) { + pthread_condattr_t attr; + pthread_condattr_init(&attr); + pthread_condattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); + pthread_cond_init(&mCond, &attr); + pthread_condattr_destroy(&attr); + } else { + pthread_cond_init(&mCond, NULL); + } +} inline Condition::~Condition() { pthread_cond_destroy(&mCond); } diff --git a/libs/surfaceflinger_client/SharedBufferStack.cpp b/libs/surfaceflinger_client/SharedBufferStack.cpp index 65ce1c1..a17e8ac 100644 --- a/libs/surfaceflinger_client/SharedBufferStack.cpp +++ b/libs/surfaceflinger_client/SharedBufferStack.cpp @@ -34,7 +34,7 @@ namespace android { // ---------------------------------------------------------------------------- SharedClient::SharedClient() - : lock(Mutex::SHARED) + : lock(Mutex::SHARED), cv(Condition::SHARED) { } diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp index 74852dc..cd7bcd5 100644 --- a/media/libmedia/AudioTrack.cpp +++ b/media/libmedia/AudioTrack.cpp @@ -983,8 +983,10 @@ void AudioTrack::AudioTrackThread::onFirstRef() // ========================================================================= audio_track_cblk_t::audio_track_cblk_t() - : 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) + : lock(Mutex::SHARED), cv(Condition::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) { } |
