arcan
arcan copied to clipboard
(shmif) zero-copy lockfree event queue API
The ring-buffers and _enqueue / _dequeue approach is starting to show its age. A better approach to the front-back ring-buffer with copy+step+mutex would be to use two 64bit- atomic bitmaps, one for 'pending' and one for 'commit', with alloc being fls(~pending).
_get_slot () -> find free bit from last in pending, flip and return the bit and arcan_event* into which the caller can write. if queue is full, set a futex on the pending and wait.
_commit(bit) -> set the corresponding bit in commit.
On the other side, load the commit bitmap, sweep LSB to MSB, and 0 out the commit bitmap and the alloc bitmap for the slots in question.