summaryrefslogtreecommitdiff
path: root/sem_init.c
diff options
context:
space:
mode:
authorrpj <rpj>2002-06-03 09:19:57 +0000
committerrpj <rpj>2002-06-03 09:19:57 +0000
commitb2bca276f0fdb43e7ba4aa6baefe835d23820164 (patch)
treead8f093e264f1ac41304401847e8cdbc35609b9d /sem_init.c
parent4f0a0cc0fcbe4d63f8436a82ea186ffbe2b9e1cb (diff)
An attempt to get sem_getvalue working properly.
Diffstat (limited to 'sem_init.c')
-rw-r--r--sem_init.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/sem_init.c b/sem_init.c
index e36678c..78e9770 100644
--- a/sem_init.c
+++ b/sem_init.c
@@ -4,15 +4,13 @@
* Module: sem_init.c
*
* Purpose:
- * Semaphores aren't actually part of the PThreads standard.
+ * Semaphores aren't actually part of PThreads.
* They are defined by the POSIX Standard:
*
- * POSIX 1003.1b-1993 (POSIX.1b)
+ * POSIX 1003.1-2001
*
* -------------------------------------------------------------
*
- * --------------------------------------------------------------------------
- *
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2002 Pthreads-win32 contributors
@@ -49,14 +47,12 @@
#include "semaphore.h"
#include "implement.h"
-#include <limits.h>
-
int
sem_init (sem_t * sem, int pshared, unsigned int value)
/*
* ------------------------------------------------------
* DOCPUBLIC
- * This function initializes an unnamed semaphore. the
+ * This function initializes a semaphore. The
* initial value of the semaphore is 'value'
*
* PARAMETERS
@@ -73,7 +69,7 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
* initial value of the semaphore counter
*
* DESCRIPTION
- * This function initializes an unnamed semaphore. The
+ * This function initializes a semaphore. The
* initial value of the semaphore is set to 'value'.
*
* RESULTS
@@ -106,45 +102,46 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
s = (sem_t) calloc (1, sizeof (*s));
if (NULL == s)
- {
- result = ENOMEM;
- }
+ {
+ result = ENOMEM;
+ }
#ifdef NEED_SEM
else
- {
- s->value = value;
- s->event = CreateEvent (NULL,
- FALSE, /* manual reset */
- FALSE, /* initial state */
- NULL);
- if (0 == s->event)
- {
- result = ENOSPC;
- }
- else
- {
- if (value != 0)
- {
- SetEvent(s->event);
- }
-
- InitializeCriticalSection(&s->sem_lock_cs);
- }
- }
-
+ {
+ s->value = value;
+ s->event = CreateEvent (NULL,
+ FALSE, /* manual reset */
+ FALSE, /* initial state */
+ NULL);
+
+ if (0 == s->event)
+ {
+ result = ENOSPC;
+ }
+ else
+ {
+ if (value != 0)
+ {
+ SetEvent(s->event);
+ }
+
+ InitializeCriticalSection(&s->sem_lock_cs);
+ }
+ }
+
#else /* NEED_SEM */
s->sem = CreateSemaphore (NULL, /* Always NULL */
- value, /* Initial value */
- INT_MAX, /* Maximum value */
- NULL); /* Name */
-
+ value, /* Initial value */
+ _POSIX_SEM_VALUE_MAX, /* Maximum value */
+ NULL); /* Name */
+
if (0 == s->sem)
- {
- result = ENOSPC;
- }
+ {
+ result = ENOSPC;
+ }
#endif /* NEED_SEM */