Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Framework/Core/include/Framework/DeviceState.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef struct uv_loop_s uv_loop_t;
typedef struct uv_timer_s uv_timer_t;
typedef struct uv_poll_s uv_poll_t;
typedef struct uv_signal_s uv_signal_t;
typedef struct uv_async_s uv_async_t;

namespace o2::framework
{
Expand Down Expand Up @@ -78,6 +79,9 @@ struct DeviceState {
std::vector<uv_poll_t*> activeOutputPollers;
/// The list of active signal handlers
std::vector<uv_signal_t*> activeSignals;

uv_async_t* awakeMainThread = nullptr;

int loopReason = 0;
};

Expand Down
16 changes: 16 additions & 0 deletions Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,22 @@ void handleRegionCallbacks(ServiceRegistry& registry, std::vector<FairMQRegionIn
}
}

namespace
{
void on_awake_main_thread(uv_async_t* handle)
{
DeviceState* state = (DeviceState*)handle->data;
state->loopReason |= DeviceState::ASYNC_NOTIFICATION;
}
} // namespace
void DataProcessingDevice::InitTask()
{
if (mState.awakeMainThread == nullptr) {
mState.awakeMainThread = (uv_async_t*)malloc(sizeof(uv_async_t));
mState.awakeMainThread->data = &mState;
uv_async_init(mState.loop, mState.awakeMainThread, on_awake_main_thread);
}

for (auto& channel : fChannels) {
channel.second.at(0).Transport()->SubscribeToRegionEvents([this,
&registry = mServiceRegistry,
Expand All @@ -372,6 +386,8 @@ void DataProcessingDevice::InitTask()
// When not running we can handle the callbacks synchronously.
if (this->GetCurrentState() != fair::mq::State::Running) {
handleRegionCallbacks(registry, pendingRegionInfos);
} else {
uv_async_send(registry.get<DeviceState>().awakeMainThread);
}
});
}
Expand Down