arcan icon indicating copy to clipboard operation
arcan copied to clipboard

(shmif) zero-copy lockfree event queue API

Open letoram opened this issue 6 years ago • 0 comments

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.

letoram avatar Sep 01 '19 15:09 letoram