The replacement for CreateEvent is eventfd, you probably want EFD_CLOEXEC
and EFD_NONBLOCK
flags. Don’t use the semaphore flag unless you know what you’re doing.
The replacement for WaitForMultipleObjects is poll, specify the POLLIN
flag in the requested events. Just keep in mind the event is not being reset by poll, it will stay signalled. Read 8 bytes from the eventfd handle to reset. The functionality is identical to manual-reset events on Windows.
To signal an event, call write on the eventfd
handle, passing the address of a local uint64_t
variable with value 1.
To destroy events once you no longer need them, just call close.
Update: I’ve just noticed you’re passing bWaitAll=TRUE
to WaitForMultipleObjects
.
Unfortunately, Linux poll can’t quite do that. It returns when timeout is expired, or when at least 1 handle becomes signaled, whichever happens first.
Still, the workaround is not too hard. You can emulate bWaitAll
by calling poll multiple times in a loop until all of the events are signaled. No need to rebuild the array of handles, you can set file handle to a negative value for the events which became signaled after poll returned. Note that multiple of them may become signaled at once, poll return value tells how many of them did. Also don't forget to decrease the timeout value.