summaryrefslogtreecommitdiff
path: root/sem_init.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-05-17 01:38:02 +0000
committerrpj <rpj>2004-05-17 01:38:02 +0000
commit771465fed0cf50ee2dd790723245fc091699c324 (patch)
treed8c18d095a33fe7c4564bd90c5f313bb9e4057dd /sem_init.c
parent8b14911744f58cbe3730703f3fcc41cd969fd0f3 (diff)
re-indentation, bug fixes, hooks for pre-emptive async cancelation
Diffstat (limited to 'sem_init.c')
-rw-r--r--sem_init.c102
1 files changed, 48 insertions, 54 deletions
diff --git a/sem_init.c b/sem_init.c
index 4841530..eca0026 100644
--- a/sem_init.c
+++ b/sem_init.c
@@ -11,8 +11,6 @@
*
* -------------------------------------------------------------
*
- * --------------------------------------------------------------------------
- *
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2003 Pthreads-win32 contributors
@@ -41,10 +39,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
-#ifndef _UWIN
-# include <process.h>
-#endif
-
#include "pthread.h"
#include "semaphore.h"
#include "implement.h"
@@ -59,29 +53,30 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
*
* PARAMETERS
* sem
- * pointer to an instance of sem_t
+ * pointer to an instance of sem_t
*
* pshared
- * if zero, this semaphore may only be shared between
- * threads in the same process.
- * if nonzero, the semaphore can be shared between
- * processes
+ * if zero, this semaphore may only be shared between
+ * threads in the same process.
+ * if nonzero, the semaphore can be shared between
+ * processes
*
* value
- * initial value of the semaphore counter
+ * initial value of the semaphore counter
*
* DESCRIPTION
* This function initializes a semaphore. The
* initial value of the semaphore is set to 'value'.
*
* RESULTS
- * 0 successfully created semaphore,
- * -1 failed, error in errno
+ * 0 successfully created semaphore,
+ * -1 failed, error in errno
* ERRNO
- * EINVAL 'sem' is not a valid semaphore,
- * ENOSPC a required resource has been exhausted,
- * ENOSYS semaphores are not supported,
- * EPERM the process lacks appropriate privilege
+ * EINVAL 'sem' is not a valid semaphore,
+ * ENOMEM out of memory,
+ * ENOSPC a required resource has been exhausted,
+ * ENOSYS semaphores are not supported,
+ * EPERM the process lacks appropriate privilege
*
* ------------------------------------------------------
*/
@@ -96,57 +91,56 @@ sem_init (sem_t * sem, int pshared, unsigned int value)
* processes
*/
result = EPERM;
-
}
else
{
-
s = (sem_t) calloc (1, sizeof (*s));
if (NULL == s)
- {
- result = ENOMEM;
- }
+ {
+ result = ENOMEM;
+ }
+ else
+ {
#ifdef NEED_SEM
- else
- {
- s->value = value;
- s->event = CreateEvent (NULL,
- PTW32_FALSE, /* manual reset */
- PTW32_FALSE, /* initial state */
- NULL);
-
- if (0 == s->event)
- {
- result = ENOSPC;
- }
- else
- {
- if (value != 0)
- {
- SetEvent(s->event);
- }
-
- InitializeCriticalSection(&s->sem_lock_cs);
- }
- }
+ s->value = value;
+ s->event = CreateEvent (NULL, PTW32_FALSE, /* manual reset */
+ PTW32_FALSE, /* initial state */
+ NULL);
+
+ if (0 == s->event)
+ {
+ free (s);
+ result = ENOSPC;
+ }
+ else
+ {
+ if (value != 0)
+ {
+ SetEvent (s->event);
+ }
+
+ InitializeCriticalSection (&s->sem_lock_cs);
+ }
#else /* NEED_SEM */
- s->sem = CreateSemaphore (NULL, /* Always NULL */
- (long) value, /* Initial value */
- (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
- NULL); /* Name */
-
- if (0 == s->sem)
- {
- result = ENOSPC;
- }
+ s->sem = CreateSemaphore (NULL, /* Always NULL */
+ (long) value, /* Initial value */
+ (long) _POSIX_SEM_VALUE_MAX, /* Maximum value */
+ NULL); /* Name */
+
+ if (0 == s->sem)
+ {
+ free (s);
+ result = ENOSPC;
+ }
#endif /* NEED_SEM */
+ }
}
if (result != 0)