blob: d764ba39ed7582672e7c97fd6860a87b8203921a [file] [log] [blame]
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +08001#ifndef _DVR_MUTEX_H_
2#define _DVR_MUTEX_H_
3
4#include <pthread.h>
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +08005
6typedef struct dvr_mutex_s
7{
8 pthread_mutex_t lock;
9 pthread_t thread;
Zhiqiang Han7e771452022-06-15 22:22:39 +080010 int lock_cnt;
Zhiqiang Hanf9c0e272022-06-14 13:54:03 +080011} dvr_mutex_t;
12
13void _dvr_mutex_init(void *mutex);
14void _dvr_mutex_lock(void *mutex);
15void _dvr_mutex_unlock(void *mutex);
16void _dvr_mutex_destroy(void *mutex);
17int _dvr_mutex_save(void *mutex);
18void _dvr_mutex_restore(void *mutex, int val);
19
20#define DVR_MUTEX_DEBUG
21
22#ifndef DVR_MUTEX_DEBUG
23
24#define dvr_mutex_init(a) _dvr_mutex_init(a)
25#define dvr_mutex_lock(a) _dvr_mutex_lock(a)
26#define dvr_mutex_unlock(a) _dvr_mutex_unlock(a)
27#define dvr_mutex_destroy(a) _dvr_mutex_destroy(a)
28#define dvr_mutex_save(a) _dvr_mutex_save(a)
29#define dvr_mutex_restore(a, v) _dvr_mutex_restore(a, v)
30
31#else/*DEBUG*/
32
33void _dvr_mutex_init_dbg(void *mutex, const char *file, int line);
34void _dvr_mutex_lock_dbg(void *mutex, const char *file, int line);
35void _dvr_mutex_unlock_dbg(void *mutex, const char *file, int line);
36void _dvr_mutex_destroy_dbg(void *mutex, const char *file, int line);
37int _dvr_mutex_save_dbg(void *mutex, const char *file, int line);
38void _dvr_mutex_restore_dbg(void *mutex, int val, const char *file, int line);
39#define dvr_mutex_init(a) _dvr_mutex_init_dbg(a, __FUNCTION__, __LINE__)
40#define dvr_mutex_lock(a) _dvr_mutex_lock_dbg(a, __FUNCTION__, __LINE__)
41#define dvr_mutex_unlock(a) _dvr_mutex_unlock_dbg(a, __FUNCTION__, __LINE__)
42#define dvr_mutex_destroy(a) _dvr_mutex_destroy_dbg(a, __FUNCTION__, __LINE__)
43#define dvr_mutex_save(a) _dvr_mutex_save_dbg(a, __FUNCTION__, __LINE__)
44#define dvr_mutex_restore(a, v) _dvr_mutex_restore_dbg(a, v, __FUNCTION__, __LINE__)
45
46#endif/*DEBUG*/
47
48#endif/*_DVR_MUTEX_H_*/