Mercurial > dwindows
changeset 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 | 79bd0aff0bc2 |
children | 1e0cd8dafdfb |
files | dw.def dww.def gtk/dw.c gtk3/dw.c mac/dw.m os2/dw.c template/dw.c win/dw.c |
diffstat | 8 files changed, 84 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dw.def Thu Sep 15 05:10:07 2011 +0000 +++ b/dw.def Thu Sep 15 21:13:59 2011 +0000 @@ -185,6 +185,7 @@ dw_mutex_close @301 dw_mutex_lock @302 dw_mutex_unlock @303 + dw_mutex_trylock @304 dw_event_new @310 dw_event_reset @311
--- a/dww.def Thu Sep 15 05:10:07 2011 +0000 +++ b/dww.def Thu Sep 15 21:13:59 2011 +0000 @@ -182,6 +182,7 @@ dw_mutex_close @301 dw_mutex_lock @302 dw_mutex_unlock @303 + dw_mutex_trylock @304 dw_event_new @310 dw_event_reset @311
--- a/gtk/dw.c Thu Sep 15 05:10:07 2011 +0000 +++ b/gtk/dw.c Thu Sep 15 21:13:59 2011 +0000 @@ -8521,6 +8521,20 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + if(pthread_mutex_trylock(mutex) == 0) + return DW_ERROR_NONE; + return DW_ERROR_TIMEOUT; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().
--- a/gtk3/dw.c Thu Sep 15 05:10:07 2011 +0000 +++ b/gtk3/dw.c Thu Sep 15 21:13:59 2011 +0000 @@ -7399,6 +7399,20 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + if(pthread_mutex_trylock(mutex) == 0) + return DW_ERROR_NONE; + return DW_ERROR_TIMEOUT; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().
--- a/mac/dw.m Thu Sep 15 05:10:07 2011 +0000 +++ b/mac/dw.m Thu Sep 15 21:13:59 2011 +0000 @@ -8455,6 +8455,20 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + if(pthread_mutex_trylock(mutex) == 0) + return DW_ERROR_NONE; + return DW_ERROR_TIMEOUT; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().
--- a/os2/dw.c Thu Sep 15 05:10:07 2011 +0000 +++ b/os2/dw.c Thu Sep 15 21:13:59 2011 +0000 @@ -9026,6 +9026,20 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + if(DosRequestMutexSem(mutex, SEM_IMMEDIATE_RETURN) == NO_ERROR) + return DW_ERROR_NONE; + return DW_ERROR_TIMEOUT; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().
--- a/template/dw.c Thu Sep 15 05:10:07 2011 +0000 +++ b/template/dw.c Thu Sep 15 21:13:59 2011 +0000 @@ -3132,6 +3132,18 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + return DW_ERROR_GENERAL; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().
--- a/win/dw.c Thu Sep 15 05:10:07 2011 +0000 +++ b/win/dw.c Thu Sep 15 21:13:59 2011 +0000 @@ -9205,6 +9205,20 @@ } /* + * Tries to gain access to the semaphore. + * Parameters: + * mutex: The handle to the mutex returned by dw_mutex_new(). + * Returns: + * DW_ERROR_NONE on success, DW_ERROR_TIMEOUT if it is already locked. + */ +int API dw_mutex_trylock(HMTX mutex) +{ + if(WaitForSingleObject((HANDLE)mutex, 0) == WAIT_OBJECT_0) + return DW_ERROR_NONE; + return DW_ERROR_TIMEOUT; +} + +/* * Reliquishes the access to the semaphore. * Parameters: * mutex: The handle to the mutex returned by dw_mutex_new().