134 files changed, 31073 insertions, 30287 deletions
diff --git a/tvapi/libtv/tvutils/CMutex.h b/tvapi/libtv/tvutils/CMutex.h index ec9d3e9..5c91c1a 100644 --- a/tvapi/libtv/tvutils/CMutex.h +++ b/tvapi/libtv/tvutils/CMutex.h @@ -20,51 +20,51 @@ class CCondition; */ class CMutex { public: - enum { - PRIVATE = 0, - SHARED = 1 - }; - - CMutex(); - CMutex(const char *name); - CMutex(int type, const char *name = NULL); - ~CMutex(); - - // lock or unlock the mutex - int lock(); - void unlock(); - - // lock if possible; returns 0 on success, error otherwise - int tryLock(); - - // Manages the mutex automatically. It'll be locked when Autolock is - // constructed and released when Autolock goes out of scope. - class Autolock { - public: - inline Autolock(CMutex &mutex) : mLock(mutex) - { - mLock.lock(); - } - inline Autolock(CMutex *mutex) : mLock(*mutex) - { - mLock.lock(); - } - inline ~Autolock() - { - mLock.unlock(); - } - private: - CMutex &mLock; - }; + enum { + PRIVATE = 0, + SHARED = 1 + }; + + CMutex(); + CMutex(const char *name); + CMutex(int type, const char *name = NULL); + ~CMutex(); + + // lock or unlock the mutex + int lock(); + void unlock(); + + // lock if possible; returns 0 on success, error otherwise + int tryLock(); + + // Manages the mutex automatically. It'll be locked when Autolock is + // constructed and released when Autolock goes out of scope. + class Autolock { + public: + inline Autolock(CMutex &mutex) : mLock(mutex) + { + mLock.lock(); + } + inline Autolock(CMutex *mutex) : mLock(*mutex) + { + mLock.lock(); + } + inline ~Autolock() + { + mLock.unlock(); + } + private: + CMutex &mLock; + }; private: - friend class CCondition; + friend class CCondition; - // A mutex cannot be copied - CMutex(const CMutex &); - CMutex &operator = (const CMutex &); + // A mutex cannot be copied + CMutex(const CMutex &); + CMutex &operator = (const CMutex &); - pthread_mutex_t mMutex; + pthread_mutex_t mMutex; }; @@ -73,39 +73,39 @@ private: inline CMutex::CMutex() { - pthread_mutex_init(&mMutex, NULL); + pthread_mutex_init(&mMutex, NULL); } inline CMutex::CMutex(const char *name) { - pthread_mutex_init(&mMutex, NULL); + pthread_mutex_init(&mMutex, NULL); } inline CMutex::CMutex(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); - } + 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 CMutex::~CMutex() { - pthread_mutex_destroy(&mMutex); + pthread_mutex_destroy(&mMutex); } inline int CMutex::lock() { - return -pthread_mutex_lock(&mMutex); + return -pthread_mutex_lock(&mMutex); } inline void CMutex::unlock() { - pthread_mutex_unlock(&mMutex); + pthread_mutex_unlock(&mMutex); } inline int CMutex::tryLock() { - return -pthread_mutex_trylock(&mMutex); + return -pthread_mutex_trylock(&mMutex); } |