summaryrefslogtreecommitdiff
path: root/sem_post.c
diff options
context:
space:
mode:
authorrpj <rpj>2005-05-06 07:27:10 +0000
committerrpj <rpj>2005-05-06 07:27:10 +0000
commit7523c7c4d75652f67cd31cb123e1268790394c8b (patch)
tree0920ebf089ccb971e0878542f85486171a541a8a /sem_post.c
parentcf42850c77554311e62d3780f6a36cbc38e5e002 (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);
}