From 853d8121aff4f56452c8d9950bae143297547c5b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 13 May 2011 12:41:35 -0700 Subject: uhd: work on logging and message facility initialization --- host/lib/utils/msg.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'host/lib/utils/msg.cpp') diff --git a/host/lib/utils/msg.cpp b/host/lib/utils/msg.cpp index e850b5a6d..0fd62bfc1 100644 --- a/host/lib/utils/msg.cpp +++ b/host/lib/utils/msg.cpp @@ -61,20 +61,24 @@ static void msg_to_cerr(const std::string &title, const std::string &msg){ } /*********************************************************************** - * Global settings for the messenger + * Global resources for the messenger **********************************************************************/ -static boost::mutex msg_mutex; -static std::ostringstream msg_ss; -static uhd::msg::type_t msg_type; -static uhd::msg::handler_t msg_handler; +struct msg_resource_type{ + boost::mutex mutex; + std::ostringstream ss; + uhd::msg::type_t type; + uhd::msg::handler_t handler; +}; + +UHD_SINGLETON_FCN(msg_resource_type, msg_rs); /*********************************************************************** * Setup the message handlers **********************************************************************/ void uhd::msg::register_handler(const handler_t &handler){ - msg_mutex.lock(); - msg_handler = handler; - msg_mutex.unlock(); + msg_rs().mutex.lock(); + msg_rs().handler = handler; + msg_rs().mutex.unlock(); } static void default_msg_handler(uhd::msg::type_t type, const std::string &msg){ @@ -108,16 +112,16 @@ UHD_STATIC_BLOCK(msg_register_default_handler){ * The message object implementation **********************************************************************/ uhd::msg::_msg::_msg(const type_t type){ - msg_mutex.lock(); - msg_type = type; + msg_rs().mutex.lock(); + msg_rs().type = type; } uhd::msg::_msg::~_msg(void){ - msg_handler(msg_type, msg_ss.str()); - msg_ss.str(""); //clear for next call - msg_mutex.unlock(); + msg_rs().handler(msg_rs().type, msg_rs().ss.str()); + msg_rs().ss.str(""); //clear for next call + msg_rs().mutex.unlock(); } std::ostream & uhd::msg::_msg::operator()(void){ - return msg_ss; + return msg_rs().ss; } -- cgit v1.2.3