X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fmutex.h;h=50a64e55aaa0a87a1a6d114960ed5cd3416e5527;hb=47a232c3c19e718a30281d3ada8acc1b6212ea8c;hp=8088a2839dbd21a15b8567f3768e850d5c5bb583;hpb=521cf1db00f8ce2d9f9494dca503d6c17d89ac2f;p=libs%2Fcore.git diff --git a/source/core/mutex.h b/source/core/mutex.h index 8088a28..50a64e5 100644 --- a/source/core/mutex.h +++ b/source/core/mutex.h @@ -4,6 +4,7 @@ This file is part of libmspcore Copyright © 2006 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ + #ifndef MSP_CORE_MUTEX_H_ #define MSP_CORE_MUTEX_H_ @@ -14,6 +15,11 @@ namespace Msp { class Mutex { + friend class Semaphore; + +private: + MutexHandle mutex; + public: #ifndef WIN32 Mutex() { pthread_mutex_init(&mutex, 0); } @@ -28,10 +34,6 @@ public: int unlock() { return !ReleaseMutex(mutex); } ~Mutex() { CloseHandle(mutex); } #endif -private: - MutexHandle mutex; - - friend class Semaphore; }; /** @@ -39,14 +41,15 @@ Locks the mutex for te lifetime of the object. */ class MutexLock { +private: + Mutex &mutex; + public: MutexLock(Mutex &m, bool l=true): mutex(m) { if(l) mutex.lock(); } ~MutexLock() { mutex.unlock(); } int lock() { return mutex.lock(); } private: - Mutex &mutex; - MutexLock(const MutexLock &); MutexLock &operator=(const MutexLock &); };