Need access lock when calling super methods.
authorStefan Vogel <sv@exept.de>
Fri, 03 Nov 2000 17:48:30 +0100
changeset 917 df608391baa5
parent 916 63fddba933d6
child 918 c93d55269f9d
Need access lock when calling super methods.
SharedQueue.st
--- a/SharedQueue.st	Tue Oct 31 19:37:23 2000 +0100
+++ b/SharedQueue.st	Fri Nov 03 17:48:30 2000 +0100
@@ -13,7 +13,7 @@
 "{ Package: 'stx:libbasic2' }"
 
 Queue subclass:#SharedQueue
-	instanceVariableNames:'dataAvailable spaceAvailable'
+	instanceVariableNames:'dataAvailable spaceAvailable accessLock'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Kernel-Processes'
@@ -120,10 +120,13 @@
     |value|
 
     dataAvailable wait.
+    accessLock wait.
     value := super next.
+    accessLock signal.
     spaceAvailable signal.
 
-    ^ value.!
+    ^ value.
+!
 
 nextPut:anObject
     "enter anObject into the queue; wait for available space, if
@@ -131,9 +134,12 @@
      to readers."
 
     spaceAvailable wait.
+    accessLock wait.
     super nextPut:anObject.
+    accessLock signal.
     dataAvailable signal.
-    ^ anObject.!
+    ^ anObject.
+!
 
 readSemaphore
     "return the semaphore which is signalled when data is available
@@ -157,8 +163,11 @@
     [(dataAvailable waitWithTimeout:0) notNil] whileTrue:[
         count := count + 1.
     ].    
-    super removeAll.
-    count timesRepeat:[spaceAvailable signal].!
+    accessLock critical:[
+        super removeAll.
+    ].
+    count timesRepeat:[spaceAvailable signal].
+!
 
 removeLast
     "return the last value in the queue; if it its empty, wait 'til
@@ -169,10 +178,13 @@
     |value|
 
     dataAvailable wait.
-    value := super removeLast.
+    accessLock critical:[
+        value := super removeLast.
+    ].
     spaceAvailable signal.
 
-    ^ value.!
+    ^ value.
+!
 
 writeSemaphore
     "return the semaphore which is signalled when the queue has space
@@ -190,12 +202,14 @@
 
     super init:size.
     dataAvailable := Semaphore new name:'shared q-read'.
-    spaceAvailable := (Semaphore new:size) name:'shared q-write'
+    spaceAvailable := (Semaphore new:size) name:'shared q-write'.
+    accessLock := Semaphore forMutualExclusion.
 
-    "Modified: 25.1.1997 / 00:19:45 / cg"! !
+    "Modified: 25.1.1997 / 00:19:45 / cg"
+! !
 
 !SharedQueue class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic2/SharedQueue.st,v 1.22 2000-10-31 18:37:23 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic2/SharedQueue.st,v 1.23 2000-11-03 16:48:30 stefan Exp $'
 ! !