Fix data races
This PR addresses several issues:
- A data race is possible in
EventServer::AddEvent()
in ExternalLoop mode, because it is called byEventSet::AddSetToServer()
which was outside of any spinlock. The call is moved inside an existing spinlock to fix this. - The local variable
ninflight
, used for the stopping condition when processing an event, was calculated as the difference of two atomics, a quantity which itself is not necessarily atomic. With @agheata, I determined that the other stopping conditionndone >= fNprimaries
is no longer necessary (since events are now loaded with all primaries before processing starts, which at some earlier stage was not necessarily the case). Therefore, it is not actually needed to trackfNdone
orfNtracks
, just a newfNinflight
that is atomically incremented and decremented. This reduces the number of atomic operations needed and simplifies the bookkeeping inEvent
. (Additionally, the atomic write-read operation onfNinflight
is intended to force a cache synchronization beforeRunManager::EventTransported()
is called, which can merge the user data across multiple threads.) - Some unused variables were removed (cleanup).