blob: af342abf338cbefebb6b8cfb94c168920c80789d (
plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
//+build darwin
//+private
package sync2
import "core:time"
import "core:c"
import "core:intrinsics"
foreign import pthread "System.framework"
_current_thread_id :: proc "contextless" () -> int {
tid: u64;
// NOTE(Oskar): available from OSX 10.6 and iOS 3.2.
// For older versions there is `syscall(SYS_thread_selfid)`, but not really
// the same thing apparently.
foreign pthread { pthread_threadid_np :: proc "c" (rawptr, ^u64) -> c.int ---; }
pthread_threadid_np(nil, &tid);
return int(tid);
}
foreign {
@(link_name="usleep")
_darwin_usleep :: proc "c" (us: uint) -> i32 ---
@(link_name="sched_yield")
_darwin_sched_yield :: proc "c" () -> i32 ---
}
_atomic_try_wait_slow :: proc(ptr: ^u32, val: u32) {
history: uint = 10;
for {
// Exponential wait
_darwin_usleep(history >> 2);
history += history >> 2;
if history > (1 << 10) {
history = 1 << 10;
}
if atomic_load(ptr) != val {
break;
}
}
}
_atomic_wait :: proc(ptr: ^u32, val: u32) {
if intrinsics.expect(atomic_load(ptr) != val, true) {
return;
}
for i in 0..<16 {
if atomic_load(ptr) != val {
return;
}
if i < 12 {
intrinsics.cpu_relax();
} else {
_darwin_sched_yield();
}
}
for val == atomic_load(ptr) {
_atomic_try_wait_slow(ptr, val);
}
}
_Mutex :: struct {
}
_mutex_lock :: proc(m: ^Mutex) {
}
_mutex_unlock :: proc(m: ^Mutex) {
}
_mutex_try_lock :: proc(m: ^Mutex) -> bool {
return false;
}
_RW_Mutex :: struct {
}
_rw_mutex_lock :: proc(rw: ^RW_Mutex) {
}
_rw_mutex_unlock :: proc(rw: ^RW_Mutex) {
}
_rw_mutex_try_lock :: proc(rw: ^RW_Mutex) -> bool {
return false;
}
_rw_mutex_shared_lock :: proc(rw: ^RW_Mutex) {
}
_rw_mutex_shared_unlock :: proc(rw: ^RW_Mutex) {
}
_rw_mutex_try_shared_lock :: proc(rw: ^RW_Mutex) -> bool {
return false;
}
_Recursive_Mutex :: struct {
}
_recursive_mutex_lock :: proc(m: ^Recursive_Mutex) {
}
_recursive_mutex_unlock :: proc(m: ^Recursive_Mutex) {
}
_recursive_mutex_try_lock :: proc(m: ^Recursive_Mutex) -> bool {
return false;
}
_Cond :: struct {
}
_cond_wait :: proc(c: ^Cond, m: ^Mutex) {
}
_cond_wait_with_timeout :: proc(c: ^Cond, m: ^Mutex, timeout: time.Duration) -> bool {
return false;
}
_cond_signal :: proc(c: ^Cond) {
}
_cond_broadcast :: proc(c: ^Cond) {
}
_Sema :: struct {
}
_sema_wait :: proc(s: ^Sema) {
}
_sema_post :: proc(s: ^Sema, count := 1) {
}
|