Skip to content
Snippets Groups Projects

Feature/forgetting in wm and em

Merged Fabian Tërnava requested to merge feature/forgetting-in-wm-and-em into master
Compare and Show latest version
6 files
+ 29
40
Compare changes
  • Side-by-side
  • Inline
Files
6
#pragma once
#include <atomic>
#include <chrono>
#include <thread>
#include <SimoxUtility/json.h>
#include <ArmarXCore/core/services/tasks/PeriodicTask.h>
@@ -31,6 +35,12 @@ namespace armarx::armem::server::ltm::detail::mixin
TIMING_END_STREAM(LTM_Memory_DirectlyStore, ARMARX_DEBUG);
}
void
bufferFinished()
{
//use this to count how much work is still left
}
protected:
void
setMixinMemoryID(const MemoryID& id)
@@ -51,6 +61,8 @@ namespace armarx::armem::server::ltm::detail::mixin
task = new armarx::PeriodicTask<BufferedMemoryMixin>(
this, &BufferedMemoryMixin::storeBuffer, waitingTimeMs);
task->start();
task->setDelayWarningTolerance(
waitingTimeMs); //a warning will be issued if the task takes longer than the waitingTime
}
}
@@ -62,6 +74,7 @@ namespace armarx::armem::server::ltm::detail::mixin
task->stop();
task = nullptr;
}
}
armem::wm::Memory
@@ -87,7 +100,12 @@ namespace armarx::armem::server::ltm::detail::mixin
return;
}
while (storeFlag.test_and_set(std::memory_order_acquire))
{
std::this_thread::yield();
}
this->directlyStore(*to_store);
storeFlag.clear(std::memory_order_release);
}
/// configuration
@@ -97,9 +115,17 @@ namespace armarx::armem::server::ltm::detail::mixin
if (json.find("BufferedMemory.storeFrequency") != json.end())
{
storeFrequency = json.at("BufferedMemory.storeFrequency");
ARMARX_INFO << "Setting store frequency from configuration json to "
<< storeFrequency;
}
}
void
createPropertyDefinitions(PropertyDefinitionsPtr& defs, const std::string& prefix)
{
defs->optional(storeFrequency, prefix + "storeFrequency");
}
virtual void _directlyStore(const armem::wm::Memory& memory) = 0;
void
@@ -109,6 +135,7 @@ namespace armarx::armem::server::ltm::detail::mixin
buffer->append(memory);
}
protected:
/// Internal memory for data consolidated from wm to ltm (double-buffer)
/// The to-put-to-ltm buffer (contains data in plain text)
@@ -116,6 +143,7 @@ namespace armarx::armem::server::ltm::detail::mixin
/// This means that it is not guaranteed that all data in the buffer will be stored in the ltm
std::unique_ptr<armem::wm::Memory> buffer;
std::unique_ptr<armem::wm::Memory> to_store;
std::atomic_flag storeFlag = ATOMIC_FLAG_INIT;
/// The frequency (Hz) to store data to the ltm
float storeFrequency = 10;
Loading