Skip to content

Commit

Permalink
impl clear for safe-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Oct 27, 2024
1 parent 19e1dde commit c7298f5
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions insideout/mailboxes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,27 @@ proc resume*[T](mail: Mailbox[T]) =
if disable(mail[].state, Paused):
checkWake wakeMask(mail[].state, <<!Paused)

proc clear*[T](mail: var MailboxObj[T]) =
when insideoutSafeMode:
withRLock mail.lock:
while not mail.list.head.isNil:
if mail.list.head.next == mail.list.head: # last item
reset mail.list.head.next
reset mail.list.head
else:
var node = mail.list.head
mail.list.head = node.next
if mail.list.tail.next == node:
mail.list.tail.next = mail.list.head
reset node
else:
if not mail.queue.isNil:
while not pop(mail.queue).isNil:
discard

proc clear*[T](mail: Mailbox[T]) =
when T isnot void:
if not mail[].queue.isNil:
while not pop(mail[].queue).isNil:
discard
clear mail[]

proc waitForEmpty*[T](mail: Mailbox[T]) =
assert not mail.isNil
Expand Down

0 comments on commit c7298f5

Please sign in to comment.