diff options
author | Josh Blum <josh@joshknows.com> | 2011-06-01 13:57:25 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-06-01 13:57:25 -0700 |
commit | 19ecd43340ce16ced6be530c9dff5cf724a6e160 (patch) | |
tree | 38b761e1f02ece14dcbcc0e8d9184087c638f291 /host/lib/utils/msg.cpp | |
parent | db6fa3812a673481df25f49c0081d4ca63200c66 (diff) | |
download | uhd-19ecd43340ce16ced6be530c9dff5cf724a6e160.tar.gz uhd-19ecd43340ce16ced6be530c9dff5cf724a6e160.tar.bz2 uhd-19ecd43340ce16ced6be530c9dff5cf724a6e160.zip |
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.
Diffstat (limited to 'host/lib/utils/msg.cpp')
-rw-r--r-- | host/lib/utils/msg.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
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; } |