diff os2/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 58b5374355ab
children 924c8087a755
line wrap: on
line diff
--- 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().