version 1.11, 2008/08/14 17:44:27
|
version 1.12, 2008/08/15 17:24:52
|
|
|
} | } |
} | } |
| |
void Mutex::try_lock() |
Boolean Mutex::try_lock() |
{ | { |
PEGASUS_DEBUG_ASSERT(_magic); | PEGASUS_DEBUG_ASSERT(_magic); |
| |
int r = pthread_mutex_trylock(&_rep.mutex); | int r = pthread_mutex_trylock(&_rep.mutex); |
if (r == -1) | if (r == -1) |
r=errno; | r=errno; |
switch (r) |
|
|
if (r == 0) |
{ | { |
case 0: |
|
#if defined(PEGASUS_DEBUG) | #if defined(PEGASUS_DEBUG) |
_rep.count++; | _rep.count++; |
#endif | #endif |
break; |
return true; |
|
} |
| |
case EBUSY: |
if (r == EBUSY) |
throw AlreadyLocked(Threads::self()); |
{ |
|
return false; |
|
} |
| |
default: |
|
throw WaitFailed(Threads::self()); | throw WaitFailed(Threads::self()); |
} | } |
} |
|
| |
Boolean Mutex::timed_lock(Uint32 milliseconds) | Boolean Mutex::timed_lock(Uint32 milliseconds) |
{ | { |
|
|
_rep.count++; | _rep.count++; |
} | } |
| |
void Mutex::try_lock() |
Boolean Mutex::try_lock() |
{ | { |
PEGASUS_DEBUG_ASSERT(_magic); | PEGASUS_DEBUG_ASSERT(_magic); |
| |
DWORD rc = WaitForSingleObject(_rep.handle, 0); | DWORD rc = WaitForSingleObject(_rep.handle, 0); |
| |
if (rc == WAIT_TIMEOUT) | if (rc == WAIT_TIMEOUT) |
throw AlreadyLocked(Threads::self()); |
{ |
|
return false; |
|
} |
| |
if (rc == WAIT_FAILED) | if (rc == WAIT_FAILED) |
|
{ |
throw WaitFailed(Threads::self()); | throw WaitFailed(Threads::self()); |
|
} |
| |
_rep.count++; | _rep.count++; |
|
return true; |
} | } |
| |
Boolean Mutex::timed_lock(Uint32 milliseconds) | Boolean Mutex::timed_lock(Uint32 milliseconds) |