forked from bitgapp/eqMac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMutex.swift
More file actions
40 lines (31 loc) · 753 Bytes
/
Copy pathMutex.swift
File metadata and controls
40 lines (31 loc) · 753 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
//
// Mutex.swift
// eqMac
//
// Created by Nodeful on 24/09/2021.
// Copyright © 2021 Romans Kisils. All rights reserved.
//
import Foundation
public class Mutex {
public var mutex = pthread_mutex_t()
public init () {
var attributes = pthread_mutexattr_t()
guard pthread_mutexattr_init(&attributes) == 0 else {
preconditionFailure()
}
pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_NORMAL)
guard pthread_mutex_init(&mutex, &attributes) == 0 else {
preconditionFailure()
}
pthread_mutexattr_destroy(&attributes)
}
public func lock () {
pthread_mutex_lock(&mutex)
}
public func unlock () {
pthread_mutex_unlock(&mutex)
}
deinit {
pthread_mutex_destroy(&mutex)
}
}