-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutex.cpp
More file actions
43 lines (34 loc) · 1.06 KB
/
Copy pathmutex.cpp
File metadata and controls
43 lines (34 loc) · 1.06 KB
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
#ifdef CBS_WIN32
void Mutex::create(this Mutex& self) {
::InitializeCriticalSection((CRITICAL_SECTION*)&self.critical_section);
}
void Mutex::destroy(this Mutex& self) {
::DeleteCriticalSection((CRITICAL_SECTION*)&self.critical_section);
}
void Mutex::lock(this Mutex& self) {
::EnterCriticalSection((CRITICAL_SECTION*)&self.critical_section);
}
bool Mutex::try_lock(this Mutex& self) {
return ::TryEnterCriticalSection((CRITICAL_SECTION*)&self.critical_section) != FALSE;
}
void Mutex::unlock(this Mutex& self) {
::LeaveCriticalSection((CRITICAL_SECTION*)&self.critical_section);
}
#endif
#ifdef CBS_LINUX
void Mutex::create(this Mutex& self) {
::pthread_mutex_init(&self.pthread_mutex, nullptr);
}
void Mutex::destroy(this Mutex& self) {
::pthread_mutex_destroy(&self.pthread_mutex);
}
void Mutex::lock(this Mutex& self) {
::pthread_mutex_lock(&self.pthread_mutex);
}
bool Mutex::try_lock(this Mutex& self) {
return ::pthread_mutex_trylock(&self.pthread_mutex) == 0;
}
void Mutex::unlock(this Mutex& self) {
::pthread_mutex_unlock(&self.pthread_mutex);
}
#endif