version 1.4.2.3, 2006/07/28 20:46:41
|
version 1.4.2.4, 2006/07/28 23:52:11
|
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Mike Day (mdday@us.ibm.com) |
// Author: Mike Brasher (m.brasher@inovadevelopment.com) |
// |
|
// Modified By: Markus Mueller |
|
// Ramnath Ravindran (Ramnath.Ravindran@compaq.com) |
|
// David Eger (dteger@us.ibm.com) |
|
// Amit K Arora, IBM (amita@in.ibm.com) for PEP#101 |
|
// Sean Keenan, Hewlett-Packard Company (sean.keenan@hp.com) |
|
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// David Dillard, VERITAS Software Corp. |
|
// (david.dillard@veritas.com) |
|
// Aruran, IBM (ashanmug@in.ibm.com) for BUG# 3518 |
|
// |
|
// Reworked By: Mike Brasher (m.brasher@inovadevelopment.com) |
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
{ | { |
pthread_mutex_t mutex; | pthread_mutex_t mutex; |
pthread_mutexattr_t attr; | pthread_mutexattr_t attr; |
ThreadType owner; |
|
}; | }; |
inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); } | inline void mutex_lock(MutexType* mutex) { pthread_mutex_lock(mutex); } |
inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); } | inline void mutex_unlock(MutexType* mutex) { pthread_mutex_unlock(mutex); } |
|
|
struct MutexRep | struct MutexRep |
{ | { |
MutexType handle; | MutexType handle; |
ThreadType owner; |
|
size_t count; | size_t count; |
}; | }; |
inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); } | inline void mutex_lock(MutexType* m) { WaitForSingleObject(*m, INFINITE); } |
|
|
| |
~Mutex(); | ~Mutex(); |
| |
void lock(ThreadType caller = Threads::self()); |
void lock(); |
| |
void try_lock(ThreadType caller = Threads::self()); |
void try_lock(); |
| |
void timed_lock(Uint32 milliseconds, ThreadType caller = Threads::self()); |
void timed_lock(Uint32 milliseconds); |
| |
void unlock(); | void unlock(); |
| |
ThreadType get_owner() { return _rep.owner; } |
|
|
|
void set_owner(ThreadType caller) { _rep.owner = caller; } |
|
|
|
private: | private: |
Mutex(const Mutex&); | Mutex(const Mutex&); |
Mutex& operator=(const Mutex&); | Mutex& operator=(const Mutex&); |
|
|
void lock() | void lock() |
{ | { |
if (_locked) | if (_locked) |
throw AlreadyLocked(Threads::self()); |
throw AlreadyLocked(ThreadType()); |
| |
_mutex.lock(); | _mutex.lock(); |
_locked = true; | _locked = true; |
|
|
void unlock() | void unlock() |
{ | { |
if (!_locked) | if (!_locked) |
throw Permission(Threads::self()); |
throw Permission(ThreadType()); |
| |
_mutex.unlock(); | _mutex.unlock(); |
_locked = false; | _locked = false; |