X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fcore%2Fmutex.h;fp=source%2Fcore%2Fmutex.h;h=50a64e55aaa0a87a1a6d114960ed5cd3416e5527;hp=8088a2839dbd21a15b8567f3768e850d5c5bb583;hb=cfc8e0b7b15ea505bd6a6a9599cbc5ce1e316963;hpb=7db1e6d50594b47a32ecca5a349a4e8540f890c0 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 &); };