loony/node

Search:
Group by:
Source   Edit  

Provided are atomic counters and templates/functions which assist measuring memory leaks with loony. This is primarily used when debugging the algorithm and is unlikely to be required by end-users. There is a cost in using these functions as they use costly atomic writes.

Types

Node = object
  slots*: array[N, Atomic[uint]]
  next*: Atomic[NodePtr]
  ctrl*: ControlBlock
Source   Edit  

Vars

deqCounter {.global.}: Atomic[int]
Source   Edit  
deqPathCounter {.global.}: Atomic[int]
Source   Edit  
enqCounter {.global.}: Atomic[int]
Source   Edit  
enqPathCounter {.global.}: Atomic[int]
Source   Edit  
nodeCounter {.global.}: Atomic[int]
Source   Edit  
reclaimCounter {.global.}: Atomic[int]
Source   Edit  
recPathCounter {.global.}: Atomic[int]
Source   Edit  

Procs

proc `=destroy`(n: var Node) {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc allocNode(): ptr Node {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc allocNode[T](pel: T): ptr Node
Source   Edit  
proc compareAndSwapNext(t: NodePtr; expect: var uint; swap: uint): bool {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc compareAndSwapNext(t: var Node; expect: var uint; swap: uint): bool {.
    ...raises: [], tags: [], forbids: [].}
Source   Edit  
proc deallocNode(n: ptr Node) {....raises: [], tags: [], forbids: [].}
Source   Edit  
proc echoDebugNodeCounter() {....raises: [Exception], tags: [RootEffect],
                              forbids: [].}
This will output the counter Source   Edit  
proc fetchAddSlot(t: var Node; idx: uint16; w: uint; moorder: MemoryOrder): uint {.
    ...raises: [], tags: [], forbids: [].}

Fetches the pointer to the object in the slot while atomically increasing the value by w.

Remembering that the pointer has 3 tail bits clear; these are reserved and increased atomically to indicate RESUME, READER, WRITER statuship.

Source   Edit  
proc fetchNext(node: NodePtr; moorder: MemoryOrder): NodePtr {....raises: [],
    tags: [], forbids: [].}
Source   Edit  
proc incrDeqCount(node: var Node; final: uint16 = 0) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc incrEnqCount(node: var Node; final: uint16 = 0) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc prepareElement[T](el: var T): uint
Prepare an item for the queue: ensure that no other threads will free it, then turn it into an integer and add the WRITER bit. Source   Edit  
proc tryReclaim(node: var Node; start: uint16) {....raises: [], tags: [],
    forbids: [].}
Source   Edit  

Templates

template debugNodeCounter(body: untyped)
Source   Edit  
template decDebugCounter(): untyped
Source   Edit  
template incDebugCounter(): untyped
Source   Edit  
template incDeqCounter(): untyped
Source   Edit  
template incDeqPathCounter(): untyped
Source   Edit  
template incEnqCounter(): untyped
Source   Edit  
template incEnqPathCounter(): untyped
Source   Edit  
template incReclaimCounter(): untyped
Source   Edit  
template incRecPathCounter(): untyped
Source   Edit  
template prn(idx: uint16): uint16
prn = 'Pro re nata' - when required Provides the actual index depending on if we are rotating the index or not. Source   Edit  
template toNode(pt: NodePtr | uint): Node
Source   Edit  
template toNodePtr(pt: uint | ptr Node): NodePtr
Source   Edit  
template toUInt(node: var Node): uint
Source   Edit  
template toUInt(nodeptr: ptr Node): uint
Source   Edit