Skip to content
Snippets Groups Projects
Commit 68204b4c authored by Joana Plewnia's avatar Joana Plewnia
Browse files

fixed race condition in MNS and added info output when clients are still...

fixed race condition in MNS and added info output when clients are still waiting for servers (with Fabian R.)
parent 3259c726
No related branches found
No related tags found
No related merge requests found
Pipeline #21583 failed
#include "MemoryNameSystem.h"
namespace armarx::armem::mns
{
// dto::WaitForServerResult MemoryNameSystem::waitForServer(const dto::WaitForServerInput& input)
void MemoryNameSystem::waitForServer_async(
void
MemoryNameSystem::waitForServer_async(
const AMD_MemoryNameSystemInterface_waitForServerPtr& future,
const dto::WaitForServerInput& input)
{
waitForServerFutures[input.name].push_back(future);
ARMARX_INFO << "Waiting for server `" << input.name << "`.";
{
std::lock_guard g{futuresMtx};
waitForServerFutures[input.name].push_back(future);
}
waitForServer_processOnce();
}
void MemoryNameSystem::waitForServer_processOnce()
void
MemoryNameSystem::waitForServer_processOnce()
{
std::lock_guard g{futuresMtx};
for (auto it = waitForServerFutures.begin(); it != waitForServerFutures.end();)
{
auto& [name, futures] = *it;
......@@ -32,16 +40,20 @@ namespace armarx::armem::mns
{
future->ice_response(result);
}
// it: iterator following the last removed element (https://en.cppreference.com/w/cpp/container/map/erase)
it = waitForServerFutures.erase(it);
}
else
{
++it; // Skip.
++it; // Skip.
ARMARX_INFO << "Server `" << name << "` not available yet.";
}
}
}
dto::RegisterServerResult MemoryNameSystem::registerServer(const dto::RegisterServerInput& input)
dto::RegisterServerResult
MemoryNameSystem::registerServer(const dto::RegisterServerInput& input)
{
const auto result = Registry::registerServer(input);
waitForServer_processOnce();
......@@ -49,8 +61,8 @@ namespace armarx::armem::mns
return result;
}
armarx::RemoteGui::Client::GridLayout MemoryNameSystem::RemoteGui_buildInfoGrid()
armarx::RemoteGui::Client::GridLayout
MemoryNameSystem::RemoteGui_buildInfoGrid()
{
using namespace armarx::RemoteGui::Client;
......@@ -58,10 +70,9 @@ namespace armarx::armem::mns
int row = 0;
grid.add(Label("Memory Name"), {row, 0})
.add(Label("Component Name"), {row, 1})
.add(Label("R/W/P/A"), {row, 2})
.add(Label("Registration Time"), {row, 3})
;
.add(Label("Component Name"), {row, 1})
.add(Label("R/W/P/A"), {row, 2})
.add(Label("Registration Time"), {row, 3});
row++;
for (const auto& [name, info] : servers)
......@@ -109,4 +120,4 @@ namespace armarx::armem::mns
return grid;
}
}
} // namespace armarx::armem::mns
#pragma once
#include "Registry.h"
#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
#include <map>
#include <mutex>
#include <string>
#include <ArmarXGui/libraries/ArmarXGuiComponentPlugins/LightweightRemoteGuiComponentPlugin.h>
#include <map>
#include <string>
#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
#include "Registry.h"
namespace armarx::armem::mns
{
......@@ -16,18 +16,15 @@ namespace armarx::armem::mns
class MemoryNameSystem : public Registry
{
public:
using WaitForServerFuturePtr = AMD_MemoryNameSystemInterface_waitForServerPtr;
public:
/**
* @brief Store the call in a container for later response.
*/
void waitForServer_async(
const AMD_MemoryNameSystemInterface_waitForServerPtr& future,
const dto::WaitForServerInput& input);
void waitForServer_async(const AMD_MemoryNameSystemInterface_waitForServerPtr& future,
const dto::WaitForServerInput& input);
void waitForServer_processOnce();
......@@ -38,11 +35,11 @@ namespace armarx::armem::mns
armarx::RemoteGui::Client::GridLayout RemoteGui_buildInfoGrid();
public:
private:
/// Queued calls to `waitForServer`.
std::map<std::string, std::vector<WaitForServerFuturePtr>> waitForServerFutures;
std::mutex futuresMtx;
};
}
} // namespace armarx::armem::mns
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment