From c156eacc8b9c6f33f89c7563f2821320be79c2e1 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 1 Jul 2001 14:35:49 +0000 Subject: 2001-07-01 Ross Johnson Contributed by - Alexander Terekhov. * condvar.c: Fixed lost signal bug reported by Timur Aydin (taydin@snet.net). [RPJ (me) didn't translate the original algorithm correctly.] * semaphore.c: Added sem_post_multiple; this is a useful routine, but it doesn't appear to be standard. For now it's not an exported function. --- semaphore.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 4 deletions(-) (limited to 'semaphore.c') diff --git a/semaphore.c b/semaphore.c index 9f80f77..81b777f 100644 --- a/semaphore.c +++ b/semaphore.c @@ -121,10 +121,10 @@ sem_init (sem_t * sem, int pshared, unsigned int value) #else /* NEED_SEM */ - s->sem = CreateSemaphore (0, - value, - 0x7FFFFFF, - NULL); + s->sem = CreateSemaphore (NULL, /* Always NULL */ + value, /* Initial value */ + 0x7FFFFFFFL, /* Maximum value */ + NULL); /* Name */ if (0 == s->sem) { @@ -463,6 +463,71 @@ sem_post (sem_t * sem) } /* sem_post */ +int +sem_post_multiple (sem_t * sem, int count ) + /* + * ------------------------------------------------------ + * DOCPUBLIC + * This function posts multiple wakeups to a semaphore. + * + * PARAMETERS + * sem + * pointer to an instance of sem_t + * + * count + * counter, must be greater than or equal to zero. + * + * DESCRIPTION + * This function posts multiple wakeups to a semaphore. If there + * are waiting threads (or processes), n <= count are awakened; + * the semaphore value is incremented by count - n. + * + * RESULTS + * 0 successfully posted semaphore, + * -1 failed, error in errno + * ERRNO + * EINVAL 'sem' is not a valid semaphore + * or count is less than zero. + * + * ------------------------------------------------------ + */ +{ + int result = 0; + + if (sem == NULL || *sem == NULL || count < 0) + { + result = EINVAL; + } + else if (count == 0) + { + return 0; + } + +#ifdef NEED_SEM + + else if (! ptw32_increase_semaphore (sem, count)) + +#else /* NEED_SEM */ + + else if (! ReleaseSemaphore ((*sem)->sem, count, 0)) + +#endif /* NEED_SEM */ + + { + result = EINVAL; + } + + if (result != 0) + { + errno = result; + return -1; + } + + return 0; + +} /* sem_post_multiple */ + + int sem_open (const char * name, int oflag, mode_t mode, unsigned int value) { -- cgit v1.2.3