123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "pthread.h"
- #include "implement.h"
- int
- pthread_barrier_wait (pthread_barrier_t * barrier)
- {
- int result;
- int step;
- pthread_barrier_t b;
- if (barrier == NULL || *barrier == (pthread_barrier_t) PTE_OBJECT_INVALID)
- {
- return EINVAL;
- }
- b = *barrier;
- step = b->iStep;
- if (0 == PTE_ATOMIC_DECREMENT ((int *) &(b->nCurrentBarrierHeight)))
- {
-
- b->nCurrentBarrierHeight = b->nInitialBarrierHeight;
-
- result = (b->nInitialBarrierHeight > 1
- ? sem_post_multiple (&(b->semBarrierBreeched[step]),
- b->nInitialBarrierHeight - 1) : 0);
- }
- else
- {
-
- result = sem_wait (&(b->semBarrierBreeched[step]));
- }
-
- if (0 == result)
- {
- result = (step ==
- PTE_ATOMIC_COMPARE_EXCHANGE (& (b->iStep),(1L - step),step) ?
- PTHREAD_BARRIER_SERIAL_THREAD : 0);
- }
- return (result);
- }
|