[PATCH] Add futex wrappers with error checking v2

Torvald Riegel triegel@redhat.com
Fri Jan 9 11:05:00 GMT 2015


This patch is a revision of
https://sourceware.org/ml/libc-alpha/2014-12/msg00134.html

This adds new functions for futex operations, starting with wait,
abstimed_wait, reltimed_wait, wake.  They add documentation and error
checking according to the outcomes of this thread:
https://sourceware.org/ml/libc-alpha/2014-09/msg00381.html

Compared to the previous patch, this splits futex_timed_wait into two
variants with relative and absolute timeouts, respectively.  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.
The latter is done by adding lll_futex_abstimed_wait.  I expect that we
will refactor this later on, depending on how we do the lll_ parts.

I have transformed the lll_futex_* uses that I saw except:
* Anything related to lowlevellock or mutexes.
* Some sparc-specific files, because the machine maintainer is
travelling until Monday.
* pthread condvar: I'm still unsure whether I can get the replacement
condvar posted before the freeze, whatever it will be.
* pthread barrier, because I need to look closer at what it does with
the private flag.
* All tls.h files.
* pthread semaphore, which I'll do by in a revision of my semaphore
patch.

>From this list, we should be able to deal with all of them except
lowlevellock, which might require more care (or maybe not) and, more
importantly, requires all futex functions to come from the
lowlevellock-futex.h files, not lowlevellock.h.  The latter is true
except on the archs whose maintainers haven't reviewed my patches for
that yet (ia64, hppa, s390).

Also note that this patch relies in some places on LLL_PRIVATE being
equal in value to FUTEX_PRIVATE.  This is something we'll have to sort
out later in the lowlevellock refactoring;  we can't easily split these
currently because the same flag (eg, on the rwlock) is used to control
private/shared for both lowlevellocks and futexes unrelated to locks.

Using the wrappers actually catched a bug in sysdeps/nptl/fork.c: The
previous code didn't provide an address but the value, so this might
have led to lost wake-ups due to the futex_wake not targeting the actual
futex.


Tested on x86_64 gnu linux.  Not tested on i386 gnu linux because I get
a build failure that doesn't seem to be related to my patch (multiple
definitions of `_dl_addr_inside_object' and `_itoa').  I'll investigate
the latter, and report if I see regressions due to my patch.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: futex-cleanupv2.patch
Type: text/x-patch
Size: 34151 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150109/683a56d3/attachment.bin>


More information about the Libc-alpha mailing list