summaryrefslogtreecommitdiff
path: root/include/linux/percpu-rwsem.h
blob: 153251c076856821bc25b2ab85914b672b1fe938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_PERCPU_RWSEM_H
#define _LINUX_PERCPU_RWSEM_H

#include <pthread.h>
#include <linux/preempt.h>

struct percpu_rw_semaphore {
	pthread_mutex_t		lock;
};

static inline void percpu_down_read_preempt_disable(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_lock(&sem->lock);
}

static inline void percpu_down_read(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_lock(&sem->lock);
}

static inline int percpu_down_read_trylock(struct percpu_rw_semaphore *sem)
{
	return !pthread_mutex_trylock(&sem->lock);
}

static inline void percpu_up_read_preempt_enable(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_unlock(&sem->lock);
}

static inline void percpu_up_read(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_unlock(&sem->lock);
}

static inline void percpu_down_write(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_lock(&sem->lock);
}

static inline void percpu_up_write(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_unlock(&sem->lock);
}

static inline void percpu_free_rwsem(struct percpu_rw_semaphore *sem) {}

static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
{
	pthread_mutex_init(&sem->lock, NULL);
	return 0;
}

#define percpu_rwsem_assert_held(sem)		do {} while (0)

#endif