summaryrefslogtreecommitdiff
path: root/sem_getvalue.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-22 15:06:41 +0000
committerrpj <rpj>2004-10-22 15:06:41 +0000
commit045278e11b53fc1ad59945427feab1cd9275988f (patch)
treeda8570a7a8962d9563814c4910e8a9d5fb6fa685 /sem_getvalue.c
parentf84df26e12431bb9ecd07fbc52c804538635901f (diff)
Changes to mutexes and semaphores - considered alpha for now
Diffstat (limited to 'sem_getvalue.c')
-rw-r--r--sem_getvalue.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/sem_getvalue.c b/sem_getvalue.c
index eb6e6af..f2efd10 100644
--- a/sem_getvalue.c
+++ b/sem_getvalue.c
@@ -52,9 +52,7 @@ sem_getvalue (sem_t * sem, int *sval)
* ------------------------------------------------------
* DOCPUBLIC
* This function stores the current count value of the
- * semaphore. If the count is negative, it's absolute
- * value is the number of threads currently waiting on
- * the semaphore.
+ * semaphore.
* RESULTS
*
* Return value
@@ -88,21 +86,27 @@ sem_getvalue (sem_t * sem, int *sval)
{
long value;
register sem_t s = *sem;
+ int result = 0;
#ifdef NEED_SEM
EnterCriticalSection (&s->sem_lock_cs);
value = s->value;
LeaveCriticalSection (&s->sem_lock_cs);
+ *sval = value;
#else
- value = s->value;
+ if ((result = pthread_mutex_lock(&s->lock)) == 0)
+ {
+ value = s->value;
+ (void) pthread_mutex_unlock(&s->lock);
+ *sval = value;
+ }
#endif
- *sval = value;
- return 0;
+ return result;
}
} /* sem_getvalue */