diff -r 4af47e15a741 -r 0ecf0fc76b40 SharedQueue.st --- a/SharedQueue.st Tue Feb 18 17:05:17 2020 +0100 +++ b/SharedQueue.st Wed Feb 19 20:40:49 2020 +0100 @@ -1,3 +1,5 @@ +"{ Encoding: utf8 }" + " COPYRIGHT (c) 1993 by Claus Gittinger All Rights Reserved @@ -291,6 +293,27 @@ !SharedQueue methodsFor:'accessing-reading'! +next + "return the next 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" + + |retVal| + + "/ need a loop here, in case someone else was reading the element in-between the + "/ wait and the accessLock-critical + [ + dataAvailable wait. + retVal := accessLock critical:[super nextOrNil]. + ] doWhile:[retVal isNil]. + spaceAvailable signal. + + ^ retVal. + + "Modified: / 22-02-2017 / 14:40:32 / stefan" + "Modified (comment): / 25-06-2019 / 14:28:44 / Claus Gittinger" +! + nextIfEmpty:exceptionBlock "return the next value in the queue; if it is empty do not wait, but return the value of exceptionBlock. @@ -383,6 +406,18 @@ self commonWriteWith:[self superNextPutFirst:anObject]. "Modified (comment): / 22-02-2017 / 15:18:42 / stefan" +! + +nonBlockingNextPut:aValue + "add data to the queue, but do not block if the queue is full" + + accessLock critical:[ + spaceAvailable consume. + super nextPut:aValue. + dataAvailable signal. + ]. + + "Created: / 19-02-2020 / 17:34:36 / Stefan Vogel" ! ! !SharedQueue methodsFor:'enumerating'! @@ -434,29 +469,6 @@ "Modified (comment): / 22-02-2017 / 15:18:03 / stefan" ! ! -!SharedQueue methodsFor:'reading'! - -next - "return the next 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" - - |retVal| - - "/ need a loop here, in case someone else was reading the element in-between the - "/ wait and the accessLock-critical - [ - dataAvailable wait. - retVal := accessLock critical:[super nextOrNil]. - ] doWhile:[retVal isNil]. - spaceAvailable signal. - - ^ retVal. - - "Modified: / 22-02-2017 / 14:40:32 / stefan" - "Modified (comment): / 25-06-2019 / 14:28:44 / Claus Gittinger" -! ! - !SharedQueue class methodsFor:'documentation'! version