summaryrefslogtreecommitdiff
path: root/sem_post.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-05-06 07:31:28 +0000
committerrpj <rpj>2005-05-06 07:31:28 +0000
commit78f83cfa240ec14874b22c7302ff8d306c130aaf (patch)
treebf29a117aecb99e9ecb2d30bad398d8b20392b49 /sem_post.c
parente3845d9b6b0a18ffdfdf0cefd811a17fce62f1ac (diff)
''
Diffstat (limited to 'sem_post.c')
-rw-r--r--sem_post.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/sem_post.c b/sem_post.c
index f4f48e1..2edaecf 100644
--- a/sem_post.c
+++ b/sem_post.c
@@ -68,6 +68,7 @@ sem_post (sem_t * sem)
* ERRNO
* EINVAL 'sem' is not a valid semaphore,
* ENOSYS semaphores are not supported,
+ * ERANGE semaphore count is too big
*
* ------------------------------------------------------
*/
@@ -81,23 +82,29 @@ sem_post (sem_t * sem)
}
else if ((result = pthread_mutex_lock (&s->lock)) == 0)
{
-#ifdef NEED_SEM
-
- if (++s->value <= 0)
+ if (s->value < _POSIX_SEM_VALUE_MAX)
{
- if (!SetEvent(s->sem))
+#ifdef NEED_SEM
+ if (++s->value <= 0
+ && !SetEvent(s->sem))
{
+ s->value--;
result = EINVAL;
}
- }
#else
- if (++s->value <= 0
- && !ReleaseSemaphore (s->sem, 1, NULL))
+ if (++s->value <= 0
+ && !ReleaseSemaphore (s->sem, 1, NULL))
+ {
+ s->value--;
+ result = EINVAL;
+ }
+#endif /* NEED_SEM */
+ }
+ else
{
- result = EINVAL;
+ result = ERANGE;
}
-#endif /* NEED_SEM */
-
+
(void) pthread_mutex_unlock (&s->lock);
}