summaryrefslogtreecommitdiff
path: root/src/thread
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-09-29 14:02:06 -0400
committerRich Felker <dalias@aerifal.cx>2020-10-14 20:27:12 -0400
commit69a1b39019c51258af14c0b2d836c23d20929c9a (patch)
tree082ab5011895176fceda6854f817a4f52a541841 /src/thread
parentb115bee4dd7c33ec719fe2fc566d41c0e2133c85 (diff)
downloadmusl-69a1b39019c51258af14c0b2d836c23d20929c9a.tar.gz
musl-69a1b39019c51258af14c0b2d836c23d20929c9a.tar.bz2
musl-69a1b39019c51258af14c0b2d836c23d20929c9a.tar.xz
musl-69a1b39019c51258af14c0b2d836c23d20929c9a.zip
drop use of pthread_once in mutexattr kernel support tests
this makes the code slightly smaller and eliminates these functions from relevance to possible future changes to multithreaded fork. the barrier of a_store isn't technically needed here, but a_store is used anyway for internal consistency of the memory model.
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/pthread_mutexattr_setprotocol.c19
-rw-r--r--src/thread/pthread_mutexattr_setrobust.c20
2 files changed, 18 insertions, 21 deletions
diff --git a/src/thread/pthread_mutexattr_setprotocol.c b/src/thread/pthread_mutexattr_setprotocol.c
index 511cc32d..8b80c1ce 100644
--- a/src/thread/pthread_mutexattr_setprotocol.c
+++ b/src/thread/pthread_mutexattr_setprotocol.c
@@ -1,24 +1,23 @@
#include "pthread_impl.h"
#include "syscall.h"
-static pthread_once_t check_pi_once;
-static int check_pi_result;
-
-static void check_pi()
-{
- volatile int lk = 0;
- check_pi_result = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
-}
+static volatile int check_pi_result = -1;
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
{
+ int r;
switch (protocol) {
case PTHREAD_PRIO_NONE:
a->__attr &= ~8;
return 0;
case PTHREAD_PRIO_INHERIT:
- pthread_once(&check_pi_once, check_pi);
- if (check_pi_result) return check_pi_result;
+ r = check_pi_result;
+ if (r < 0) {
+ volatile int lk = 0;
+ r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
+ a_store(&check_pi_result, r);
+ }
+ if (r) return r;
a->__attr |= 8;
return 0;
case PTHREAD_PRIO_PROTECT:
diff --git a/src/thread/pthread_mutexattr_setrobust.c b/src/thread/pthread_mutexattr_setrobust.c
index 04db92a6..30a9ac3b 100644
--- a/src/thread/pthread_mutexattr_setrobust.c
+++ b/src/thread/pthread_mutexattr_setrobust.c
@@ -1,22 +1,20 @@
#include "pthread_impl.h"
#include "syscall.h"
-static pthread_once_t check_robust_once;
-static int check_robust_result;
-
-static void check_robust()
-{
- void *p;
- size_t l;
- check_robust_result = -__syscall(SYS_get_robust_list, 0, &p, &l);
-}
+static volatile int check_robust_result = -1;
int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust)
{
if (robust > 1U) return EINVAL;
if (robust) {
- pthread_once(&check_robust_once, check_robust);
- if (check_robust_result) return check_robust_result;
+ int r = check_robust_result;
+ if (r < 0) {
+ void *p;
+ size_t l;
+ r = -__syscall(SYS_get_robust_list, 0, &p, &l);
+ a_store(&check_robust_result, r);
+ }
+ if (r) return r;
a->__attr |= 4;
return 0;
}