* 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.
This commit is contained in:
parent
471bbbe240
commit
056b8e60cd
@ -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>
|
2011-03-27 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
|
||||||
|
|
||||||
* cygwin.din (strchrnul): Export.
|
* cygwin.din (strchrnul): Export.
|
||||||
|
@ -3076,10 +3076,16 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value)
|
|||||||
{
|
{
|
||||||
/* opengroup calls this undefined */
|
/* opengroup calls this undefined */
|
||||||
if (is_good_object (sem))
|
if (is_good_object (sem))
|
||||||
return EBUSY;
|
{
|
||||||
|
set_errno(EBUSY);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (value > SEM_VALUE_MAX)
|
if (value > SEM_VALUE_MAX)
|
||||||
return EINVAL;
|
{
|
||||||
|
set_errno(EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*sem = new semaphore (pshared, value);
|
*sem = new semaphore (pshared, value);
|
||||||
|
|
||||||
@ -3087,7 +3093,8 @@ semaphore::init (sem_t *sem, int pshared, unsigned int value)
|
|||||||
{
|
{
|
||||||
delete (*sem);
|
delete (*sem);
|
||||||
*sem = NULL;
|
*sem = NULL;
|
||||||
return EAGAIN;
|
set_errno(EAGAIN);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -3096,11 +3103,17 @@ int
|
|||||||
semaphore::destroy (sem_t *sem)
|
semaphore::destroy (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (!is_good_object (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. */
|
/* It's invalid to destroy a semaphore not opened with sem_init. */
|
||||||
if ((*sem)->fd != -1)
|
if ((*sem)->fd != -1)
|
||||||
return EINVAL;
|
{
|
||||||
|
set_errno(EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME - new feature - test for busy against threads... */
|
/* FIXME - new feature - test for busy against threads... */
|
||||||
|
|
||||||
@ -3113,11 +3126,17 @@ int
|
|||||||
semaphore::close (sem_t *sem)
|
semaphore::close (sem_t *sem)
|
||||||
{
|
{
|
||||||
if (!is_good_object (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. */
|
/* It's invalid to close a semaphore not opened with sem_open. */
|
||||||
if ((*sem)->fd == -1)
|
if ((*sem)->fd == -1)
|
||||||
return EINVAL;
|
{
|
||||||
|
set_errno(EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
delete (*sem);
|
delete (*sem);
|
||||||
delete sem;
|
delete sem;
|
||||||
|
@ -21,6 +21,7 @@ details. */
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include "cygerrno.h"
|
||||||
|
|
||||||
enum cw_sig_wait
|
enum cw_sig_wait
|
||||||
{
|
{
|
||||||
@ -641,6 +642,7 @@ public:
|
|||||||
}
|
}
|
||||||
static void terminate ()
|
static void terminate ()
|
||||||
{
|
{
|
||||||
|
save_errno save;
|
||||||
semaphores.for_each (&semaphore::_terminate);
|
semaphores.for_each (&semaphore::_terminate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user