summaryrefslogtreecommitdiff
path: root/sem_getvalue.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_getvalue.c
parent4f0a0cc0fcbe4d63f8436a82ea186ffbe2b9e1cb (diff)
An attempt to get sem_getvalue working properly.
Diffstat (limited to 'sem_getvalue.c')
-rw-r--r--sem_getvalue.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sem_getvalue.c b/sem_getvalue.c
index abc76c0..b3033d3 100644
--- a/sem_getvalue.c
+++ b/sem_getvalue.c
@@ -4,15 +4,13 @@
* Module: sem_getvalue.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
@@ -93,19 +91,24 @@ sem_getvalue(sem_t * sem, int * sval)
#else
long value = *sval;
- /* Note:
- * The windows NT documentation says that the increment must be
- * greater than zero, but it is set to zero here. If this works,
- * the function will return true. If not, we can't do it this way
- * so flag it as not implemented.
- */
+ /* From "Win32 System Programming - Second Edition"
+ * by Johnson M Hart, chapter 9, page 256 :
+ *
+ * "The release count must be greater than zero, but if it
+ * would cause the semaphore count to exceed the maximum,
+ * the call will fail, returning FALSE, and the count will
+ * remain unchanged. Releasing a semaphore with a large count
+ * is a method used to obtain the current count atomically
+ * (of course, another thread might change the value immediately)."
+ */
- if ( ReleaseSemaphore( (*sem)->sem, 0L, &value) )
+ if ( ! ReleaseSemaphore( (*sem)->sem, _POSIX_SEM_VALUE_MAX + 1, &value) )
{
*sval = value;
}
else
{
+ /* This should NEVER occur. */
result = ENOSYS;
}