summaryrefslogtreecommitdiff
path: root/tools/perf/util/mutex.h
blob: cfff32a902d9160f8f356cdd8289abeb2e3eda67 (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
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __PERF_MUTEX_H
#define __PERF_MUTEX_H

#include <pthread.h>
#include <stdbool.h>

/*
 * A wrapper around the mutex implementation that allows perf to error check
 * usage, etc.
 */
struct mutex {
	pthread_mutex_t lock;
};

/* A wrapper around the condition variable implementation. */
struct cond {
	pthread_cond_t cond;
};

/* Default initialize the mtx struct. */
void mutex_init(struct mutex *mtx);
/*
 * Initialize the mtx struct and set the process-shared rather than default
 * process-private attribute.
 */
void mutex_init_pshared(struct mutex *mtx);
void mutex_destroy(struct mutex *mtx);

void mutex_lock(struct mutex *mtx);
void mutex_unlock(struct mutex *mtx);
/* Tries to acquire the lock and returns true on success. */
bool mutex_trylock(struct mutex *mtx);

/* Default initialize the cond struct. */
void cond_init(struct cond *cnd);
/*
 * Initialize the cond struct and specify the process-shared rather than default
 * process-private attribute.
 */
void cond_init_pshared(struct cond *cnd);
void cond_destroy(struct cond *cnd);

void cond_wait(struct cond *cnd, struct mutex *mtx);
void cond_signal(struct cond *cnd);
void cond_broadcast(struct cond *cnd);

#endif /* __PERF_MUTEX_H */