From de6926bc94a2e73fc2b5364840deebc6f2ff7f6e Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 13 Jul 2009 21:59:37 -0700 Subject: [PATCH] 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 --- include/utils/threads.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/utils/threads.h b/include/utils/threads.h index 5c0396596..e9b078889 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); }