forked from ReactKit/SwiftTask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_RecursiveLock.swift
More file actions
44 lines (36 loc) · 1.04 KB
/
_RecursiveLock.swift
File metadata and controls
44 lines (36 loc) · 1.04 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
44
//
// _RecursiveLock.swift
// SwiftTask
//
// Created by Yasuhiro Inami on 2015/05/18.
// Copyright (c) 2015年 Yasuhiro Inami. All rights reserved.
//
import Darwin
internal final class _RecursiveLock
{
private let mutex: UnsafeMutablePointer<pthread_mutex_t>
private let attribute: UnsafeMutablePointer<pthread_mutexattr_t>
internal init()
{
self.mutex = UnsafeMutablePointer<pthread_mutex_t>.alloc(1)
self.attribute = UnsafeMutablePointer<pthread_mutexattr_t>.alloc(1)
pthread_mutexattr_init(self.attribute)
pthread_mutexattr_settype(self.attribute, PTHREAD_MUTEX_RECURSIVE)
pthread_mutex_init(self.mutex, self.attribute)
}
deinit
{
pthread_mutexattr_destroy(self.attribute)
pthread_mutex_destroy(self.mutex)
self.attribute.dealloc(1)
self.mutex.dealloc(1)
}
internal func lock()
{
pthread_mutex_lock(self.mutex)
}
internal func unlock()
{
pthread_mutex_unlock(self.mutex)
}
}