summaryrefslogtreecommitdiff
path: root/nptl/pthread_barrier_wait.c
diff options
context:
space:
mode:
authorTorvald Riegel <triegel@redhat.com>2014-12-04 14:12:23 +0100
committerTorvald Riegel <triegel@redhat.com>2015-07-10 13:47:09 +0200
commita2f0363f817a58c4d3f439aa515a3b1d73efde36 (patch)
tree6204a1208c1421d573e8c91e4523376a18e1dd60 /nptl/pthread_barrier_wait.c
parent203c1a898dd2e281eae30f3c57ceb8d4a50b00f4 (diff)
Add and use new glibc-internal futex API.
This adds new functions for futex operations, starting with wait, abstimed_wait, reltimed_wait, wake. They add documentation and error checking according to the current draft of the Linux kernel futex manpage. Waiting with absolute or relative timeouts is split into separate functions. This allows for removing a few cases of code duplication in pthreads code, which uses absolute timeouts; also, it allows us to put platform-specific code to go from an absolute to a relative timeout into the platform-specific futex abstractions.. Futex operations that can be canceled are also split out into separate functions suffixed by "_cancelable". There are separate versions for both Linux and NaCl; while they currently differ only slightly, my expectation is that the separate versions of lowlevellock-futex.h will eventually be merged into futex-internal.h when we get to move the lll_ functions over to the new futex API.
Diffstat (limited to 'nptl/pthread_barrier_wait.c')
-rw-r--r--nptl/pthread_barrier_wait.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/nptl/pthread_barrier_wait.c b/nptl/pthread_barrier_wait.c
index d69a929ef6..2b34e3097b 100644
--- a/nptl/pthread_barrier_wait.c
+++ b/nptl/pthread_barrier_wait.c
@@ -19,6 +19,7 @@
#include <errno.h>
#include <sysdep.h>
#include <lowlevellock.h>
+#include <futex-internal.h>
#include <pthreadP.h>
@@ -29,9 +30,12 @@ __pthread_barrier_wait (barrier)
{
struct pthread_barrier *ibarrier = (struct pthread_barrier *) barrier;
int result = 0;
+ int lll_private = ibarrier->private ^ FUTEX_PRIVATE_FLAG;
+ int futex_private = (lll_private == LLL_PRIVATE
+ ? FUTEX_PRIVATE : FUTEX_SHARED);
/* Make sure we are alone. */
- lll_lock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
+ lll_lock (ibarrier->lock, lll_private);
/* One more arrival. */
--ibarrier->left;
@@ -44,8 +48,7 @@ __pthread_barrier_wait (barrier)
++ibarrier->curr_event;
/* Wake up everybody. */
- lll_futex_wake (&ibarrier->curr_event, INT_MAX,
- ibarrier->private ^ FUTEX_PRIVATE_FLAG);
+ futex_wake (&ibarrier->curr_event, INT_MAX, futex_private);
/* This is the thread which finished the serialization. */
result = PTHREAD_BARRIER_SERIAL_THREAD;
@@ -57,12 +60,11 @@ __pthread_barrier_wait (barrier)
unsigned int event = ibarrier->curr_event;
/* Before suspending, make the barrier available to others. */
- lll_unlock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
+ lll_unlock (ibarrier->lock, lll_private);
/* Wait for the event counter of the barrier to change. */
do
- lll_futex_wait (&ibarrier->curr_event, event,
- ibarrier->private ^ FUTEX_PRIVATE_FLAG);
+ futex_wait_simple (&ibarrier->curr_event, event, futex_private);
while (event == ibarrier->curr_event);
}
@@ -72,7 +74,7 @@ __pthread_barrier_wait (barrier)
/* If this was the last woken thread, unlock. */
if (atomic_increment_val (&ibarrier->left) == init_count)
/* We are done. */
- lll_unlock (ibarrier->lock, ibarrier->private ^ FUTEX_PRIVATE_FLAG);
+ lll_unlock (ibarrier->lock, lll_private);
return result;
}