diff options
author | rpj <rpj> | 2006-12-22 02:36:40 +0000 |
---|---|---|
committer | rpj <rpj> | 2006-12-22 02:36:40 +0000 |
commit | 9e61bc0571b4812381cf89dd6f4bcbe3931f6acd (patch) | |
tree | 2b60eec9340369ed259a9d1de422ac5ec3eb9291 /sem_timedwait.c | |
parent | 1beb00e609d241ee6c2048c476e2240f05033cbd (diff) |
Diffstat (limited to 'sem_timedwait.c')
-rw-r--r-- | sem_timedwait.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/sem_timedwait.c b/sem_timedwait.c index deefa6e..52146b4 100644 --- a/sem_timedwait.c +++ b/sem_timedwait.c @@ -137,6 +137,8 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) int result = 0; sem_t s = *sem; + pthread_testcancel(); + if (sem == NULL) { result = EINVAL; @@ -157,11 +159,20 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) milliseconds = ptw32_relmillisecs (abstime); } - pthread_testcancel(); - if ((result = pthread_mutex_lock (&s->lock)) == 0) { - int v = --s->value; + int v; + + /* See sem_destroy.c + */ + if (*sem == NULL) + { + (void) pthread_mutex_unlock (&s->lock); + errno = EINVAL; + return -1; + } + + v = --s->value; (void) pthread_mutex_unlock (&s->lock); if (v < 0) @@ -192,6 +203,13 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) if (!timedout && pthread_mutex_lock (&s->lock) == 0) { + if (*sem == NULL) + { + (void) pthread_mutex_unlock (&s->lock); + errno = EINVAL; + return -1; + } + if (s->leftToUnblock > 0) { --s->leftToUnblock; |