Skip to content

Commit

Permalink
fix(plugins): Avoid double device control releases
Browse files Browse the repository at this point in the history
This was not really broken, but it generated a debug log message
containing the keyword 'error' consistently, which is convoluting any
debugging session.

This commit also adds some trace log message on plugin device control
API calls.
  • Loading branch information
dennisklein committed Jul 7, 2021
1 parent b374c23 commit e2452fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fairmq/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ class Plugin
auto GetCurrentDeviceState() const -> DeviceState { return fPluginServices->GetCurrentDeviceState(); }
auto TakeDeviceControl() -> void { fPluginServices->TakeDeviceControl(fkName); };
auto StealDeviceControl() -> void { fPluginServices->StealDeviceControl(fkName); };
auto ReleaseDeviceControl() -> void { fPluginServices->ReleaseDeviceControl(fkName); };
auto ReleaseDeviceControl() -> void
{
if (fPluginServices->GetDeviceController() == fkName) {
fPluginServices->ReleaseDeviceControl(fkName);
}
};
auto ChangeDeviceState(const DeviceStateTransition next) -> bool { return fPluginServices->ChangeDeviceState(fkName, next); }
auto SubscribeToDeviceStateChange(std::function<void(DeviceState)> callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); }
auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); }
Expand Down
5 changes: 5 additions & 0 deletions fairmq/PluginServices.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* copied verbatim in the file "LICENSE" *
********************************************************************************/

#include <fairlogger/Logger.h>
#include <fairmq/PluginServices.h>
#include <fairmq/tools/Strings.h>

Expand Down Expand Up @@ -34,8 +35,10 @@ auto PluginServices::TakeDeviceControl(const string& controller) -> void

if (!fDeviceController) {
fDeviceController = controller;
LOG(trace) << "Plugin '" << controller << "' took over control.";
} else if (fDeviceController == controller) {
// nothing to do
LOG(trace) << "Plugin '" << controller << "' is already in control.";
} else {
throw DeviceControlError{tools::ToString(
"Plugin '", controller, "' is not allowed to take over control. ",
Expand All @@ -49,6 +52,7 @@ auto PluginServices::StealDeviceControl(const string& controller) -> void
lock_guard<mutex> lock{fDeviceControllerMutex};

fDeviceController = controller;
LOG(trace) << "Plugin '" << controller << "' steals control!";
}

auto PluginServices::ReleaseDeviceControl(const string& controller) -> void
Expand All @@ -58,6 +62,7 @@ auto PluginServices::ReleaseDeviceControl(const string& controller) -> void

if (fDeviceController == controller) {
fDeviceController = boost::none;
LOG(trace) << "Plugin '" << controller << "' releases control.";
} else {
LOG(debug) << "Plugin '" << controller << "' cannot release control "
<< "because it has no control.";
Expand Down

0 comments on commit e2452fa

Please sign in to comment.