- live browsing of Self object memory -

lobby traitssharedQueue

CopyDowns: vector

CreatorPath: traits sharedQueue

Module: sharedQueue

parent* = traits collection
copy =
( | c |
    c: clone.
    c rep: list copyRemoveAll.
    c resetLock.
    c)
do: = ( lockSema protect: [rep do: block])block cannot contain non-local returns
filterOut: =
( | in. out |
    in:  list copyRemoveAll.
    out: list copyRemoveAll.
    lockSema protect: [
        rep do: [ | :e | (criteria value: e) ifTrue: [ out add: e ]
                                              False: [ in  add: e ] ].
        rep: in.
    ].
    out)
findFirst:IfPresent:IfAbsent: =
( 
    lockSema protect: [ 
        rep  findFirst: criteria  
             IfPresent: [| :v. :k | 
               ^ p value: v With: k.
           ] IfAbsent: [
               ^ a value
           ].
    ])
resetLock =
( 
    lockSema:  recursiveSemaphore copyBinary.
    blockSema: semaphore copyBinary get.
    self)
Reset lock so I am unlocked. -- dmu
size = ( lockSema protectNoNLR: [rep size])
grabLock = ( lockSema wait)
releaseLock = ( lockSema signal)

adding

add: = ( addOperation: [rep add: elem])
addFirst: = ( addOperation: [rep addFirst: elem])
addLast: = ( addOperation: [rep addLast: elem])
addOperation: =
( 
    lockSema protectNoNLR: [
        addBlk value.  "Add the element."
        0 < count ifTrue: [blockSema signal].
    ].
    self)
'addBlk' must not cause a non-local return.

printing

collectionName = 'sharedQueue'
printStringSize:Depth: = ( lockSema protectNoNLR: [resend.printStringSize: s Depth: d])
statePrintString = ( lockSema protectNoNLR: [resend.statePrintString])

removing

remove: =
( 
    lockSema protectNoNLR: [rep remove: elem].
    self)
removeAll =
( 
    lockSema protectNoNLR: [rep removeAll].
    self)
removeFirst = ( removeFirstOrLast: [rep removeFirst])
removeLast = ( removeFirstOrLast: [rep removeLast])
removeFirstOrLast: =
( | done <- false. res |
    [   lockSema protectNoNLR: [
            rep nonEmpty ifTrue: [res: remBlock value. done: true]
                          False: [count: 1 + count].
        ]. 
        "done predicate on next line added by dmu 2/97"
        done ifFalse: [
          blockSema wait.
          lockSema protectNoNLR: [count: count - 1].
        ].
        done.
    ] whileFalse.
    res)

testing

isEmpty = ( lockSema protectNoNLR: [rep isEmpty])
isOrdered = true