SharedQueue.st
changeset 4068 cadb70dce850
parent 4066 405375f4f7de
child 4346 7a4c996ac8f0
equal deleted inserted replaced
4067:b462a3ff3a61 4068:cadb70dce850
   293         dataAvailable waitUncounted.
   293         dataAvailable waitUncounted.
   294     ].
   294     ].
   295     ^ super peek
   295     ^ super peek
   296 ! !
   296 ! !
   297 
   297 
   298 !SharedQueue methodsFor:'accessing-writing'!
   298 !SharedQueue methodsFor:'adding'!
   299 
   299 
   300 nextPut:anObject
   300 nextPut:anObject
   301     "enter anObject to the end of the queue; 
   301     "enter anObject to the end of the queue; 
   302      wait for available space, if the queue is full. 
   302      do NOT wait for available space, if the queue is full; instead resize as required. 
   303      After the put, signal availablity of a datum to readers."
   303      After the put, signal availablity of a datum to readers."
   304 
   304 
   305     |retVal|
   305     self commonWriteWith:[self superNextPut:anObject].
   306 
   306     ^ self.
   307     spaceAvailable wait.
       
   308     accessLock critical:[
       
   309         retVal := super nextPut:anObject.
       
   310         dataAvailable signal.
       
   311     ].
       
   312     ^ retVal.
       
   313 !
   307 !
   314 
   308 
   315 nextPutFirst:anObject
   309 nextPutFirst:anObject
   316     "insert anObject at the beginning of the queue; 
   310     "insert anObject at the beginning of the queue; 
   317      wait for available space, if the queue is full. 
   311      do NOT wait for available space, if the queue is full, instead resize as required. 
   318      After the put, signal availablity of a datum to readers.
   312      After the put, signal availablity of a datum to readers.
   319      Insertion at the beginning may be useful to add hi-prio elements (for example, in a job-scheduler)"
   313      Insertion at the beginning may be useful to add hi-prio elements (for example, in a job-scheduler)"
   320 
   314 
   321     |retVal|
   315     self commonWriteWith:[self superNextPutFirst:anObject].
   322 
   316     ^ self
   323     spaceAvailable wait.
       
   324     accessLock critical:[
       
   325         retVal := super nextPutFirst:anObject.
       
   326         dataAvailable signal.
       
   327     ].
       
   328     ^ retVal.
       
   329 ! !
   317 ! !
   330 
   318 
   331 !SharedQueue methodsFor:'enumerating'!
   319 !SharedQueue methodsFor:'enumerating'!
   332 
   320 
   333 do:anObject
   321 do:anObject
   354     accessLock := RecursionLock new.
   342     accessLock := RecursionLock new.
   355 
   343 
   356     "Modified: 25.1.1997 / 00:19:45 / cg"
   344     "Modified: 25.1.1997 / 00:19:45 / cg"
   357 ! !
   345 ! !
   358 
   346 
       
   347 !SharedQueue methodsFor:'private'!
       
   348 
       
   349 commonWriteWith:aBlock
       
   350     "common code for nextPut / nextPutFirst; 
       
   351      do NOT wait for available space, if the queue is full; instead resize as required. 
       
   352      After the put, signal availablity of a datum to readers."
       
   353 
       
   354     spaceAvailable wait.
       
   355     accessLock critical:[
       
   356         aBlock value.
       
   357         dataAvailable signal.
       
   358     ].
       
   359 ! !
       
   360 
   359 !SharedQueue class methodsFor:'documentation'!
   361 !SharedQueue class methodsFor:'documentation'!
   360 
   362 
   361 version
   363 version
   362     ^ '$Header$'
   364     ^ '$Header$'
   363 !
   365 !