Data-Stack-Shared
view release on metacpan or search on metacpan
* rather than resurrecting a phantom FILLED slot. The pusher's value is
* dropped â equivalent to a crashed pusher. In practice the gap between
* claim_write and publish is sub-microsecond memcpy time, so the false-
* positive threshold is many orders of magnitude away from normal latency. */
static inline uint32_t stk_drain(StkHandle *h) {
StkHeader *hdr = h->hdr;
uint32_t t = __atomic_exchange_n(&hdr->top, 0, __ATOMIC_ACQ_REL);
if (t == 0) return 0;
/* Wall-clock deadline for the per-slot wait. We hot-spin first, then
* fall back to short sleeps to avoid burning a core for 2s on a stuck
* slot. The deadline is checked periodically (every 64 iterations) to
* keep the steady-state cost ~zero. */
for (uint32_t i = 0; i < t; i++) {
struct timespec dl;
int dl_set = 0;
uint32_t spins = 0;
for (;;) {
uint64_t c = __atomic_load_n(&h->ctl[i], __ATOMIC_ACQUIRE);
uint32_t st = STK_SLOT_STATE(c);
if (st == STK_SLOT_FILLED) {
uint64_t nc = (STK_SLOT_GEN(c) << 2) | STK_SLOT_READING;
( run in 0.959 second using v1.01-cache-2.11-cpan-71847e10f99 )