From 69b5ad2b5c0d5ccb62663ce116852317a2bd1e97 Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" Date: Tue, 27 Jul 2021 12:48:49 +0200 Subject: [PATCH] os/impl/LogForwarder: Do not use a static Bottle CC-Issue #2643 --- src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp | 9 +++------ src/libYARP_os/src/yarp/os/impl/LogForwarder.h | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp b/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp index b1b11f9d9f8..beaf80e7582 100644 --- a/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp +++ b/src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp @@ -37,7 +37,6 @@ yarp::os::impl::LogForwarder::LogForwarder() if (!outputPort.open(logPortName)) { printf("LogForwarder error while opening port %s\n", logPortName.c_str()); } - outputPort.enableBackgroundWrite(true); outputPort.addOutput("/yarplogger", "fast_tcp"); started = true; @@ -46,12 +45,12 @@ yarp::os::impl::LogForwarder::LogForwarder() void yarp::os::impl::LogForwarder::forward(const std::string& message) { mutex.lock(); - static Bottle b; + Bottle& b = outputPort.prepare(); b.clear(); std::string port = "[" + outputPort.getName() + "]"; b.addString(port); b.addString(message); - outputPort.write(b); + outputPort.writeStrict(); mutex.unlock(); } @@ -68,9 +67,7 @@ void yarp::os::impl::LogForwarder::shutdown() yarp::os::impl::LogForwarder& fw = getInstance(); fw.forward(ost.str()); - while (fw.outputPort.isWriting()) { - yarp::os::SystemClock::delaySystem(0.2); - } + fw.outputPort.waitForWrite(); fw.outputPort.interrupt(); fw.outputPort.close(); } diff --git a/src/libYARP_os/src/yarp/os/impl/LogForwarder.h b/src/libYARP_os/src/yarp/os/impl/LogForwarder.h index 28188bd7e8c..52c7758b9e7 100644 --- a/src/libYARP_os/src/yarp/os/impl/LogForwarder.h +++ b/src/libYARP_os/src/yarp/os/impl/LogForwarder.h @@ -8,7 +8,8 @@ #include -#include +#include +#include #include #include @@ -32,7 +33,7 @@ class YARP_os_impl_API LogForwarder LogForwarder& operator=(LogForwarder const&) = delete; std::mutex mutex; - yarp::os::Port outputPort; + yarp::os::BufferedPort outputPort; static bool started; };