1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include <stdlib.h>
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_barrier_init (pthread_barrier_t * barrier,
- const pthread_barrierattr_t * attr, unsigned int count)
- {
- pthread_barrier_t b;
- if (barrier == NULL || count == 0)
- {
- return EINVAL;
- }
- if (NULL != (b = (pthread_barrier_t) calloc (1, sizeof (*b))))
- {
- b->pshared = (attr != NULL && *attr != NULL
- ? (*attr)->pshared : PTHREAD_PROCESS_PRIVATE);
- b->nCurrentBarrierHeight = b->nInitialBarrierHeight = count;
- b->iStep = 0;
-
- if (0 == sem_init (&(b->semBarrierBreeched[0]), b->pshared, 0))
- {
- if (0 == sem_init (&(b->semBarrierBreeched[1]), b->pshared, 0))
- {
- *barrier = b;
- return 0;
- }
- (void) sem_destroy (&(b->semBarrierBreeched[0]));
- }
- (void) free (b);
- }
- return ENOMEM;
- }
|