From 19ecd43340ce16ced6be530c9dff5cf724a6e160 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 1 Jun 2011 13:57:25 -0700 Subject: uhd: tweaks to log and msg implementation The implementations now contain the string stream in each instance. This way there is not a global stringstream to lock access to. This resolves the issue of nested log calls locking condition. --- host/lib/utils/msg.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'host/lib/utils/msg.cpp') diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp index 0fd62bfc1..de98ada64 100644 --- a/host/lib/utils/msg.cpp +++ b/host/lib/utils/msg.cpp @@ -65,8 +65,6 @@ static void msg_to_cerr(const std::string &title, const std::string &msg){ **********************************************************************/ struct msg_resource_type{ boost::mutex mutex; - std::ostringstream ss; - uhd::msg::type_t type; uhd::msg::handler_t handler; }; @@ -76,9 +74,8 @@ UHD_SINGLETON_FCN(msg_resource_type, msg_rs); * Setup the message handlers **********************************************************************/ void uhd::msg::register_handler(const handler_t &handler){ - msg_rs().mutex.lock(); + boost::mutex::scoped_lock lock(msg_rs().mutex); msg_rs().handler = handler; - msg_rs().mutex.unlock(); } static void default_msg_handler(uhd::msg::type_t type, const std::string &msg){ @@ -111,17 +108,21 @@ UHD_STATIC_BLOCK(msg_register_default_handler){ /*********************************************************************** * The message object implementation **********************************************************************/ +struct uhd::msg::_msg::impl{ + std::ostringstream ss; + type_t type; +}; + uhd::msg::_msg::_msg(const type_t type){ - msg_rs().mutex.lock(); - msg_rs().type = type; + _impl = UHD_PIMPL_MAKE(impl, ()); + _impl->type = type; } uhd::msg::_msg::~_msg(void){ - msg_rs().handler(msg_rs().type, msg_rs().ss.str()); - msg_rs().ss.str(""); //clear for next call - msg_rs().mutex.unlock(); + boost::mutex::scoped_lock lock(msg_rs().mutex); + msg_rs().handler(_impl->type, _impl->ss.str()); } std::ostream & uhd::msg::_msg::operator()(void){ - return msg_rs().ss; + return _impl->ss; } -- cgit v1.2.3