mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-23 17:23:44 +08:00
Revert "params: safe and efficient async writing parameters (#25912)"
This reverts commit 780669c33fea1b2a14a0bd6e2eac82c9b8893aa5. old-commit-hash: ec479322d3d8d789290bee68919d14b040481d53
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include <csignal>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "common/queue.h"
|
||||
#include "common/swaglog.h"
|
||||
#include "common/util.h"
|
||||
#include "system/hardware/hw.h"
|
||||
@@ -328,33 +327,3 @@ void Params::clearAll(ParamKeyType key_type) {
|
||||
|
||||
fsync_dir(getParamPath());
|
||||
}
|
||||
|
||||
void Params::putNonBlocking(const std::string &key, const std::string &val) {
|
||||
static AsyncWriter async_writer;
|
||||
async_writer.queue({params_path, key, val});
|
||||
}
|
||||
|
||||
|
||||
// AsyncWriter
|
||||
|
||||
AsyncWriter::~AsyncWriter() {
|
||||
if (future.valid()) {
|
||||
future.wait();
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWriter::queue(const std::tuple<std::string, std::string, std::string> &dat) {
|
||||
q.push(dat);
|
||||
// start thread on demand
|
||||
if (!future.valid() || future.wait_for(std::chrono::milliseconds(0)) == std::future_status::ready) {
|
||||
future = std::async(std::launch::async, &AsyncWriter::write, this);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncWriter::write() {
|
||||
std::tuple<std::string, std::string, std::string> dat;
|
||||
while (q.try_pop(dat, 0)) {
|
||||
auto &[path, key, value] = dat;
|
||||
Params(path).put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user