author | Claus Gittinger <cg@exept.de> |
Tue, 31 Jul 2001 17:10:05 +0200 | |
changeset 5897 | 793b0adad934 |
parent 5713 | 993805688c7f |
child 6061 | 9e266783d5c2 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5556 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
375 | 15 |
Object subclass:#Semaphore |
2262 | 16 |
instanceVariableNames:'count waitingProcesses lastOwnerID name' |
757 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Kernel-Processes' |
|
699 | 20 |
! |
1 | 21 |
|
1812
a048a98aa299
kludge around a situation, where one process
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
22 |
!Semaphore class methodsFor:'documentation'! |
69 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
69 | 38 |
documentation |
39 |
" |
|
40 |
Semaphores are used to synchronize processes providing a nonBusy wait |
|
41 |
mechanism. A process can wait for the availability of some resource by |
|
93 | 42 |
performing a Semaphore>>wait, which will suspend the process until the |
43 |
resource becomes available. Signalling is done by (another process performing) |
|
44 |
Semaphore>>signal. |
|
159 | 45 |
If the resource has been already available before the wait, no suspending is |
69 | 46 |
done, but the resource immediately allocated. |
2234 | 47 |
|
93 | 48 |
There are also semaphores for mutual access to a critical region |
49 |
(Semaphore>>forMutualExclusion and Semaphore>>critical:). |
|
88 | 50 |
|
2234 | 51 |
Additional protocol is provided for oneShot semaphores, |
52 |
(#signalOnce) and for conditional signalling (#signalIf). |
|
53 |
||
159 | 54 |
You can also attach semaphores to external events (such as I/O arrival or |
2142 | 55 |
timer events). |
56 |
This is done by telling the Processor to signal the semaphore |
|
183 | 57 |
under some condition. |
159 | 58 |
See 'Processor>>signal:afterSeconds:', 'Processor>>signal:onInput:' etc. |
59 |
||
2142 | 60 |
See examples in doc/coding (found in the CodingExamples-nameSpace). |
1273 | 61 |
|
4437 | 62 |
Warning/Note/Hint: |
63 |
a Semaphore-forMutualExclusion does NEVER allow for the critical |
|
64 |
region to be entered twice - NOT EVEN by the same process. |
|
65 |
That means, that a recursive attempt to enter that section leads |
|
66 |
to a deadlock. |
|
67 |
Use a RecursionLock instead of a semaphore to avoid this. |
|
68 |
||
2262 | 69 |
|
4437 | 70 |
[instance variables:] |
71 |
count <SmallInteger> the number of waits, that will go through |
|
72 |
without blocking. |
|
73 |
Incremented on #signal; decremented on #wait. |
|
2262 | 74 |
|
4437 | 75 |
waitingProcesses <OrderedCollection> waiting processes - will be served first |
76 |
come first served when signalled. |
|
2262 | 77 |
|
4437 | 78 |
lastOwnerID <SmallInteger> a debugging aid: set when count drops |
79 |
to zero to the current processes id. |
|
80 |
Helps in finding deadlocks. |
|
81 |
||
82 |
name <String> a debugging aid: an optional userFriendly |
|
83 |
name; helps to identify a semaphore easier. |
|
2262 | 84 |
|
1273 | 85 |
[see also:] |
4437 | 86 |
SemaphoreSet RecursionLock Monitor |
87 |
SharedQueue Delay |
|
88 |
Process ProcessorScheduler |
|
1294 | 89 |
|
90 |
[author:] |
|
4437 | 91 |
Claus Gittinger |
3392 | 92 |
" |
93 |
! |
|
94 |
||
95 |
examples |
|
96 |
" |
|
97 |
two processes synchronizing on a sema: |
|
4437 | 98 |
[exBegin] |
99 |
|sema thread1 thread2| |
|
3392 | 100 |
|
4437 | 101 |
sema := Semaphore new. |
3392 | 102 |
|
4437 | 103 |
thread1 := [ |
104 |
Transcript showCR:'here is thread 1; now waiting ...'. |
|
105 |
sema wait. |
|
106 |
Transcript showCR:'here is thread 1 again.'. |
|
107 |
] newProcess. |
|
3392 | 108 |
|
4437 | 109 |
thread2 := [ |
110 |
Transcript showCR:'here is thread 2; delaying a bit ...'. |
|
111 |
Delay waitForSeconds:5. |
|
112 |
Transcript showCR:'here is thread 2 again; now signalling the sema'. |
|
113 |
sema signal. |
|
114 |
Transcript showCR:'here is thread 2 after the signalling.'. |
|
115 |
] newProcess. |
|
3392 | 116 |
|
4437 | 117 |
thread1 priority:7. |
118 |
thread2 priority:6. |
|
3392 | 119 |
|
4437 | 120 |
thread1 resume. |
121 |
thread2 resume. |
|
122 |
[exEnd] |
|
3392 | 123 |
|
124 |
semaphore for critical regions: |
|
4437 | 125 |
[exBegin] |
126 |
|accessLock| |
|
127 |
||
128 |
accessLock := Semaphore forMutualExclusion. |
|
129 |
||
130 |
[ |
|
131 |
5 timesRepeat:[ |
|
132 |
Delay waitForSeconds:2. |
|
133 |
accessLock critical:[ |
|
134 |
Transcript showCR:'thread1 in critical region'. |
|
135 |
Delay waitForSeconds:1. |
|
136 |
Transcript showCR:'thread1 leaving critical region'. |
|
137 |
]. |
|
138 |
] |
|
139 |
] forkAt:5. |
|
3392 | 140 |
|
4437 | 141 |
[ |
142 |
5 timesRepeat:[ |
|
143 |
Delay waitForSeconds:1. |
|
144 |
accessLock critical:[ |
|
145 |
Transcript showCR:'thread2 in critical region'. |
|
146 |
Delay waitForSeconds:2. |
|
147 |
Transcript showCR:'thread2 leaving critical region'. |
|
148 |
]. |
|
149 |
] |
|
150 |
] forkAt:4. |
|
151 |
[exEnd] |
|
152 |
||
153 |
a deadlock due to recursive enter of a critical region: |
|
154 |
[exBegin] |
|
155 |
|accessLock block| |
|
3392 | 156 |
|
4437 | 157 |
accessLock := Semaphore forMutualExclusion. |
158 |
||
159 |
block := [:arg | |
|
160 |
Transcript showCR:'about to enter'. |
|
161 |
accessLock critical:[ |
|
162 |
Transcript showCR:'entered - doing action'. |
|
163 |
arg value |
|
164 |
]. |
|
165 |
Transcript showCR:'left region'. |
|
166 |
]. |
|
167 |
||
168 |
block value:[]. 'this works'. |
|
169 |
block value:[block value:[] ]. 'this deadlocks'. |
|
170 |
[exEnd] |
|
3392 | 171 |
|
4437 | 172 |
Avoid the deadlock by using a RecursionLock instead: |
173 |
[exBegin] |
|
174 |
|accessLock block| |
|
175 |
||
176 |
accessLock := RecursionLock new. |
|
177 |
||
178 |
block := [:arg | |
|
179 |
Transcript showCR:'about to enter'. |
|
180 |
accessLock critical:[ |
|
181 |
Transcript showCR:'entered - doing action'. |
|
182 |
arg value |
|
183 |
]. |
|
184 |
Transcript showCR:'left region'. |
|
185 |
]. |
|
186 |
||
187 |
block value:[]. 'this works'. |
|
188 |
block value:[block value:[] ]. 'this deadlocks'. |
|
189 |
[exEnd] |
|
69 | 190 |
" |
191 |
! ! |
|
192 |
||
1812
a048a98aa299
kludge around a situation, where one process
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
193 |
!Semaphore class methodsFor:'instance creation'! |
1 | 194 |
|
699 | 195 |
forMutualExclusion |
196 |
"create & return a new semaphore which allows exactly one process to |
|
2142 | 197 |
wait on it without blocking. This type of semaphore is used |
4437 | 198 |
for mutual exclusion from critical regions (see #critical:). |
199 |
Also see RecursionLock, to avoid deadlock in case of recursive entered |
|
200 |
critical regions." |
|
699 | 201 |
|
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
202 |
^ super new setCount:1; name:'criticalRegionSema' |
2142 | 203 |
|
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
204 |
"Modified: / 17.6.1998 / 16:23:09 / cg" |
699 | 205 |
! |
206 |
||
1 | 207 |
new |
208 |
"create & return a new semaphore which blocks until a signal is sent" |
|
209 |
||
210 |
^ super new setCount:0 |
|
211 |
! |
|
212 |
||
213 |
new:n |
|
214 |
"create & return a new semaphore which allows n waits before |
|
215 |
blocking" |
|
216 |
||
217 |
^ super new setCount:n |
|
699 | 218 |
! ! |
1 | 219 |
|
757 | 220 |
!Semaphore methodsFor:'friend-class interface'! |
221 |
||
222 |
checkAndRegisterProcess:process |
|
2142 | 223 |
"interface for SemaphoreSet. |
757 | 224 |
If the semaphore is available, decrement it and return true. |
2262 | 225 |
Otherwise register our process to be wakened up once the semaphore is available |
226 |
and return false.. |
|
757 | 227 |
" |
228 |
||
229 |
" |
|
2262 | 230 |
bad ST/X trick (needs change, when multiProcessor support is added): |
757 | 231 |
this works only since interrupts are only serviced at |
232 |
message send and method-return time .... |
|
233 |
If you add a message send into the ifTrue:-block, things will |
|
234 |
go mad ... (especially be careful when adding a debugPrint-here) |
|
235 |
" |
|
236 |
count ~~ 0 ifTrue:[ |
|
3392 | 237 |
count := count - 1. |
2262 | 238 |
count == 0 ifTrue:[ |
239 |
lastOwnerID := Processor activeProcessId. |
|
240 |
]. |
|
3392 | 241 |
^ true |
757 | 242 |
]. |
1122 | 243 |
(waitingProcesses identityIndexOf:process) == 0 ifTrue:[ |
3392 | 244 |
waitingProcesses add:process. |
757 | 245 |
]. |
246 |
^ false |
|
247 |
||
248 |
"Modified: 14.12.1995 / 10:32:17 / stefan" |
|
2142 | 249 |
"Modified: 10.1.1997 / 21:42:18 / cg" |
757 | 250 |
! |
251 |
||
252 |
unregisterProcess:process |
|
2142 | 253 |
"interface for SemaphoreSet. |
254 |
Unregister our process from the Semaphore" |
|
757 | 255 |
|
2352 | 256 |
waitingProcesses removeIdentical:process ifAbsent:[]. |
757 | 257 |
|
258 |
"Created: 14.12.1995 / 10:31:50 / stefan" |
|
2352 | 259 |
"Modified: 1.2.1997 / 12:11:22 / cg" |
757 | 260 |
! ! |
261 |
||
699 | 262 |
!Semaphore methodsFor:'printing & storing'! |
1 | 263 |
|
699 | 264 |
displayString |
2142 | 265 |
"return a string to display the receiver - include the |
266 |
count for your convenience" |
|
267 |
||
2723 | 268 |
^ self class name , '(' , count printString , ' name: ' , (name ? 'unnamed') , ')' |
2262 | 269 |
|
2723 | 270 |
"Modified: 28.6.1997 / 16:21:09 / cg" |
2265 | 271 |
! |
272 |
||
273 |
name |
|
274 |
"return the semaphores userFriendly name" |
|
275 |
||
276 |
^ name |
|
277 |
! |
|
278 |
||
279 |
name:aString |
|
280 |
"set the semaphores userFriendly name" |
|
281 |
||
282 |
name := aString |
|
1 | 283 |
! ! |
284 |
||
285 |
!Semaphore methodsFor:'private accessing'! |
|
286 |
||
2407
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
287 |
initSignals |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
288 |
"set the count of the semaphore to zero. |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
289 |
provided for ST-80 compatibility." |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
290 |
|
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
291 |
count := 0 |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
292 |
|
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
293 |
"Created: 17.2.1997 / 11:31:19 / cg" |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
294 |
! |
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
295 |
|
1 | 296 |
setCount:n |
2142 | 297 |
"set the count of the semaphore; |
298 |
thats the number of possible waits, without blocking" |
|
299 |
||
2407
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
300 |
waitingProcesses := OrderedCollection new:2. |
1 | 301 |
count := n |
2142 | 302 |
|
2407
6b0e21391915
added #initSignals for ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2352
diff
changeset
|
303 |
"Modified: 17.2.1997 / 11:36:40 / cg" |
1 | 304 |
! ! |
305 |
||
5256 | 306 |
!Semaphore methodsFor:'queries'! |
217 | 307 |
|
2235 | 308 |
count |
309 |
"return the number of 'already-counted' trigger events. |
|
310 |
Thats the number of waits which will succeed without blocking" |
|
311 |
||
312 |
^ count |
|
313 |
||
314 |
"Created: 23.1.1997 / 02:55:58 / cg" |
|
315 |
! |
|
316 |
||
2265 | 317 |
lastOwnerId |
318 |
"return the processId of the last owning process |
|
319 |
(the one which counted to zero). |
|
320 |
May be very useful in debugging deadLock situations" |
|
321 |
||
322 |
^ lastOwnerID |
|
323 |
||
324 |
"Created: 24.1.1997 / 23:09:33 / cg" |
|
325 |
! |
|
326 |
||
1329 | 327 |
numberOfWaitingProcesses |
328 |
"return the number of processes waiting on the receiver" |
|
329 |
||
330 |
^ waitingProcesses size |
|
331 |
||
332 |
"Created: 3.5.1996 / 18:06:27 / cg" |
|
333 |
! |
|
334 |
||
1577
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
335 |
waitingProcesses |
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
336 |
"return the processes waiting on the receiver" |
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
337 |
|
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
338 |
^ waitingProcesses |
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
339 |
|
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
340 |
"Created: 18.7.1996 / 20:53:33 / cg" |
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
341 |
! |
720f14f90e2c
access to waitingProcesses added
Claus Gittinger <cg@exept.de>
parents:
1329
diff
changeset
|
342 |
|
217 | 343 |
wouldBlock |
344 |
"return true, if the receiver would block the activeProcess |
|
345 |
if a wait was performed. False otherwise." |
|
346 |
||
347 |
^ count == 0 |
|
348 |
! ! |
|
349 |
||
5556 | 350 |
!Semaphore methodsFor:'testing'! |
351 |
||
352 |
isEmpty |
|
353 |
"ST80 compatibility - return true if there are no waiters" |
|
354 |
||
355 |
^ waitingProcesses isEmpty |
|
356 |
||
357 |
"Created: / 3.5.1996 / 18:06:27 / cg" |
|
358 |
"Modified: / 18.6.1998 / 16:07:38 / cg" |
|
359 |
! ! |
|
360 |
||
699 | 361 |
!Semaphore methodsFor:'wait & signal'! |
362 |
||
5713 | 363 |
clear |
364 |
"clear the semaphores count" |
|
365 |
||
366 |
count := 0 |
|
367 |
! |
|
368 |
||
699 | 369 |
critical:aBlock |
370 |
"evaluate aBlock as a critical region; the receiver must be |
|
371 |
created using Semaphore>>forMutualExclusion" |
|
372 |
||
1185
2b24258b4f24
Fix in critical: don't signal a semaphore that we didn't get when unwinding.
Stefan Vogel <sv@exept.de>
parents:
1122
diff
changeset
|
373 |
|retVal gotSema| |
926
101239898989
unwind block over wait (in critical)
Claus Gittinger <cg@exept.de>
parents:
770
diff
changeset
|
374 |
|
101239898989
unwind block over wait (in critical)
Claus Gittinger <cg@exept.de>
parents:
770
diff
changeset
|
375 |
[ |
3669 | 376 |
gotSema := self wait. |
377 |
retVal := aBlock value. |
|
1185
2b24258b4f24
Fix in critical: don't signal a semaphore that we didn't get when unwinding.
Stefan Vogel <sv@exept.de>
parents:
1122
diff
changeset
|
378 |
] valueOnUnwindDo:[ |
3669 | 379 |
"/ be careful - the unwind may occur both while waiting |
380 |
"/ AND while evaluating the block. |
|
381 |
gotSema notNil ifTrue:[self signal]. |
|
1185
2b24258b4f24
Fix in critical: don't signal a semaphore that we didn't get when unwinding.
Stefan Vogel <sv@exept.de>
parents:
1122
diff
changeset
|
382 |
]. |
2b24258b4f24
Fix in critical: don't signal a semaphore that we didn't get when unwinding.
Stefan Vogel <sv@exept.de>
parents:
1122
diff
changeset
|
383 |
self signal. |
926
101239898989
unwind block over wait (in critical)
Claus Gittinger <cg@exept.de>
parents:
770
diff
changeset
|
384 |
^ retVal |
699 | 385 |
|
386 |
" |
|
387 |
the example below is stupid (it should use a SharedQueue, |
|
388 |
or at least a Queue with critical regions). |
|
389 |
Anyhow, it demonstrates how two processes lock each other |
|
390 |
from accessing coll at the same time |
|
391 |
||
392 |
|sema coll| |
|
393 |
||
394 |
sema := Semaphore forMutualExclusion. |
|
395 |
coll := OrderedCollection new:10. |
|
396 |
||
397 |
[ |
|
3669 | 398 |
1 to:1000 do:[:i | |
399 |
sema critical:[ |
|
400 |
coll addLast:i. |
|
401 |
(Delay forSeconds:0.1) wait. |
|
402 |
] |
|
403 |
] |
|
699 | 404 |
] forkAt:4. |
405 |
||
406 |
[ |
|
3669 | 407 |
1 to:1000 do:[:i | |
408 |
sema critical:[ |
|
409 |
coll removeFirst. |
|
410 |
(Delay forSeconds:0.1) wait. |
|
411 |
] |
|
412 |
] |
|
699 | 413 |
] forkAt:4. |
414 |
" |
|
1185
2b24258b4f24
Fix in critical: don't signal a semaphore that we didn't get when unwinding.
Stefan Vogel <sv@exept.de>
parents:
1122
diff
changeset
|
415 |
|
3669 | 416 |
"Modified: / 16.4.1996 / 10:00:46 / stefan" |
417 |
"Modified: / 21.7.1998 / 17:45:26 / cg" |
|
699 | 418 |
! |
419 |
||
420 |
signal |
|
4633 | 421 |
"waking up (the first) waiter. |
422 |
Q: should this be the highest prio waiter ?" |
|
699 | 423 |
|
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
424 |
|wasBlocked| |
362 | 425 |
|
699 | 426 |
wasBlocked := OperatingSystem blockInterrupts. |
1031 | 427 |
[ |
3836
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
428 |
|p| |
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
429 |
|
3836
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
430 |
count := count + 1. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
431 |
p := waitingProcesses removeFirstIfAbsent:nil. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
432 |
p notNil ifTrue:[ |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
433 |
Processor resume:p. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
434 |
]. |
1031 | 435 |
] valueNowOrOnUnwindDo:[ |
3836
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
436 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
1031 | 437 |
] |
438 |
||
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
439 |
"Modified: / 4.2.1998 / 21:01:07 / cg" |
699 | 440 |
! |
441 |
||
442 |
signalForAll |
|
443 |
"signal the semaphore for all waiters. |
|
444 |
This can be used for process synchronization, if multiple processes are |
|
445 |
waiting for a common event." |
|
446 |
||
447 |
|wasBlocked| |
|
448 |
||
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
449 |
waitingProcesses notEmpty ifTrue:[ |
3392 | 450 |
wasBlocked := OperatingSystem blockInterrupts. |
451 |
[ |
|
452 |
|p| |
|
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
453 |
|
3392 | 454 |
"/ first, make them all runnable, but do not schedule |
455 |
"/ (in case one has higher prio and goes into a wait |
|
456 |
"/ immediately again.) |
|
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
457 |
|
3392 | 458 |
[waitingProcesses notEmpty] whileTrue:[ |
459 |
p := waitingProcesses removeFirst. |
|
460 |
count := count + 1. |
|
461 |
Processor makeRunnable:p. |
|
462 |
]. |
|
463 |
] valueNowOrOnUnwindDo:[ |
|
464 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
465 |
]. |
|
466 |
"/ |
|
467 |
"/ now, reschedule |
|
468 |
"/ |
|
469 |
Processor reschedule |
|
699 | 470 |
] |
1031 | 471 |
|
3272
3e35f761be17
when signalling multiple process, make ALL of them FIRST runnable
Claus Gittinger <cg@exept.de>
parents:
2723
diff
changeset
|
472 |
"Modified: / 5.2.1998 / 10:40:26 / cg" |
699 | 473 |
! |
362 | 474 |
|
699 | 475 |
signalIf |
476 |
"signal the semaphore, but only if being waited upon. |
|
477 |
This can be used for one-shot semaphores (i.e. not remembering |
|
478 |
previous signals)" |
|
479 |
||
480 |
|wasBlocked| |
|
481 |
||
482 |
waitingProcesses notEmpty ifTrue:[ |
|
3392 | 483 |
wasBlocked := OperatingSystem blockInterrupts. |
484 |
[ |
|
485 |
waitingProcesses notEmpty ifTrue:[ |
|
486 |
self signal |
|
487 |
]. |
|
488 |
] valueNowOrOnUnwindDo:[ |
|
489 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
490 |
] |
|
699 | 491 |
] |
1031 | 492 |
|
493 |
"Modified: 28.2.1996 / 21:23:57 / cg" |
|
699 | 494 |
! |
495 |
||
496 |
signalOnce |
|
497 |
"wakeup waiters - but only once. |
|
498 |
I.e. if the semaphore has already been signalled, this |
|
499 |
is ignored." |
|
500 |
||
501 |
|wasBlocked| |
|
502 |
||
503 |
count == 0 ifTrue:[ |
|
3836
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
504 |
wasBlocked := OperatingSystem blockInterrupts. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
505 |
[ |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
506 |
|p| |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
507 |
|
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
508 |
count == 0 ifTrue:[ |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
509 |
count := 1. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
510 |
p := waitingProcesses removeFirstIfAbsent:nil. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
511 |
p notNil ifTrue:[ |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
512 |
Processor resume:p. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
513 |
]. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
514 |
]. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
515 |
] valueNowOrOnUnwindDo:[ |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
516 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
318f7d6f242b
avoid two more sends in signal / signalOnce
Claus Gittinger <cg@exept.de>
parents:
3669
diff
changeset
|
517 |
] |
699 | 518 |
] |
1031 | 519 |
|
520 |
"Modified: 28.2.1996 / 21:24:08 / cg" |
|
699 | 521 |
! |
1 | 522 |
|
523 |
wait |
|
524 |
"wait for the semaphore" |
|
525 |
||
2142 | 526 |
|activeProcess wasBlocked| |
1 | 527 |
|
528 |
" |
|
2262 | 529 |
bad ST/X trick (needs change, when multiProcessor support is added): |
159 | 530 |
this works only since interrupts are only serviced at |
531 |
message send and method-return time .... |
|
2262 | 532 |
If you add a message send between the compare and the decrement, |
533 |
things will go mad ... (especially be careful when adding a debugPrint-here) |
|
93 | 534 |
" |
535 |
count ~~ 0 ifTrue:[ |
|
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
536 |
count := count - 1. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
537 |
count == 0 ifTrue:[ |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
538 |
lastOwnerID := Processor activeProcessId. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
539 |
]. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
540 |
^ self |
93 | 541 |
]. |
542 |
||
2142 | 543 |
activeProcess := Processor activeProcess. |
159 | 544 |
|
302 | 545 |
wasBlocked := OperatingSystem blockInterrupts. |
159 | 546 |
" |
547 |
need a while-loop here, since more than one process may |
|
548 |
wait for it and another one may also wake up. |
|
549 |
Thus, the count is not always non-zero after returning from |
|
550 |
suspend. |
|
551 |
" |
|
1 | 552 |
[count == 0] whileTrue:[ |
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
553 |
waitingProcesses add:activeProcess. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
554 |
" |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
555 |
for some more descriptive info in processMonitor ... |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
556 |
... set the state to #wait (instead of #suspend) |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
557 |
" |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
558 |
[ |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
559 |
activeProcess suspendWithState:#wait |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
560 |
] valueOnUnwindDo:[ |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
561 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
562 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
563 |
]. |
1812
a048a98aa299
kludge around a situation, where one process
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
564 |
|
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
565 |
count == 0 ifTrue:[ |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
566 |
"/ care for someone manually resuming me ... |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
567 |
"/ being multiple times on waitingProcesses |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
568 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
569 |
] |
1 | 570 |
]. |
10 | 571 |
count := count - 1. |
2262 | 572 |
count == 0 ifTrue:[ |
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
573 |
lastOwnerID := Processor activeProcessId. |
2262 | 574 |
]. |
93 | 575 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
576 |
|
3600
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
577 |
"Modified: / 13.12.1995 / 13:26:33 / stefan" |
6c5629eea51d
give mutual-exclusion semas a distinct default name
Claus Gittinger <cg@exept.de>
parents:
3392
diff
changeset
|
578 |
"Modified: / 17.6.1998 / 15:26:27 / cg" |
10 | 579 |
! |
580 |
||
329 | 581 |
waitUncounted |
582 |
"wait for the semaphore; do not consume the resource |
|
583 |
(i.e. do not count down)" |
|
584 |
||
2142 | 585 |
|activeProcess wasBlocked| |
329 | 586 |
|
587 |
" |
|
2262 | 588 |
bad ST/X trick (needs change, when multiProcessor support is added): |
329 | 589 |
this works only since interrupts are only serviced at |
590 |
message send and method-return time .... |
|
2262 | 591 |
If you add a message send between the compare and the decrement, |
592 |
things will go mad ... (especially be careful when adding a debugPrint-here) |
|
329 | 593 |
" |
594 |
count ~~ 0 ifTrue:[ |
|
3392 | 595 |
^ self |
329 | 596 |
]. |
597 |
||
2142 | 598 |
activeProcess := Processor activeProcess. |
329 | 599 |
|
600 |
wasBlocked := OperatingSystem blockInterrupts. |
|
601 |
" |
|
602 |
need a while-loop here, since more than one process may |
|
603 |
wait for it and another one may also wake up. |
|
604 |
Thus, the count is not always non-zero after returning from |
|
605 |
suspend. |
|
606 |
" |
|
607 |
[count == 0] whileTrue:[ |
|
3392 | 608 |
waitingProcesses add:activeProcess. |
609 |
" |
|
610 |
for some more descriptive info in processMonitor ... |
|
611 |
... set the state to #wait (instead of #suspend) |
|
612 |
" |
|
613 |
[ |
|
614 |
activeProcess suspendWithState:#wait |
|
615 |
] valueOnUnwindDo:[ |
|
616 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
|
617 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
618 |
]. |
|
619 |
count == 0 ifTrue:[ |
|
620 |
"/ care for someone manually resuming me ... |
|
621 |
"/ being multiple times on waitingProcesses |
|
622 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
|
623 |
] |
|
329 | 624 |
]. |
625 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
626 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
627 |
"Modified: 13.12.1995 / 13:26:49 / stefan" |
2352 | 628 |
"Modified: 1.2.1997 / 12:11:41 / cg" |
329 | 629 |
! |
630 |
||
159 | 631 |
waitWithTimeout:seconds |
632 |
"wait for the semaphore, but abort the wait after some time. |
|
2690 | 633 |
return the receiver if the semaphore triggered normal, nil if we return |
926
101239898989
unwind block over wait (in critical)
Claus Gittinger <cg@exept.de>
parents:
770
diff
changeset
|
634 |
due to a timeout. |
101239898989
unwind block over wait (in critical)
Claus Gittinger <cg@exept.de>
parents:
770
diff
changeset
|
635 |
The seconds-argument may be a float (i.e. use 0.1 for a 100ms timeout). |
2690 | 636 |
With zero timeout, this can be used to poll a semaphore (returning |
637 |
the receiver if the semaphore is available, nil if not). |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
638 |
However, polling is not the intended use of semaphores, though. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
639 |
If seconds is nil, wait without timeout." |
159 | 640 |
|
2142 | 641 |
|activeProcess timeoutOccured wasBlocked unblock now endTime| |
159 | 642 |
|
643 |
" |
|
2262 | 644 |
bad ST/X trick (needs change, when multiProcessor support is added): |
159 | 645 |
this works only since interrupts are only serviced at |
646 |
message send and method-return time .... |
|
2262 | 647 |
If you add a message send between the compare and the decrement, |
648 |
things will go mad ... (especially be careful when adding a debugPrint-here) |
|
159 | 649 |
" |
650 |
count ~~ 0 ifTrue:[ |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
651 |
count := count - 1. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
652 |
count == 0 ifTrue:[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
653 |
lastOwnerID := Processor activeProcessId. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
654 |
]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
655 |
^ self |
159 | 656 |
]. |
657 |
||
658 |
" |
|
659 |
with zero-timeout, this is a poll |
|
660 |
" |
|
661 |
seconds = 0 ifTrue:[ |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
662 |
^ nil |
159 | 663 |
]. |
664 |
||
2142 | 665 |
activeProcess := Processor activeProcess. |
302 | 666 |
|
159 | 667 |
wasBlocked := OperatingSystem blockInterrupts. |
668 |
||
669 |
" |
|
670 |
calculate the end-time |
|
671 |
" |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
672 |
seconds notNil ifTrue:[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
673 |
now := OperatingSystem getMillisecondTime. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
674 |
endTime := OperatingSystem millisecondTimeAdd:now and:(seconds * 1000). |
159 | 675 |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
676 |
unblock := [timeoutOccured := true. Processor resume:activeProcess]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
677 |
Processor addTimedBlock:unblock for:activeProcess atMilliseconds:endTime. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
678 |
]. |
159 | 679 |
|
680 |
" |
|
681 |
need a while-loop here, since more than one process may |
|
682 |
wait for it and another one may also wake up. |
|
683 |
Thus, the count is not always non-zero after returning from |
|
684 |
suspend. |
|
685 |
" |
|
686 |
[count == 0] whileTrue:[ |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
687 |
waitingProcesses add:activeProcess. |
302 | 688 |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
689 |
timeoutOccured := false. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
690 |
" |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
691 |
for some more descriptive info in processMonitor ... |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
692 |
... set the state to #wait (instead of #suspend) |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
693 |
" |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
694 |
[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
695 |
activeProcess suspendWithState:#wait. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
696 |
] valueOnUnwindDo:[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
697 |
unblock := nil. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
698 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
699 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
700 |
]. |
159 | 701 |
|
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
702 |
waitingProcesses removeIdentical:activeProcess ifAbsent:[]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
703 |
timeoutOccured ifTrue:[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
704 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
705 |
unblock := nil. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
706 |
^ nil |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
707 |
]. |
159 | 708 |
]. |
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
709 |
|
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
710 |
unblock notNil ifTrue:[ |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
711 |
Processor removeTimedBlock:unblock. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
712 |
unblock := nil. |
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
713 |
]. |
2690 | 714 |
|
159 | 715 |
count := count - 1. |
2262 | 716 |
count == 0 ifTrue:[ |
4902
caf73c9821c5
Allow nil as argument to #waitWithTimeout: (no timeout) (stefan)
Claus Gittinger <cg@exept.de>
parents:
4633
diff
changeset
|
717 |
lastOwnerID := Processor activeProcessId. |
2262 | 718 |
]. |
159 | 719 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
770
402958905760
protocol of waitWithTImeOut: changed
Claus Gittinger <cg@exept.de>
parents:
769
diff
changeset
|
720 |
^ self |
752
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
721 |
|
0259dd855289
new suspendAction, Semaphore & ProcSched stuff from stefan
Claus Gittinger <cg@exept.de>
parents:
699
diff
changeset
|
722 |
"Modified: 13.12.1995 / 13:27:24 / stefan" |
2690 | 723 |
"Modified: 16.6.1997 / 21:54:38 / cg" |
699 | 724 |
! ! |
77 | 725 |
|
1812
a048a98aa299
kludge around a situation, where one process
Claus Gittinger <cg@exept.de>
parents:
1577
diff
changeset
|
726 |
!Semaphore class methodsFor:'documentation'! |
183 | 727 |
|
699 | 728 |
version |
5713 | 729 |
^ '$Header: /cvs/stx/stx/libbasic/Semaphore.st,v 1.59 2000-11-16 11:16:59 cg Exp $' |
1 | 730 |
! ! |