From 26d244281a62c909acfd7527da256a9413241122 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 19 Mar 2010 16:14:13 -0700 Subject: 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 --- include/utils/threads.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'include') 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); } -- cgit v1.1