forked from yaosj2k/dnsforwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rwlock.h
executable file
·78 lines (63 loc) · 2.31 KB
/
rwlock.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef RWLOCK_H_INCLUDED
#define RWLOCK_H_INCLUDED
#include "common.h"
#ifdef WIN32
#ifdef WIN64
#ifndef InitializeSRWLock
typedef struct _RWLock {
PVOID Ptr;
} RWLock;
#else
typedef SRWLOCK RWLock;
#endif /* InitializeSRWLock */
#else /* WIN64 */
typedef CRITICAL_SECTION RWLock;
#endif /* WIN64 */
#else /* WIN32 */
#ifdef HAVE_PTHREAD_RWLOCK_INIT
typedef pthread_rwlock_t RWLock;
#else /* HAVE_PTHREAD_RWLOCK_INIT */
typedef pthread_mutex_t RWLock;
#endif /* HAVE_PTHREAD_RWLOCK_INIT */
#endif /* WIN32 */
#ifdef WIN32
#ifdef WIN64
#ifndef InitializeSRWLock
VOID WINAPI InitializeSRWLock(RWLock *SRWLock);
VOID WINAPI AcquireSRWLockShared(RWLock *SRWLock);
VOID WINAPI AcquireSRWLockExclusive(RWLock *SRWLock);
VOID WINAPI ReleaseSRWLockShared(RWLock *SRWLock);
VOID WINAPI ReleaseSRWLockExclusive(RWLock *SRWLock);
#endif /* InitializeSRWLock */
#define RWLock_Init(l) InitializeSRWLock(&(l))
#define RWLock_RdLock(l) AcquireSRWLockShared(&(l))
#define RWLock_WrLock(l) AcquireSRWLockExclusive(&(l))
#define RWLock_UnRLock(l) ReleaseSRWLockShared(&(l))
#define RWLock_UnWLock(l) ReleaseSRWLockExclusive(&(l))
#define RWLock_Destroy(l)
#else /* WIN64 */
#define RWLock_Init(l) CRITICAL_SECTION_INIT((l), 1024)
#define RWLock_RdLock(l) ENTER_CRITICAL_SECTION(l)
#define RWLock_WrLock(l) ENTER_CRITICAL_SECTION(l)
#define RWLock_UnRLock(l) LEAVE_CRITICAL_SECTION(l)
#define RWLock_UnWLock(l) LEAVE_CRITICAL_SECTION(l)
#define RWLock_Destroy(l) DELETE_CRITICAL_SECTION(l)
#endif /* WIN64 */
#else /* WIN32 */
#ifdef HAVE_PTHREAD_RWLOCK_INIT
#define RWLock_Init(l) pthread_rwlock_init(&(l), NULL)
#define RWLock_RdLock(l) pthread_rwlock_rdlock(&(l))
#define RWLock_WrLock(l) pthread_rwlock_wrlock(&(l))
#define RWLock_UnRLock(l) pthread_rwlock_unlock(&(l))
#define RWLock_UnWLock(l) pthread_rwlock_unlock(&(l))
#define RWLock_Destroy(l) pthread_rwlock_destroy(&(l))
#else
#define RWLock_Init(l) (pthread_mutex_init(&(l), NULL))
#define RWLock_RdLock(l) (pthread_mutex_lock(&(l)))
#define RWLock_WrLock(l) (pthread_mutex_lock(&(l)))
#define RWLock_UnRLock(l) (pthread_mutex_unlock(&(l)))
#define RWLock_UnWLock(l) (pthread_mutex_unlock(&(l)))
#define RWLock_Destroy(l) (pthread_mutex_destroy(&(l)))
#endif
#endif /* WIN32 */
#endif // RWLOCK_H_INCLUDED