1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

Fix semaphore destruction (bug 12674).

This commit fixes semaphore destruction by either using 64b atomic
operations (where available), or by using two separate fields when only
32b atomic operations are available.  In the latter case, we keep a
conservative estimate of whether there are any waiting threads in one
bit of the field that counts the number of available tokens, thus
allowing sem_post to atomically both add a token and determine whether
it needs to call futex_wake.

See:
https://sourceware.org/ml/libc-alpha/2014-12/msg00155.html
This commit is contained in:
Carlos O'Donell
2015-01-21 00:46:16 -05:00
parent a8db092ec0
commit 042e1521c7
34 changed files with 731 additions and 2102 deletions

View File

@ -193,9 +193,14 @@ sem_open (const char *name, int oflag, ...)
struct new_sem newsem;
} sem;
sem.newsem.value = value;
sem.newsem.private = 0;
#if __HAVE_64B_ATOMICS
sem.newsem.data = value;
#else
sem.newsem.value = value << SEM_VALUE_SHIFT;
sem.newsem.nwaiters = 0;
#endif
/* This always is a shared semaphore. */
sem.newsem.private = LLL_SHARED;
/* Initialize the remaining bytes as well. */
memset ((char *) &sem.initsem + sizeof (struct new_sem), '\0',