-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathContents.swift
More file actions
45 lines (33 loc) · 829 Bytes
/
Contents.swift
File metadata and controls
45 lines (33 loc) · 829 Bytes
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
import Foundation
final public class ReadWriteLock {
// MARK: - Properties
private var rwLock: pthread_rwlock_t = {
var rwLock = pthread_rwlock_t()
pthread_rwlock_init(&rwLock, nil)
return rwLock
}()
// MARK: - Deinit
deinit {
destroy()
}
// MARK: - Methods
func readLock() {
pthread_rwlock_rdlock(&rwLock)
}
func tryReadLock() {
pthread_rwlock_tryrdlock(&rwLock)
}
func writeLock() {
pthread_rwlock_wrlock(&rwLock)
}
func tryWriteLock() {
pthread_rwlock_trywrlock(&rwLock)
}
// MARK: - Private methods
private func destroy() {
pthread_rwlock_destroy(&rwLock)
}
func unlock() {
pthread_rwlock_unlock(&rwLock)
}
}