summaryrefslogtreecommitdiff
path: root/semaphore.c
diff options
context:
space:
mode:
authorrpj <rpj>2001-07-01 14:35:49 +0000
committerrpj <rpj>2001-07-01 14:35:49 +0000
commitc156eacc8b9c6f33f89c7563f2821320be79c2e1 (patch)
treee43c9e4dcfc56577e2dac01c39d4a10ea91c5dc4 /semaphore.c
parent19299847fdd32094b28377db1aea61b0f605dc8b (diff)
2001-07-01 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
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.
Diffstat (limited to 'semaphore.c')
-rw-r--r--semaphore.c73
1 files changed, 69 insertions, 4 deletions
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)
{
@@ -464,6 +464,71 @@ sem_post (sem_t * sem)
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)
{
errno = ENOSYS;