1570af302Sopenharmony_ci#include "pthread_impl.h"
2570af302Sopenharmony_ci#include "syscall.h"
3570af302Sopenharmony_ci#include <unsupported_api.h>
4570af302Sopenharmony_ci
5570af302Sopenharmony_cistatic volatile int check_pi_result = -1;
6570af302Sopenharmony_ci
7570af302Sopenharmony_ciint pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol)
8570af302Sopenharmony_ci{
9570af302Sopenharmony_ci	int r;
10570af302Sopenharmony_ci
11570af302Sopenharmony_ci	UNSUPPORTED_API_VOID(LITEOS_A);
12570af302Sopenharmony_ci	switch (protocol) {
13570af302Sopenharmony_ci	case PTHREAD_PRIO_NONE:
14570af302Sopenharmony_ci		a->__attr &= ~8;
15570af302Sopenharmony_ci		return 0;
16570af302Sopenharmony_ci	case PTHREAD_PRIO_INHERIT:
17570af302Sopenharmony_ci		r = check_pi_result;
18570af302Sopenharmony_ci		if (r < 0) {
19570af302Sopenharmony_ci			volatile int lk = 0;
20570af302Sopenharmony_ci			r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0);
21570af302Sopenharmony_ci			a_store(&check_pi_result, r);
22570af302Sopenharmony_ci		}
23570af302Sopenharmony_ci		if (r) return r;
24570af302Sopenharmony_ci		a->__attr |= 8;
25570af302Sopenharmony_ci		return 0;
26570af302Sopenharmony_ci	case PTHREAD_PRIO_PROTECT:
27570af302Sopenharmony_ci		return ENOTSUP;
28570af302Sopenharmony_ci	default:
29570af302Sopenharmony_ci		return EINVAL;
30570af302Sopenharmony_ci	}
31570af302Sopenharmony_ci}
32