244 ]. |
244 ]. |
245 ^ result |
245 ^ result |
246 |
246 |
247 "Created: / 08-06-2007 / 13:23:03 / cg" |
247 "Created: / 08-06-2007 / 13:23:03 / cg" |
248 "Modified: / 09-06-2007 / 14:22:47 / cg" |
248 "Modified: / 09-06-2007 / 14:22:47 / cg" |
|
249 ! |
|
250 |
|
251 critical:aBlock timeoutMs:timeoutMs ifBlocking:blockingBlock |
|
252 "like critical:, but do not block if the lock cannot be aquired |
|
253 within timeoutMs milliseconds. |
|
254 Instead, return the value of blockingBlock." |
|
255 |
|
256 |active retVal wasBlocked gotSema| |
|
257 |
|
258 active := Processor activeProcess. |
|
259 process == active ifTrue:[ |
|
260 "I have already got the lock" |
|
261 ^ aBlock value |
|
262 ]. |
|
263 |
|
264 "/ |
|
265 "/ sema wait & process := active |
|
266 "/ and: |
|
267 "/ proces := nil & sema signal |
|
268 "/ must both be done atomic |
|
269 "/ Scenario: |
|
270 "/ ... recLock critical |
|
271 "/ got lock |
|
272 "/ evaluated |
|
273 "/ set process to nil |
|
274 "/ -> timer interrupt |
|
275 "/ recLock critical in timeOut action |
|
276 "/ process isNil |
|
277 "/ sema wait !!!!!! DEADLOCK |
|
278 "/ |
|
279 wasBlocked := OperatingSystem blockInterrupts. |
|
280 [ |
|
281 gotSema := sema waitWithTimeoutMs:timeoutMs. |
|
282 gotSema notNil ifTrue:[ |
|
283 process := active. |
|
284 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
285 retVal := aBlock value. |
|
286 ]. |
|
287 ] ifCurtailed:[ |
|
288 "be careful - the unwind may occur both while waiting |
|
289 AND while evaluating the block" |
|
290 gotSema notNil ifTrue:[ |
|
291 OperatingSystem blockInterrupts. |
|
292 process := nil. |
|
293 sema signal. |
|
294 ]. |
|
295 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
296 ]. |
|
297 gotSema notNil ifTrue:[ |
|
298 OperatingSystem blockInterrupts. |
|
299 process := nil. |
|
300 sema signal. |
|
301 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
302 ] ifFalse:[ |
|
303 wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
304 retVal := blockingBlock value. |
|
305 ]. |
|
306 |
|
307 ^ retVal. |
249 ! ! |
308 ! ! |
250 |
309 |
251 !RecursionLock class methodsFor:'documentation'! |
310 !RecursionLock class methodsFor:'documentation'! |
252 |
311 |
253 version |
312 version |
254 ^ '$Header: /cvs/stx/stx/libbasic/RecursionLock.st,v 1.34 2009-06-13 08:34:17 cg Exp $' |
313 ^ '$Header: /cvs/stx/stx/libbasic/RecursionLock.st,v 1.35 2010-02-04 09:03:44 stefan Exp $' |
255 ! ! |
314 ! |
|
315 |
|
316 version_CVS |
|
317 ^ '$Header: /cvs/stx/stx/libbasic/RecursionLock.st,v 1.35 2010-02-04 09:03:44 stefan Exp $' |
|
318 ! ! |