--- a/Queue.st Wed Jun 12 13:35:16 1996 +0200
+++ b/Queue.st Sat Jun 22 18:52:25 1996 +0200
@@ -17,7 +17,7 @@
category:'Collections-Ordered'
!
-!Queue class methodsFor:'documentation'!
+!Queue class methodsFor:'documentation'!
copyright
"
@@ -55,7 +55,7 @@
"
! !
-!Queue class methodsFor:'instance creation'!
+!Queue class methodsFor:'instance creation'!
new
"return a new queue with space for some elements"
@@ -143,6 +143,29 @@
(tally == 0) ifTrue:[^ nil].
^ contentsArray at:readPosition.
+!
+
+removeLast
+ "return the last value in the queue;
+ Return nil, if the queue is empty"
+
+ |value pos "{ Class: SmallInteger }"|
+
+ (tally == 0) ifTrue:[^ nil].
+
+ pos := writePosition.
+ pos == 1 ifTrue:[
+ pos := contentsArray size
+ ] ifFalse:[
+ pos := pos - 1.
+ ].
+
+ value := contentsArray at:pos.
+ writePosition := pos.
+ tally := tally - 1.
+ ^ value
+
+ "Created: 22.6.1996 / 18:49:41 / cg"
! !
!Queue methodsFor:'enumerating'!
@@ -200,8 +223,8 @@
^ tally
! !
-!Queue class methodsFor:'documentation'!
+!Queue class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.17 1996-05-18 15:32:39 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/Queue.st,v 1.18 1996-06-22 16:52:09 cg Exp $'
! !
--- a/SharedQueue.st Wed Jun 12 13:35:16 1996 +0200
+++ b/SharedQueue.st Sat Jun 22 18:52:25 1996 +0200
@@ -17,7 +17,7 @@
category:'Kernel-Processes'
!
-!SharedQueue class methodsFor:'documentation'!
+!SharedQueue class methodsFor:'documentation'!
copyright
"
@@ -123,6 +123,38 @@
"Modified: 16.12.1995 / 13:47:11 / cg"
!
+removeLast
+ "return the last value in the queue; if it its empty, wait 'til
+ something is put into the receiver.
+ When the datum has been removed, signal space-availability to
+ writers"
+
+ |value ok|
+
+ ok := false.
+ [ok] whileFalse:[
+ [tally == 0] whileTrue:[
+ dataAvailable wait
+ ].
+ accessProtect critical:[
+ "
+ this check is needed, since another process may
+ have read the value in the meantime ...
+ "
+ tally == 0 ifFalse:[
+ value := super removeLast.
+ tally == (contentsArray size - 1) ifTrue:[
+ spaceAvailable signal
+ ].
+ ok := true
+ ]
+ ]
+ ].
+ ^ value
+
+ "Created: 22.6.1996 / 18:50:12 / cg"
+!
+
writeSemaphore
"return the semaphore which is signalled when the queue has space
for writing."
@@ -143,8 +175,8 @@
spaceAvailable := Semaphore new
! !
-!SharedQueue class methodsFor:'documentation'!
+!SharedQueue class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/SharedQueue.st,v 1.15 1996-04-25 16:54:09 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/SharedQueue.st,v 1.16 1996-06-22 16:52:25 cg Exp $'
! !