Index: src/untrusted/pthread/nc_semaphore.c |
diff --git a/src/untrusted/pthread/nc_semaphore.c b/src/untrusted/pthread/nc_semaphore.c |
index 84a31f78f94443929f11709c63cc651070d95cf9..346e928b7c6dd47637fdff3d28c291855aaa5014 100644 |
--- a/src/untrusted/pthread/nc_semaphore.c |
+++ b/src/untrusted/pthread/nc_semaphore.c |
@@ -103,6 +103,19 @@ int sem_wait(sem_t *sem) { |
return 0; |
} |
+int sem_trywait(sem_t *sem) { |
+ if (NULL == sem) { |
Roland McGrath
2013/07/12 21:15:58
Failing gracefully rather than crashing when passe
Mark Seaborn
2013/07/15 15:51:21
OK, I've removed the NULL checks.
The NULL check
|
+ errno = EINVAL; |
+ return -1; |
+ } |
+ |
+ if (decrement_if_positive(&sem->count)) |
+ return 0; |
+ |
+ errno = EAGAIN; |
+ return -1; |
+} |
+ |
int sem_post(sem_t *sem) { |
if (NULL == sem) { |
errno = EINVAL; |
@@ -132,3 +145,13 @@ int sem_post(sem_t *sem) { |
} |
return 0; |
} |
+ |
+int sem_getvalue(sem_t *sem, int *value) { |
+ if (NULL == sem || NULL == value) { |
Roland McGrath
2013/07/12 21:15:58
See above about checking |sem| being a null pointe
Mark Seaborn
2013/07/15 15:51:21
Done.
|
+ errno = EINVAL; |
+ return -1; |
+ } |
+ |
+ *value = sem->count; |
+ return 0; |
+} |