diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2011-03-29 11:49:25 +0400 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2011-03-29 11:49:25 +0400 |
commit | 056b8e60cda1874626c9592ef59c48d4c351a315 (patch) | |
tree | 1a8558a7bbaa7b0da2be0d5468d74a97d16624d2 | |
parent | 471bbbe240f91c67130e965208db8b245ca9d429 (diff) |
* thread.cc (semaphore::init, destroy, close): Standards conformance
fix. On a failure, return -1 and set errno.
* thread.h (semaphore::terminate): Save errno since semaphore::close()
may now modify it.
-rw-r--r-- | winsup/cygwin/ChangeLog | 7 | ||||
-rw-r--r-- | winsup/cygwin/thread.cc | 33 | ||||
-rw-r--r-- | winsup/cygwin/thread.h | 2 |
3 files changed, 35 insertions, 7 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index c7dbfc7ac..b7296bb5f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2011-03-28 Jon TURNEY <jon.turney@dronecode.org.uk> + + * thread.cc (semaphore::init, destroy, close): Standards conformance + fix. On a failure, return -1 and set errno. + * thread.h (semaphore::terminate): Save errno since semaphore::close() + may now modify it. + 2011-03-27 Yaakov Selkowitz <yselkowitz@users.sourceforge.net> * cygwin.din (strchrnul): Export. diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 628d1d13f..891b43fb9 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -3076,10 +3076,16 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value) { /* opengroup calls this undefined */ if (is_good_object (sem)) - return EBUSY; + { + set_errno(EBUSY); + return -1; + } if (value > SEM_VALUE_MAX) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } *sem = new semaphore (pshared, value); @@ -3087,7 +3093,8 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value) { delete (*sem); *sem = NULL; - return EAGAIN; + set_errno(EAGAIN); + return -1; } return 0; } @@ -3096,11 +3103,17 @@ int semaphore::destroy (sem_t *sem) { if (!is_good_object (sem)) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* It's invalid to destroy a semaphore not opened with sem_init. */ if ((*sem)->fd != -1) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* FIXME - new feature - test for busy against threads... */ @@ -3113,11 +3126,17 @@ int semaphore::close (sem_t *sem) { if (!is_good_object (sem)) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } /* It's invalid to close a semaphore not opened with sem_open. */ if ((*sem)->fd == -1) - return EINVAL; + { + set_errno(EINVAL); + return -1; + } delete (*sem); delete sem; diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h index 62bd1b959..bea8e2aa3 100644 --- a/winsup/cygwin/thread.h +++ b/winsup/cygwin/thread.h @@ -21,6 +21,7 @@ details. */ #include <limits.h> #include "security.h" #include <errno.h> +#include "cygerrno.h" enum cw_sig_wait { @@ -641,6 +642,7 @@ public: } static void terminate () { + save_errno save; semaphores.for_each (&semaphore::_terminate); } |