parent
c5cf21c0c4
commit
c51680e701
2 changed files with 47 additions and 13 deletions
|
|
@ -35,8 +35,10 @@ template withLock(t, x: untyped) =
|
|||
release(t.lock)
|
||||
|
||||
proc iterAndMutate*[A](x: var SharedList[A]; action: proc(x: A): bool) =
|
||||
## iterates over the list. If 'action' returns true, the
|
||||
## Iterates over the list. If 'action' returns true, the
|
||||
## current item is removed from the list.
|
||||
##
|
||||
## .. warning:: It may not preserve the element order after some modifications.
|
||||
withLock(x):
|
||||
var n = x.head
|
||||
while n != nil:
|
||||
|
|
@ -47,8 +49,9 @@ proc iterAndMutate*[A](x: var SharedList[A]; action: proc(x: A): bool) =
|
|||
if action(n.d[i]):
|
||||
acquire(x.lock)
|
||||
let t = x.tail
|
||||
dec t.dataLen # TODO considering t.dataLen == 0,
|
||||
# probably the module should be refactored using doubly linked lists
|
||||
n.d[i] = t.d[t.dataLen]
|
||||
dec t.dataLen
|
||||
else:
|
||||
acquire(x.lock)
|
||||
inc i
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue