mlistdeques.nim 772 B

123456789101112131415161718192021222324252627282930313233343536
  1. # listdeques
  2. # needed, type bound ops aren't considered for undeclared procs
  3. type Placeholder = object
  4. proc allocate(_: Placeholder) = discard
  5. proc delete(_: Placeholder) = discard
  6. type
  7. StealableTask* = concept task, var mutTask, type T
  8. task is ptr
  9. task.prev is T
  10. task.next is T
  11. task.parent is T
  12. task.fn is proc (param: pointer) {.nimcall.}
  13. allocate(mutTask)
  14. delete(task)
  15. ListDeque*[T: StealableTask] = object
  16. head, tail: T
  17. func isEmpty*(dq: ListDeque): bool {.inline.} =
  18. discard
  19. func popFirst*[T](dq: var ListDeque[T]): T =
  20. discard
  21. proc `=destroy`*[T: StealableTask](dq: var ListDeque[T]) =
  22. mixin delete
  23. if dq.isEmpty():
  24. return
  25. while (let task = dq.popFirst(); not task.isNil):
  26. delete(task)
  27. delete(dq.head)