summaryrefslogtreecommitdiffstats
path: root/host/lib/utils/msg.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-05-16 12:08:23 -0700
committerJosh Blum <josh@joshknows.com>2011-05-16 12:08:23 -0700
commit22097e81dc54c895ed411c74c1829721e3a1ce5e (patch)
tree8cc9ca6d8bb0432b9562fc19636eca3421b21100 /host/lib/utils/msg.cpp
parent13be023531fa1be8d43b999c3ea5ab477f101fdc (diff)
parentea5ce50a465e714c63196f52df97fb3e927e701c (diff)
downloaduhd-22097e81dc54c895ed411c74c1829721e3a1ce5e.tar.gz
uhd-22097e81dc54c895ed411c74c1829721e3a1ce5e.tar.bz2
uhd-22097e81dc54c895ed411c74c1829721e3a1ce5e.zip
Merge branch 'master' into release_work
Diffstat (limited to 'host/lib/utils/msg.cpp')
-rw-r--r--host/lib/utils/msg.cpp32
1 files changed, 18 insertions, 14 deletions
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;
}