123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #include <errno.h>
- #include <sysdep.h>
- #include <lowlevellock.h>
- #include <pthreadP.h>
- int
- pthread_barrier_wait (
- pthread_barrier_t *barrier)
- {
- struct pthread_barrier *ibarrier = (struct pthread_barrier *) barrier;
- int result = 0;
-
- lll_lock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
-
- --ibarrier->left;
-
- if (ibarrier->left == 0)
- {
-
- ++ibarrier->curr_event;
-
- lll_futex_wake (&ibarrier->curr_event, INT_MAX,
- ibarrier->private ^ FUTEX_PRIVATE_FLAG);
-
- result = PTHREAD_BARRIER_SERIAL_THREAD;
- }
- else
- {
-
- unsigned int event = ibarrier->curr_event;
-
- lll_unlock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
-
- do
- lll_futex_wait (&ibarrier->curr_event, event,
- ibarrier->private ^ FUTEX_PRIVATE_FLAG);
- while (event == ibarrier->curr_event);
- }
-
- unsigned int init_count = ibarrier->init_count;
-
- if (atomic_increment_val (&ibarrier->left) == init_count)
-
- lll_unlock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
- return result;
- }
|