summaryrefslogtreecommitdiff
path: root/mutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'mutex.c')
-rw-r--r--mutex.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/mutex.c b/mutex.c
index bef116e..448ad2a 100644
--- a/mutex.c
+++ b/mutex.c
@@ -22,7 +22,7 @@
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*/
-
+
/* errno.h or a replacement file is included by pthread.h */
//#include <errno.h>
@@ -125,11 +125,12 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
#error ERROR [__FILE__, line __LINE__]: Process shared mutexes are not supported yet.
- mx->mutex = CreateMutex (
- NULL,
- FALSE,
- ????);
- result = (mx->mutex == 0) ? EAGAIN : 0;
+ mx->mutex = CreateMutex(NULL, FALSE, "FIXME FIXME FIXME");
+
+ if (mx->mutex == 0)
+ {
+ result = EAGAIN;
+ }
#else
@@ -149,6 +150,20 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
* Create a critical section.
*/
InitializeCriticalSection(&mx->cs);
+
+ /*
+ * Check that it works ok - since InitializeCriticalSection doesn't
+ * return success or failure.
+ */
+ if (TryEnterCriticalSection(&mx->cs))
+ {
+ LeaveCriticalSection(&mx->cs);
+ }
+ else
+ {
+ DeleteCriticalSection(&mx->cs);
+ result = EAGAIN;
+ }
}
else
{
@@ -163,12 +178,16 @@ pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
if (mx->mutex == 0)
{
result = EAGAIN;
- mx = NULL;
- goto FAIL0;
}
}
}
+ if (result != 0 && mx != NULL)
+ {
+ free(mx);
+ mx = NULL;
+ }
+
FAIL0:
*mutex = mx;