summary refs log tree commit diff stats
path: root/lib/core/locks.nim
blob: fbe9c8acfc3586a0da4ec0bdec490e16c6124ec3 (plain) (blame)
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
#
#
#            Nim's Runtime Library
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module contains Nim's support for locks and condition vars.

const insideRLocksModule = false
include "system/syslocks"

type
  Lock* = SysLock ## Nim lock; whether this is re-entrant
                  ## or not is unspecified!
  Cond* = SysCond ## Nim condition variable

{.deprecated: [TLock: Lock, TCond: Cond].}

proc initLock*(lock: var Lock) {.inline.} =
  ## Initializes the given lock.
  initSysLock(lock)

proc deinitLock*(lock: var Lock) {.inline.} =
  ## Frees the resources associated with the lock.
  deinitSys(lock)

proc tryAcquire*(lock: var Lock): bool =
  ## Tries to acquire the given lock. Returns `true` on success.
  result = tryAcquireSys(lock)

proc acquire*(lock: var Lock) =
  ## Acquires the given lock.
  acquireSys(lock)

proc release*(lock: var Lock) =
  ## Releases the given lock.
  releaseSys(lock)


proc initCond*(cond: var Cond) {.inline.} =
  ## Initializes the given condition variable.
  initSysCond(cond)

proc deinitCond*(cond: var Cond) {.inline.} =
  ## Frees the resources associated with the lock.
  deinitSysCond(cond)

proc wait*(cond: var Cond, lock: var Lock) {.inline.} =
  ## waits on the condition variable `cond`.
  waitSysCond(cond, lock)

proc signal*(cond: var Cond) {.inline.} =
  ## sends a signal to the condition variable `cond`.
  signalSysCond(cond)

template withLock*(a: Lock, body: untyped) =
  ## Acquires the given lock, executes the statements in body and
  ## releases the lock after the statements finish executing.
  a.acquire()
  {.locks: [a].}:
    try:
      body
    finally:
      a.release()
m/commit/lib/system/syslocks.nim?h=devel&id=99bcc233cd8fb3bb9b6f3f0857e477dd9b33c9e8'>99bcc233c ^
dc89b2125 ^


43bddf62d ^
dc89b2125 ^




99bcc233c ^
dc89b2125 ^





43bddf62d ^
2ca90a20a ^
dc89b2125 ^
2ca90a20a ^
dc89b2125 ^
2ca90a20a ^
dc89b2125 ^
346443d1b ^
7e351fc7f ^




















dc89b2125 ^

7e351fc7f ^
99bcc233c ^

534d8a6b5 ^
39e797080 ^

4857c462d ^

e512358bc ^
0290bc224 ^
39e797080 ^

4857c462d ^

e512358bc ^
534d8a6b5 ^
39e797080 ^

4857c462d ^

e512358bc ^
2b8a1cee8 ^


4857c462d ^

2b8a1cee8 ^
0290bc224 ^

534d8a6b5 ^
99bcc233c ^
534d8a6b5 ^



















57f98dae9 ^
534d8a6b5 ^




57f98dae9 ^
534d8a6b5 ^


























99bcc233c ^
45bbecb02 ^
dc89b2125 ^
4ef255b69 ^
ebc02f6dc ^



39e797080 ^
534d8a6b5 ^
2b8a1cee8 ^
ebc02f6dc ^
534d8a6b5 ^


dc89b2125 ^
ebc02f6dc ^
534d8a6b5 ^
ebc02f6dc ^
dc89b2125 ^

534d8a6b5 ^

2b8a1cee8 ^
57f98dae9 ^
534d8a6b5 ^






dc89b2125 ^
534d8a6b5 ^

dc89b2125 ^

534d8a6b5 ^
2b8a1cee8 ^
534d8a6b5 ^




dc89b2125 ^
534d8a6b5 ^

dc89b2125 ^

7972448e6 ^

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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234