From b2bca276f0fdb43e7ba4aa6baefe835d23820164 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 3 Jun 2002 09:19:57 +0000 Subject: An attempt to get sem_getvalue working properly. --- sem_getvalue.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'sem_getvalue.c') 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; } -- cgit v1.2.3