diff options
author | Josh Blum <josh@joshknows.com> | 2011-05-04 17:01:41 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-05-04 17:01:41 -0700 |
commit | e71d2833fbc2d9b87a8367b6ddc4388c3f182d93 (patch) | |
tree | 755fbb70455f350db85088fc4ca2f28e647c799c /host/lib/utils/log.cpp | |
parent | c8dca30d72eb733d154ab9dd193631c42b8e4788 (diff) | |
download | uhd-e71d2833fbc2d9b87a8367b6ddc4388c3f182d93.tar.gz uhd-e71d2833fbc2d9b87a8367b6ddc4388c3f182d93.tar.bz2 uhd-e71d2833fbc2d9b87a8367b6ddc4388c3f182d93.zip |
uhd: added interprocess file lock to the logger file
Diffstat (limited to 'host/lib/utils/log.cpp')
-rw-r--r-- | host/lib/utils/log.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index 061173d6b..0a2861cbd 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -22,6 +22,19 @@ #include <boost/thread/mutex.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #ifdef BOOST_MSVC +//whoops! https://svn.boost.org/trac/boost/ticket/5287 +//enjoy this useless dummy class instead +namespace boost{ namespace interprocess{ + struct file_lock{ + file_lock(const char * = NULL){} + void lock(void){} + void unlock(void){} + }; +}} //namespace +#else +#include <boost/interprocess/sync/file_lock.hpp> +#endif +#ifdef BOOST_MSVC #define USE_GET_TEMP_PATH #include <Windows.h> //GetTempPath #endif @@ -32,6 +45,7 @@ namespace fs = boost::filesystem; namespace pt = boost::posix_time; +namespace ip = boost::interprocess; /*********************************************************************** * Helper function to get the system's temporary path @@ -82,6 +96,7 @@ public: uhd_logger_stream_resource_class(void) : _null_stream(&null_streambuf()){ const std::string log_path = (get_temp_path() / "uhd.log").string(); _file_stream.open(log_path.c_str(), std::fstream::out | std::fstream::app); + _file_lock = ip::file_lock(log_path.c_str()); //set the default log level _log_level = uhd::_log::regularly; @@ -107,8 +122,14 @@ public: } void aquire(bool lock){ - if (lock) _mutex.lock(); - else _mutex.unlock(); + if (lock){ + _mutex.lock(); + _file_lock.lock(); + } + else{ + _file_lock.unlock(); + _mutex.unlock(); + } } void set_verbosity(uhd::_log::verbosity_t verbosity){ @@ -130,9 +151,15 @@ private: if_lls_equal(very_rarely); } + //available stream objects std::ofstream _file_stream; std::ostream _null_stream; - boost::mutex _mutex; + + //synchronization mechanisms + boost::mutex _mutex; //process-level + ip::file_lock _file_lock; //system-level + + //log-level settings uhd::_log::verbosity_t _verbosity; uhd::_log::verbosity_t _log_level; }; |