Mercurial > dwindows
comparison win/dw.c @ 1158:f86f556ff29d
Added dw_mutex_trylock() that functions like dw_mutex_lock() except
it does not block if the mutex is already locked, it instead returns
DW_MUTEX_TIMEOUT. Allowing threads to continue to do work while
waiting to obtain a mutex.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 15 Sep 2011 21:13:59 +0000 |
parents | e6a2f57c0842 |
children | 924c8087a755 |
comparison
equal
deleted
inserted
replaced
1157:79bd0aff0bc2 | 1158:f86f556ff29d |
---|---|
9203 else | 9203 else |
9204 WaitForSingleObject((HANDLE)mutex, INFINITE); | 9204 WaitForSingleObject((HANDLE)mutex, INFINITE); |
9205 } | 9205 } |
9206 | 9206 |
9207 /* | 9207 /* |
9208 * Tries to gain access to the semaphore. | |
9209 * Parameters: | |
9210 * mutex: The handle to the mutex returned by dw_mutex_new(). | |
9211 * Returns: | |
9212 * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. | |
9213 */ | |
9214 int API dw_mutex_trylock(HMTX mutex) | |
9215 { | |
9216 if(WaitForSingleObject((HANDLE)mutex, 0) == WAIT_OBJECT_0) | |
9217 return DW_ERROR_NONE; | |
9218 return DW_ERROR_TIMEOUT; | |
9219 } | |
9220 | |
9221 /* | |
9208 * Reliquishes the access to the semaphore. | 9222 * Reliquishes the access to the semaphore. |
9209 * Parameters: | 9223 * Parameters: |
9210 * mutex: The handle to the mutex returned by dw_mutex_new(). | 9224 * mutex: The handle to the mutex returned by dw_mutex_new(). |
9211 */ | 9225 */ |
9212 void API dw_mutex_unlock(HMTX mutex) | 9226 void API dw_mutex_unlock(HMTX mutex) |