parent
d0c4c738b9
commit
492e9afa4c
2 changed files with 24 additions and 4 deletions
|
|
@ -65,11 +65,14 @@ iterator items*[A](x: var SharedList[A]): A =
|
||||||
proc add*[A](x: var SharedList[A]; y: A) =
|
proc add*[A](x: var SharedList[A]; y: A) =
|
||||||
withLock(x):
|
withLock(x):
|
||||||
var node: SharedListNode[A]
|
var node: SharedListNode[A]
|
||||||
if x.tail == nil or x.tail.dataLen == ElemsPerNode:
|
if x.tail == nil:
|
||||||
node = cast[type node](allocShared0(sizeof(node[])))
|
node = cast[typeof node](allocShared0(sizeof(node[])))
|
||||||
node.next = x.tail
|
x.tail = node
|
||||||
|
x.head = node
|
||||||
|
elif x.tail.dataLen == ElemsPerNode:
|
||||||
|
node = cast[typeof node](allocShared0(sizeof(node[])))
|
||||||
|
x.tail.next = node
|
||||||
x.tail = node
|
x.tail = node
|
||||||
if x.head == nil: x.head = node
|
|
||||||
else:
|
else:
|
||||||
node = x.tail
|
node = x.tail
|
||||||
node.d[node.dataLen] = y
|
node.d[node.dataLen] = y
|
||||||
|
|
|
||||||
17
tests/stdlib/tsharedlist.nim
Normal file
17
tests/stdlib/tsharedlist.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import sharedlist
|
||||||
|
|
||||||
|
var
|
||||||
|
list: SharedList[int]
|
||||||
|
count: int
|
||||||
|
|
||||||
|
init(list)
|
||||||
|
|
||||||
|
for i in 1 .. 250:
|
||||||
|
list.add i
|
||||||
|
|
||||||
|
for i in list:
|
||||||
|
inc count
|
||||||
|
|
||||||
|
doAssert count == 250
|
||||||
|
|
||||||
|
deinitSharedList(list)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue