summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ANNOUNCE4
-rw-r--r--ChangeLog8
-rw-r--r--implement.h6
-rw-r--r--private.c4
-rw-r--r--semaphore.c45
-rw-r--r--semaphore.h2
-rw-r--r--tests/ChangeLog5
-rw-r--r--tests/condvar3_2.c1
-rw-r--r--tests/mutex5.c24
9 files changed, 56 insertions, 43 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index 82678a1..b9b4970 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -293,8 +293,8 @@ The following functions are implemented:
pthread_attr_setschedparam
pthread_getschedparam
pthread_setschedparam
- pthread_getconcurrency (always returns '0' indicating system default)
- pthread_setconcurrency (accepts any value >= 0 but is ignored)
+ pthread_getconcurrency
+ pthread_setconcurrency
pthread_attr_getscope (returns an error ENOSYS)
pthread_attr_setscope (returns an error ENOSYS)
sched_get_priority_max (POSIX 1b)
diff --git a/ChangeLog b/ChangeLog
index 013c3e9..c88e5e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2001-06-08 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
+
+ * semaphore.h (sem_t): Fixed for compile and test.
+ * implement.h (sem_t_): Likewise.
+ * semaphore.c: Likewise.
+ * private.c (ptw32_sem_timedwait): Updated to use new
+ opaque sem_t.
+
2001-06-06 Ross Johnson <rpj@setup1.ise.canberra.edu.au>
* semaphore.h (sem_t): Is now an opaque pointer;
diff --git a/implement.h b/implement.h
index 9518f9e..0df0e4c 100644
--- a/implement.h
+++ b/implement.h
@@ -119,15 +119,15 @@ struct pthread_attr_t_ {
* ====================
*/
+struct sem_t_ {
#ifdef NEED_SEM
-typedef struct {
unsigned int value;
CRITICAL_SECTION sem_lock_cs;
HANDLE event;
-} sem_t_;
#else /* NEED_SEM */
-typedef HANDLE sem_t_;
+ HANDLE sem;
#endif /* NEED_SEM */
+};
#define PTW32_OBJECT_AUTO_INIT ((void *) -1)
#define PTW32_OBJECT_INVALID NULL
diff --git a/private.c b/private.c
index 5274da9..ecae84a 100644
--- a/private.c
+++ b/private.c
@@ -899,11 +899,11 @@ ptw32_sem_timedwait (sem_t * sem, const struct timespec * abstime)
#ifdef NEED_SEM
- result = (pthreadCancelableTimedWait (sem->event, milliseconds));
+ result = (pthreadCancelableTimedWait ((*sem)->event, milliseconds));
#else /* NEED_SEM */
- result = (pthreadCancelableTimedWait (*sem, milliseconds));
+ result = (pthreadCancelableTimedWait ((*sem)->sem, milliseconds));
#endif
diff --git a/semaphore.c b/semaphore.c
index 0f06c4b..9f80f77 100644
--- a/semaphore.c
+++ b/semaphore.c
@@ -37,6 +37,7 @@
#include "pthread.h"
#include "semaphore.h"
+#include "implement.h"
int
sem_init (sem_t * sem, int pshared, unsigned int value)
@@ -76,7 +77,7 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
*/
{
int result = 0;
-
+ sem_t s;
if (pshared != 0)
{
@@ -89,12 +90,11 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
}
else
{
+ s = (sem_t) calloc (1, sizeof (*s));
#ifdef NEED_SEM
- sem_t s = (sem_t) calloc (1, sizeof (*sem_t));
-
- if (s == NULL)
+ if (NULL == s)
{
result = ENOMEM;
}
@@ -105,7 +105,7 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
FALSE, /* manual reset */
FALSE, /* initial state */
NULL);
- if (s->Event == 0)
+ if (0 == s->Event)
{
result = ENOSPC;
}
@@ -115,25 +115,18 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
{
SetEvent(s->event);
}
- InitializeCriticalSection(&s->sem_lock_cs);
- *sem = s;
+ InitializeCriticalSection(&s->sem_lock_cs);
}
#else /* NEED_SEM */
- /*
- * NOTE: Taking advantage of the fact that
- * sem_t is a simple structure with one entry;
- * We don't have to allocate it...
- */
- *sem = CreateSemaphore (
- 0,
- value,
- 0x7FFFFFF,
- NULL);
+ s->sem = CreateSemaphore (0,
+ value,
+ 0x7FFFFFF,
+ NULL);
- if (*sem == 0)
+ if (0 == s->sem)
{
result = ENOSPC;
}
@@ -148,6 +141,8 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
return -1;
}
+ *sem = s;
+
return 0;
} /* sem_init */
@@ -180,7 +175,7 @@ sem_destroy (sem_t * sem)
*/
{
int result = 0;
- sem_t s = *sem;
+ sem_t s;
if (sem == NULL || *sem == NULL)
{
@@ -188,12 +183,14 @@ sem_destroy (sem_t * sem)
}
else
{
+ s = *sem;
*sem = NULL;
#ifdef NEED_SEM
if (! CloseHandle(s->event))
{
+ *sem = s;
result = EINVAL;
}
else
@@ -204,8 +201,9 @@ sem_destroy (sem_t * sem)
#else /* NEED_SEM */
- if (! CloseHandle (s))
+ if (! CloseHandle (s->sem))
{
+ *sem = s;
result = EINVAL;
}
@@ -215,7 +213,6 @@ sem_destroy (sem_t * sem)
if (result != 0)
{
- *sem = s;
errno = result;
return -1;
}
@@ -271,7 +268,7 @@ sem_trywait (sem_t * sem)
{
result = EINVAL;
}
- else if (WaitForSingleObject (*sem, 0) == WAIT_TIMEOUT)
+ else if (WaitForSingleObject ((*sem)->sem, 0) == WAIT_TIMEOUT)
{
result = EAGAIN;
}
@@ -385,7 +382,7 @@ sem_wait (sem_t * sem)
#else /* NEED_SEM */
- result = pthreadCancelableWait (*sem);
+ result = pthreadCancelableWait ((*sem)->sem);
#endif /* NEED_SEM */
@@ -447,7 +444,7 @@ sem_post (sem_t * sem)
#else /* NEED_SEM */
- else if (! ReleaseSemaphore (*sem, 1, 0))
+ else if (! ReleaseSemaphore ((*sem)->sem, 1, 0))
#endif /* NEED_SEM */
diff --git a/semaphore.h b/semaphore.h
index 3616b11..71679dd 100644
--- a/semaphore.h
+++ b/semaphore.h
@@ -65,7 +65,7 @@ typedef unsigned int mode_t;
#endif
-typedef sem_t_ * sem_t;
+typedef struct sem_t_ * sem_t;
int sem_init (sem_t * sem,
int pshared,
diff --git a/tests/ChangeLog b/tests/ChangeLog
index e7026f2..27f8dfe 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2001-06-8 Ross Johnson <rpj@special.ise.canberra.edu.au>
+
+ * mutex5.c: Insert inert change to quell compiler warnings.
+ * condvar3_2.c: Remove unused variable.
+
2001-06-3 Ross Johnson <rpj@special.ise.canberra.edu.au>
* condvar2_1.c: New test.
diff --git a/tests/condvar3_2.c b/tests/condvar3_2.c
index cd1565d..e5f451b 100644
--- a/tests/condvar3_2.c
+++ b/tests/condvar3_2.c
@@ -51,7 +51,6 @@ static pthread_mutex_t mutex;
static struct timespec abstime = { 0, 0 };
static struct timespec abstime2 = { 0, 0 };
static int timedout = 0;
-static int signaled = 0;
static int awoken = 0;
enum {
diff --git a/tests/mutex5.c b/tests/mutex5.c
index 6a9a917..d7b9064 100644
--- a/tests/mutex5.c
+++ b/tests/mutex5.c
@@ -13,19 +13,23 @@ int
main()
{
int mxType = -1;
+ int bool = 0; /* Use to quell GNU compiler warnings. */
- assert(PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL);
- assert(PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_ERRORCHECK);
- assert(PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_RECURSIVE);
- assert(PTHREAD_MUTEX_RECURSIVE != PTHREAD_MUTEX_ERRORCHECK);
+ assert(bool = PTHREAD_MUTEX_DEFAULT == PTHREAD_MUTEX_NORMAL);
+ assert(bool = PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_ERRORCHECK);
+ assert(bool = PTHREAD_MUTEX_DEFAULT != PTHREAD_MUTEX_RECURSIVE);
+ assert(bool = PTHREAD_MUTEX_RECURSIVE != PTHREAD_MUTEX_ERRORCHECK);
- assert(PTHREAD_MUTEX_NORMAL == PTHREAD_MUTEX_FAST_NP);
- assert(PTHREAD_MUTEX_RECURSIVE == PTHREAD_MUTEX_RECURSIVE_NP);
- assert(PTHREAD_MUTEX_ERRORCHECK == PTHREAD_MUTEX_ERRORCHECK_NP);
+ assert(bool = PTHREAD_MUTEX_NORMAL == PTHREAD_MUTEX_FAST_NP);
+ assert(bool = PTHREAD_MUTEX_RECURSIVE == PTHREAD_MUTEX_RECURSIVE_NP);
+ assert(bool = PTHREAD_MUTEX_ERRORCHECK == PTHREAD_MUTEX_ERRORCHECK_NP);
- assert(pthread_mutexattr_init(&mxAttr) == 0);
- assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
- assert(mxType == PTHREAD_MUTEX_NORMAL);
+ if (bool == bool)
+ {
+ assert(pthread_mutexattr_init(&mxAttr) == 0);
+ assert(pthread_mutexattr_gettype(&mxAttr, &mxType) == 0);
+ assert(mxType == PTHREAD_MUTEX_NORMAL);
+ }
return 0;
}