1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __PERF_MUTEX_H 3 #define __PERF_MUTEX_H 4 5 #include <pthread.h> 6 #include <stdbool.h> 7 8 /* 9 * A wrapper around the mutex implementation that allows perf to error check 10 * usage, etc. 11 */ 12 struct mutex { 13 pthread_mutex_t lock; 14 }; 15 16 /* A wrapper around the condition variable implementation. */ 17 struct cond { 18 pthread_cond_t cond; 19 }; 20 21 /* Default initialize the mtx struct. */ 22 void mutex_init(struct mutex *mtx); 23 /* 24 * Initialize the mtx struct and set the process-shared rather than default 25 * process-private attribute. 26 */ 27 void mutex_init_pshared(struct mutex *mtx); 28 void mutex_destroy(struct mutex *mtx); 29 30 void mutex_lock(struct mutex *mtx); 31 void mutex_unlock(struct mutex *mtx); 32 /* Tries to acquire the lock and returns true on success. */ 33 bool mutex_trylock(struct mutex *mtx); 34 35 /* Default initialize the cond struct. */ 36 void cond_init(struct cond *cnd); 37 /* 38 * Initialize the cond struct and specify the process-shared rather than default 39 * process-private attribute. 40 */ 41 void cond_init_pshared(struct cond *cnd); 42 void cond_destroy(struct cond *cnd); 43 44 void cond_wait(struct cond *cnd, struct mutex *mtx); 45 void cond_signal(struct cond *cnd); 46 void cond_broadcast(struct cond *cnd); 47 48 #endif /* __PERF_MUTEX_H */ 49