X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/df0e469fdcf0e0b3ef74bac6500e5751c40b4ec1..ce0ac947b4708d0bc1c7e6789b3e1f3bfc80d6e9:/cdsa/cdsa_utilities/threading.cpp diff --git a/cdsa/cdsa_utilities/threading.cpp b/cdsa/cdsa_utilities/threading.cpp index cfe9dd66..e1827f70 100644 --- a/cdsa/cdsa_utilities/threading.cpp +++ b/cdsa/cdsa_utilities/threading.cpp @@ -26,6 +26,7 @@ // we must force THREAD_NDEBUG to off while compiling our header. Trust me. // #include +#include #include @@ -58,7 +59,7 @@ ThreadStoreSlot::~ThreadStoreSlot() bool Mutex::debugHasInitialized; bool Mutex::loggingMutexi; -Mutex::Mutex(bool log) +inline void Mutex::init(Type type, bool log) { #if !defined(THREAD_NDEBUG) // this debug-setup code isn't interlocked, but it's idempotent @@ -72,9 +73,36 @@ Mutex::Mutex(bool log) #else debugLog = false; #endif //THREAD_NDEBUG +} + +struct Recursive : public pthread_mutexattr_t { + Recursive() + { + pthread_mutexattr_init(this); + pthread_mutexattr_settype(this, PTHREAD_MUTEX_RECURSIVE); + } +}; + + +Mutex::Mutex(bool log) +{ + init(normal, log); check(pthread_mutex_init(&me, NULL)); } +Mutex::Mutex(Type type, bool log) +{ + init(type, log); + switch (type) { + case normal: + check(pthread_mutex_init(&me, NULL)); + break; + case recursive: + static ModuleNexus recursive; + check(pthread_mutex_init(&me, &recursive())); + }; + } + Mutex::~Mutex() { #if !defined(THREAD_NDEBUG)