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.
This commit is contained in:
Rich Felker 2020-09-29 14:02:06 -04:00
parent b115bee4dd
commit 69a1b39019
2 changed files with 18 additions and 21 deletions

View file

@ -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:

View file

@ -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;
}