From 1dc2c177f40875f9095dc3a10a5c93ad6eb45934 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Wed, 25 Sep 2013 14:44:45 +0000 Subject: [PATCH] * thread.cc (semaphore::_getvalue): Set *sval as appropriate. Set errno and return -1 on error. --- winsup/cygwin/ChangeLog | 6 ++++++ winsup/cygwin/pthread.cc | 2 +- winsup/cygwin/thread.cc | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index b1eb36602..c522bd383 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,9 @@ +2013-09-25 Christopher Faylor + Paul Kunysch + + * thread.cc (semaphore::_getvalue): Set *sval as appropriate. Set + errno and return -1 on error. + 2013-08-31 Corinna Vinschen * include/cygwin/version.h (CYGWIN_VERSION_DLL_MINOR): Belatedly bump diff --git a/winsup/cygwin/pthread.cc b/winsup/cygwin/pthread.cc index c63c1b8ac..7f12686e7 100644 --- a/winsup/cygwin/pthread.cc +++ b/winsup/cygwin/pthread.cc @@ -185,7 +185,7 @@ sem_timedwait (sem_t * sem, const struct timespec *abstime) } int -sem_post (sem_t * sem) +sem_post (sem_t *sem) { return semaphore::post (sem); } diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 0256ad717..0e0d30127 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3443,9 +3443,19 @@ semaphore::_getvalue (int *sval) status = NtQuerySemaphore (win32_obj_id, SemaphoreBasicInformation, &sbi, sizeof sbi, NULL); + int res; if (NT_SUCCESS (status)) - return sbi.CurrentCount; - return startvalue; + { + *sval = sbi.CurrentCount; + res = 0; + } + else + { + *sval = startvalue; + __seterrno_from_nt_status (status); + res = -1; + } + return res; } int