race when manipulating interruptActions
authorClaus Gittinger <cg@exept.de>
Wed, 02 Aug 2000 13:11:32 +0200
changeset 5490 38880aca9320
parent 5489 76788e74329f
child 5491 717a2ca22b16
race when manipulating interruptActions
Process.st
--- a/Process.st	Sun Jul 30 20:48:38 2000 +0200
+++ b/Process.st	Wed Aug 02 13:11:32 2000 +0200
@@ -13,8 +13,8 @@
 "{ Package: 'stx:libbasic' }"
 
 Link subclass:#Process
-	instanceVariableNames:'id suspendContext prio state startBlock name restartable interruptActions
-		exitActions suspendSemaphore singleStepping
+	instanceVariableNames:'id suspendContext prio state startBlock name restartable
+		interruptActions exitActions suspendSemaphore singleStepping
 		emergencySignalHandler suspendActions creatorId processGroupId
 		interruptsDisabled priorityRange exceptionHandlerSet processType'
 	classVariableNames:'TerminateSignal RestartSignal CoughtSignals'
@@ -784,16 +784,16 @@
      The name is somewhat misleading (actually, its historic):
      the block is also evaluated on resume."
 
-    self uninterruptablyDo:[
-	interruptActions isNil ifTrue:[
-	    interruptActions := OrderedCollection with:aBlock.
-	] ifFalse:[
-	    interruptActions addLast:aBlock.
-	].
+    |wasBlocked|
+
+    wasBlocked := OperatingSystem blockInterrupts.
+    interruptActions isNil ifTrue:[
+        interruptActions := OrderedCollection with:aBlock.
+    ] ifFalse:[
+        interruptActions addLast:aBlock.
     ].
+    wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
 
-    "Created: 5.3.1996 / 17:10:10 / cg"
-    "Modified: 8.3.1996 / 13:03:10 / cg"
 !
 
 blockInterrupts
@@ -849,21 +849,20 @@
      The process will go back to where it got interrupted
      after doing this."
 
-    |action|
+    |action wasBlocked|
 
     [interruptActions size > 0] whileTrue:[
-	self uninterruptablyDo:[
-	    action := interruptActions removeFirst
-	].
-	action numArgs == 1 ifTrue:[
-	    action value:thisContext sender
-	] ifFalse:[
-	    action value
-	]
+        wasBlocked := OperatingSystem blockInterrupts.
+        action := interruptActions removeFirst.
+        interruptActions size == 0 ifTrue:[interruptActions := nil].
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+        action numArgs == 1 ifTrue:[
+            action value:thisContext sender
+        ] ifFalse:[
+            action value
+        ]
     ].
-    interruptActions := nil
-
-    "Modified: 9.8.1997 / 17:20:38 / cg"
 !
 
 interruptWith:aBlock
@@ -889,29 +888,30 @@
      was scheduled for the process, and the process is resumed.
      The process will go back to where it got interrupted after doing this."
 
-    |action|
+    |action wasBlocked|
 
     "/ the returned value here has a subtle effect:
     "/ if false, the interrupt is assumed to be not taken,
     "/ and will be redelivered.
 
     interruptsDisabled == true ifTrue:[
-	"/ no, I dont want interrupts right now;
-	"/ try again later.
-	^ false
+        "/ no, I dont want interrupts right now;
+        "/ try again later.
+        ^ false
     ].
 
     [interruptActions size > 0] whileTrue:[
-	self uninterruptablyDo:[
-	    action := interruptActions removeFirst
-	].
-	action numArgs == 1 ifTrue:[
-	    action value:aContext
-	] ifFalse:[
-	    action value
-	]
+        wasBlocked := OperatingSystem blockInterrupts.
+        action := interruptActions removeFirst.
+        interruptActions size == 0 ifTrue:[interruptActions := nil].
+        wasBlocked ifFalse:[OperatingSystem unblockInterrupts].
+
+        action numArgs == 1 ifTrue:[
+            action value:aContext
+        ] ifFalse:[
+            action value
+        ]
     ].
-    interruptActions := nil.
     ^ true
 
     "Created: 18.10.1996 / 20:43:39 / cg"
@@ -1823,6 +1823,6 @@
 !Process class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.112 2000-07-07 14:26:44 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Process.st,v 1.113 2000-08-02 11:11:32 cg Exp $'
 ! !
 Process initialize!