Skip to content
Open
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: 2 additions & 2 deletions Framework/Core/include/Framework/ServiceRegistryRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ServiceRegistryRef
// cannot be accessed if the streamId is <= 0 and complain accordingly.
// The dataProcessorId will be used to distinguish between different
// data processors when
ServiceRegistryRef(ServiceRegistry& registry, ServiceRegistry::Salt salt = ServiceRegistry::globalDeviceSalt())
explicit ServiceRegistryRef(ServiceRegistry& registry, ServiceRegistry::Salt salt = ServiceRegistry::globalDeviceSalt())
: mRegistry(registry),
mSalt(salt)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ class ServiceRegistryRef
mRegistry.unlock(mSalt);
}

static ServiceRegistryRef *globalDeviceRef(ServiceRegistryRef *ref = nullptr);
static ServiceRegistryRef* globalDeviceRef(ServiceRegistryRef* ref = nullptr);

private:
ServiceRegistry& mRegistry;
Expand Down
32 changes: 16 additions & 16 deletions Framework/Core/src/DataProcessingDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ void DataProcessingDevice::Init()
context.error = spec.algorithm.onError;
context.initError = spec.algorithm.onInitError;

auto configStore = DeviceConfigurationHelpers::getConfiguration(mServiceRegistry, spec.name.c_str(), spec.options);
auto configStore = DeviceConfigurationHelpers::getConfiguration(ServiceRegistryRef{mServiceRegistry}, spec.name.c_str(), spec.options);
if (configStore == nullptr) {
std::vector<std::unique_ptr<ParamRetriever>> retrievers;
retrievers.emplace_back(std::make_unique<FairOptionsRetriever>(GetConfig()));
Expand Down Expand Up @@ -450,7 +450,7 @@ void DataProcessingDevice::Init()
context.init = spec.algorithm.onInit;
if (context.init) {
static bool noCatch = getenv("O2_NO_CATCHALL_EXCEPTIONS") && strcmp(getenv("O2_NO_CATCHALL_EXCEPTIONS"), "0");
InitContext initContext{*mConfigRegistry, mServiceRegistry};
InitContext initContext{*mConfigRegistry, ServiceRegistryRef{mServiceRegistry}};

if (noCatch) {
try {
Expand Down Expand Up @@ -493,7 +493,7 @@ void DataProcessingDevice::Init()

// Invoke the callback policy for this device.
if (spec.callbacksPolicy.policy != nullptr) {
InitContext initContext{*mConfigRegistry, mServiceRegistry};
InitContext initContext{*mConfigRegistry, ServiceRegistryRef{mServiceRegistry}};
spec.callbacksPolicy.policy(mServiceRegistry.get<CallbackService>(ServiceRegistry::globalDeviceSalt()), initContext);
}

Expand Down Expand Up @@ -873,7 +873,7 @@ void DataProcessingDevice::InitTask()

O2_SIGNPOST_ID_FROM_POINTER(cid, device, &context);
O2_SIGNPOST_START(device, cid, "InitTask", "Entering InitTask callback.");
auto& spec = getRunningDevice(mRunningDevice, mServiceRegistry);
auto& spec = getRunningDevice(mRunningDevice, ServiceRegistryRef{mServiceRegistry});
auto distinct = DataRelayerHelpers::createDistinctRouteIndex(spec.inputs);
auto& state = ref.get<DeviceState>();
int i = 0;
Expand All @@ -887,7 +887,7 @@ void DataProcessingDevice::InitTask()
.name = route.configurator->name,
.routeIndex = RouteIndex{i++},
.lifetime = route.matcher.lifetime,
.creator = route.configurator->creatorConfigurator(state, mServiceRegistry, *mConfigRegistry),
.creator = route.configurator->creatorConfigurator(state, ServiceRegistryRef{mServiceRegistry}, *mConfigRegistry),
.checker = route.configurator->danglingConfigurator(state, *mConfigRegistry),
.handler = route.configurator->expirationConfigurator(state, *mConfigRegistry)};
context.expirationHandlers.emplace_back(std::move(handler));
Expand Down Expand Up @@ -981,7 +981,7 @@ void DataProcessingDevice::InitTask()
{
O2_SIGNPOST_EVENT_EMIT(device, cid, "InitTask", "Memory registration event received.");
std::lock_guard<std::mutex> lock(mRegionInfoMutex);
handleRegionCallbacks(mServiceRegistry, mPendingRegionInfos);
handleRegionCallbacks(ServiceRegistryRef{mServiceRegistry}, mPendingRegionInfos);
}
}
O2_SIGNPOST_END(device, cid, "InitTask", "Done waiting for registration events.");
Expand Down Expand Up @@ -1225,15 +1225,15 @@ void DataProcessingDevice::Run()
// no callback is issued if there is something still processing.
{
std::lock_guard<std::mutex> lock(mRegionInfoMutex);
handleRegionCallbacks(mServiceRegistry, mPendingRegionInfos);
handleRegionCallbacks(ServiceRegistryRef{mServiceRegistry}, mPendingRegionInfos);
}
// This will block for the correct delay (or until we get data
// on a socket). We also do not block on the first iteration
// so that devices which do not have a timer can still start an
// enumeration.
{
ServiceRegistryRef ref{mServiceRegistry};
ref.get<DriverClient>().flushPending(mServiceRegistry);
ref.get<DriverClient>().flushPending(ServiceRegistryRef{mServiceRegistry});
DataProcessorContext* lastActive = state.lastActiveDataProcessor.load();
// Reset to zero unless some other DataPorcessorContext completed in the meanwhile.
// In such case we will take care of it at next iteration.
Expand Down Expand Up @@ -1286,7 +1286,7 @@ void DataProcessingDevice::Run()
// Get the current timeslice for the slot.
auto& variables = ref.get<TimesliceIndex>().getVariablesForSlot(slot);
VariableContextHelpers::getTimeslice(variables);
forwardInputs(registry, slot, dropped, oldestOutputInfo, false, true);
forwardInputs(ref, slot, dropped, oldestOutputInfo, false, true);
};
auto& relayer = ref.get<DataRelayer>();
relayer.prunePending(onDrop);
Expand Down Expand Up @@ -1328,7 +1328,7 @@ void DataProcessingDevice::Run()
// fast to transition from Init to Run.
{
std::lock_guard<std::mutex> lock(mRegionInfoMutex);
handleRegionCallbacks(mServiceRegistry, mPendingRegionInfos);
handleRegionCallbacks(ServiceRegistryRef{mServiceRegistry}, mPendingRegionInfos);
}

// Receive and relay incoming data on the main thread so that I/O
Expand Down Expand Up @@ -1693,13 +1693,13 @@ void DataProcessingDevice::doRun(ServiceRegistryRef ref)
if (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed)) {
state.lastActiveDataProcessor.store(&context);
}
DanglingContext danglingContext{*context.registry};
DanglingContext danglingContext{ref};

context.preDanglingCallbacks(danglingContext);
if (state.lastActiveDataProcessor.load() == nullptr) {
ref.get<CallbackService>().call<CallbackService::Id::Idle>();
}
auto activity = ref.get<DataRelayer>().processDanglingInputs(context.expirationHandlers, *context.registry, true);
auto activity = ref.get<DataRelayer>().processDanglingInputs(context.expirationHandlers, ServiceRegistryRef{*context.registry}, true);
if (activity.expiredSlots > 0) {
state.lastActiveDataProcessor = &context;
}
Expand Down Expand Up @@ -1732,7 +1732,7 @@ void DataProcessingDevice::doRun(ServiceRegistryRef ref)
bool shouldProcess = DataProcessingHelpers::hasOnlyGenerated(spec) == false;

while (DataProcessingDevice::tryDispatchComputation(ref, streamContext.completed) && shouldProcess) {
relayer.processDanglingInputs(context.expirationHandlers, *context.registry, false);
relayer.processDanglingInputs(context.expirationHandlers, ServiceRegistryRef{*context.registry}, false);
}

auto& timingInfo = ref.get<TimingInfo>();
Expand All @@ -1747,7 +1747,7 @@ void DataProcessingDevice::doRun(ServiceRegistryRef ref)
timingInfo.creation = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
O2_SIGNPOST_EVENT_EMIT(calibration, dpid, "calibration", "TimingInfo.keepAtEndOfStream %d", timingInfo.keepAtEndOfStream);

EndOfStreamContext eosContext{*context.registry, ref.get<DataAllocator>()};
EndOfStreamContext eosContext{ref, ref.get<DataAllocator>()};

context.preEOSCallbacks(eosContext);
auto& streamContext = ref.get<StreamContext>();
Expand Down Expand Up @@ -2111,7 +2111,7 @@ void DataProcessingDevice::handleData(ServiceRegistryRef ref, InputChannelInfo&
if (oldestPossibleTimeslice != (size_t)-1) {
info.oldestForChannel = {oldestPossibleTimeslice};
auto& context = ref.get<DataProcessorContext>();
context.domainInfoUpdatedCallback(*context.registry, oldestPossibleTimeslice, info.id);
context.domainInfoUpdatedCallback(ref, oldestPossibleTimeslice, info.id);
ref.get<CallbackService>().call<CallbackService::Id::DomainInfoUpdated>((ServiceRegistryRef)*context.registry, (size_t)oldestPossibleTimeslice, (ChannelIndex)info.id);
state.lastActiveDataProcessor = &context;
}
Expand Down Expand Up @@ -2446,7 +2446,7 @@ bool DataProcessingDevice::tryDispatchComputation(ServiceRegistryRef ref, std::v
auto& spec = ref.get<DeviceSpec const>();
InputRecord record{spec.inputs,
span,
*context.registry};
ServiceRegistryRef{*context.registry}};
ProcessingContext processContext{record, ref, ref.get<DataAllocator>()};
{
// Notice this should be thread safe and reentrant
Expand Down
8 changes: 4 additions & 4 deletions Framework/Core/src/ServiceRegistry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void ServiceRegistry::declareService(ServiceSpec const& spec, DeviceState& state
mSpecs.push_back(spec);
// Services which are not stream must have a single instance created upfront.
if (spec.kind != ServiceKind::Stream) {
ServiceHandle handle = spec.init({*this}, state, options);
ServiceHandle handle = spec.init(ServiceRegistryRef{*this}, state, options);
this->registerService({handle.hash}, handle.instance, handle.kind, salt, handle.name.c_str());
this->bindService(salt, spec, handle.instance);
} else if (spec.kind == ServiceKind::Stream) {
Expand All @@ -134,7 +134,7 @@ void ServiceRegistry::lateBindStreamServices(DeviceState& state, fair::mq::ProgO
if (spec.kind != ServiceKind::Stream) {
continue;
}
ServiceHandle handle = spec.init({*this, salt}, state, options);
ServiceHandle handle = spec.init(ServiceRegistryRef{*this, salt}, state, options);
// Do we need to register it again? Maybe not.
this->registerService({handle.hash}, handle.instance, handle.kind, salt, handle.name.c_str());
this->bindService(salt, spec, handle.instance);
Expand All @@ -144,7 +144,7 @@ void ServiceRegistry::lateBindStreamServices(DeviceState& state, fair::mq::ProgO
void ServiceRegistry::postRenderGUICallbacks()
{
for (auto& handle : mPostRenderGUIHandles) {
handle.callback(*this);
handle.callback(ServiceRegistryRef{*this});
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ void* ServiceRegistry::get(ServiceTypeHash typeHash, Salt salt, ServiceKind kind
auto& rawDeviceService = this->get<RawDeviceService>(globalDeviceSalt());
auto& registry = const_cast<ServiceRegistry&>(*this);
// Call init for the proper ServiceRegistryRef
ServiceHandle handle = spec.init({registry, salt}, deviceState, *rawDeviceService.device()->fConfig);
ServiceHandle handle = spec.init(ServiceRegistryRef{registry, salt}, deviceState, *rawDeviceService.device()->fConfig);
this->registerService({handle.hash}, handle.instance, handle.kind, salt, handle.name.c_str());
this->bindService(salt, spec, handle.instance);

Expand Down
22 changes: 11 additions & 11 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry,
&deviceContext,
&driverConfig,
&loop](fair::mq::DeviceRunner& r) {
ServiceRegistryRef serviceRef = {serviceRegistry};
ServiceRegistryRef serviceRef{serviceRegistry};
simpleRawDeviceService = std::make_unique<SimpleRawDeviceService>(nullptr, spec);
serviceRef.registerService(ServiceRegistryHelpers::handleForService<RawDeviceService>(simpleRawDeviceService.get()));

Expand Down Expand Up @@ -1136,7 +1136,7 @@ int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry,
runner.AddHook<fair::mq::hooks::InstantiateDevice>(afterConfigParsingCallback);

auto result = runner.Run();
ServiceRegistryRef serviceRef = {serviceRegistry};
ServiceRegistryRef serviceRef{serviceRegistry};
auto& context = serviceRef.get<DataProcessorContext>();
DataProcessorContext::preExitCallbacks(context.preExitHandles, serviceRef);
return result;
Expand Down Expand Up @@ -1498,7 +1498,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
if (service.driverStartup == nullptr) {
continue;
}
service.driverStartup(serviceRegistry, DeviceConfig{varmap});
service.driverStartup(ServiceRegistryRef{serviceRegistry}, DeviceConfig{varmap});
}

ServiceRegistryRef ref{serviceRegistry};
Expand All @@ -1516,7 +1516,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
// This is to make sure we can process metrics, commands, configuration
// changes coming from websocket (or even via any standard uv_stream_t, I guess).
DriverServerContext serverContext{
.registry = {serviceRegistry},
.registry = ServiceRegistryRef{serviceRegistry},
.loop = loop,
.controls = &controls,
.infos = &infos,
Expand Down Expand Up @@ -1626,7 +1626,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
/// would be that we start an application and then we wait for
/// resource offers from DDS or whatever resource manager we use.
for (auto& callback : driverInitCallbacks) {
callback(serviceRegistry, {varmap});
callback(ServiceRegistryRef{serviceRegistry}, {varmap});
}
driverInfo.states.push_back(DriverState::RUNNING);
// driverInfo.states.push_back(DriverState::REDEPLOY_GUI);
Expand Down Expand Up @@ -1715,7 +1715,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,

LOGP(debug, "Adjusting device {}", device.name.c_str());

auto configStore = DeviceConfigurationHelpers::getConfiguration(serviceRegistry, device.name.c_str(), device.options);
auto configStore = DeviceConfigurationHelpers::getConfiguration(ServiceRegistryRef{serviceRegistry}, device.name.c_str(), device.options);
if (configStore != nullptr) {
auto reg = std::make_unique<ConfigParamRegistry>(std::move(configStore));
for (auto& input : device.inputs) {
Expand Down Expand Up @@ -1897,7 +1897,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
if (device.name.find("internal") != std::string::npos) {
continue;
}
auto configStore = DeviceConfigurationHelpers::getConfiguration(serviceRegistry, device.name.c_str(), device.options);
auto configStore = DeviceConfigurationHelpers::getConfiguration(ServiceRegistryRef{serviceRegistry}, device.name.c_str(), device.options);
if (configStore != nullptr) {
auto reg = std::make_unique<ConfigParamRegistry>(std::move(configStore));
for (auto& option : device.options) {
Expand Down Expand Up @@ -2047,7 +2047,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
callback();
for (auto& service : driverServices) {
if (service.postRenderGUI) {
service.postRenderGUI(serviceRegistry);
service.postRenderGUI(ServiceRegistryRef{serviceRegistry});
}
}
};
Expand Down Expand Up @@ -2153,7 +2153,7 @@ int runStateMachine(DataProcessorSpecs const& workflow,
GETCPU(parentCPU);
#endif
for (auto& callback : preScheduleCallbacks) {
callback(serviceRegistry, {varmap});
callback(ServiceRegistryRef{serviceRegistry}, {varmap});
}
childFds.resize(runningWorkflow.devices.size());
for (int di = 0; di < (int)runningWorkflow.devices.size(); ++di) {
Expand All @@ -2170,14 +2170,14 @@ int runStateMachine(DataProcessorSpecs const& workflow,
runningWorkflow.devices, driverInfo,
controls, deviceExecutions, infos,
allStates,
serviceRegistry, varmap,
ServiceRegistryRef{serviceRegistry}, varmap,
childFds, parentCPU, parentNode);
}
}
handleSignals();
handleChildrenStdio(&serverContext, forwardedStdin.str(), childFds, pollHandles);
for (auto& callback : postScheduleCallbacks) {
callback(serviceRegistry, {varmap});
callback(ServiceRegistryRef{serviceRegistry}, {varmap});
}
assert(infos.empty() == false);

Expand Down
4 changes: 2 additions & 2 deletions Framework/Core/test/benchmark_InputRecord.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void BM_InputRecordGenericGetters(benchmark::State& state)
nullptr,
0};
ServiceRegistry registry;
InputRecord emptyRecord(schema, span, registry);
InputRecord emptyRecord(schema, span, ServiceRegistryRef{registry});

std::vector<void*> inputs;

Expand Down Expand Up @@ -95,7 +95,7 @@ static void BM_InputRecordGenericGetters(benchmark::State& state)
[](size_t, DataRefIndices) -> DataRefIndices { return {size_t(-1), size_t(-1)}; },
nullptr,
inputs.size() / 2};
InputRecord record{schema, span2, registry};
InputRecord record{schema, span2, ServiceRegistryRef{registry}};

for (auto _ : state) {
// Checking we can get the whole ref by name
Expand Down
Loading