mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-07 16:33:08 +00:00
19 lines
518 B
Nim
19 lines
518 B
Nim
import std/[strutils, concurrency/atomics]
|
|
|
|
type BrokerContext* = distinct uint32
|
|
|
|
func `==`*(a, b: BrokerContext): bool {.borrow.}
|
|
|
|
func `$`*(bc: BrokerContext): string =
|
|
toHex(uint32(bc), 8)
|
|
|
|
const DefaultBrokerContext* = BrokerContext(0xCAFFE14E'u32)
|
|
|
|
var gContextCounter: Atomic[uint32]
|
|
|
|
proc newBrokerContext*(): BrokerContext =
|
|
var nextId = gContextCounter.fetchAdd(1, moRelaxed)
|
|
if nextId == uint32(DefaultBrokerContext):
|
|
nextId = gContextCounter.fetchAdd(1, moRelaxed)
|
|
return BrokerContext(nextId)
|