2025-12-17 14:55:58 +01:00
|
|
|
import std/[strutils, concurrency/atomics]
|
2025-12-17 00:36:03 +01:00
|
|
|
|
|
|
|
|
type BrokerContext* = distinct uint32
|
|
|
|
|
|
|
|
|
|
func `==`*(a, b: BrokerContext): bool {.borrow.}
|
|
|
|
|
|
|
|
|
|
func `$`*(bc: BrokerContext): string =
|
|
|
|
|
toHex(uint32(bc), 8)
|
|
|
|
|
|
|
|
|
|
const DefaultBrokerContext* = BrokerContext(0xCAFFE14E'u32)
|
|
|
|
|
|
2025-12-17 14:55:58 +01:00
|
|
|
var gContextCounter: Atomic[uint32]
|
|
|
|
|
|
2025-12-18 12:04:41 +01:00
|
|
|
proc newBrokerContext*(): BrokerContext =
|
2025-12-17 14:55:58 +01:00
|
|
|
var nextId = gContextCounter.fetchAdd(1, moRelaxed)
|
|
|
|
|
if nextId == uint32(DefaultBrokerContext):
|
|
|
|
|
nextId = gContextCounter.fetchAdd(1, moRelaxed)
|
|
|
|
|
return BrokerContext(nextId)
|