summaryrefslogtreecommitdiff
path: root/sem_post.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_post.c
parentf84df26e12431bb9ecd07fbc52c804538635901f (diff)
Changes to mutexes and semaphores - considered alpha for now
Diffstat (limited to 'sem_post.c')
-rw-r--r--sem_post.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/sem_post.c b/sem_post.c
index 7e20659..5b678c6 100644
--- a/sem_post.c
+++ b/sem_post.c
@@ -73,8 +73,11 @@ sem_post (sem_t * sem)
*/
{
int result = 0;
+#ifndef NEED_SEM
+ sem_t s = *sem;
+#endif
- if (sem == NULL || *sem == NULL)
+ if (s == NULL)
{
result = EINVAL;
}
@@ -82,18 +85,25 @@ sem_post (sem_t * sem)
#ifdef NEED_SEM
else if (!ptw32_increase_semaphore (sem, 1))
+ {
+ result = EINVAL;
+ }
#else /* NEED_SEM */
- else if (InterlockedIncrement((LPLONG) &(*sem)->value) <= 0
- && !ReleaseSemaphore((*sem)->sem, 1, NULL))
-
-#endif /* NEED_SEM */
-
+ else if ((result = pthread_mutex_lock (&s->lock)) == 0)
{
- result = EINVAL;
+ if (++s->value <= 0
+ && !ReleaseSemaphore (s->sem, 1, NULL))
+ {
+ result = EINVAL;
+ }
+
+ (void) pthread_mutex_unlock (&s->lock);
}
+#endif /* NEED_SEM */
+
if (result != 0)
{
errno = result;