From db188f0ccf196a25c1343f19b45ba4940a34587e Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Mon, 14 Feb 2011 04:10:17 -0800 Subject: [PATCH] dout: use DoutLocker rather than Mutex::Locker Use DoutLocker rather than Mutex::Locker, in preparation for making the dout_lock a plain old pthread_mutex_t. Signed-off-by: Colin McCabe --- src/common/debug.cc | 4 ++-- src/common/debug.h | 13 ++++++++++++- src/config.cc | 2 +- src/test/TestDoutStreambuf.cc | 7 ++++--- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/common/debug.cc b/src/common/debug.cc index fe41cce42f6c9..4b1a81ae50c8a 100644 --- a/src/common/debug.cc +++ b/src/common/debug.cc @@ -46,7 +46,7 @@ void _dout_open_log(bool print_version) int dout_handle_daemonize() { - Mutex::Locker l(_dout_lock); + DoutLocker _dout_locker; if (_dout_need_open) _dout_open_log(true); @@ -58,7 +58,7 @@ int dout_handle_daemonize() int dout_create_rank_symlink(int n) { - Mutex::Locker l(_dout_lock); + DoutLocker _dout_locker; if (_dout_need_open) _dout_open_log(true); diff --git a/src/common/debug.h b/src/common/debug.h index cad7397339213..2768fdf179dff 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -34,6 +34,17 @@ extern int dout_handle_daemonize(); extern int dout_create_rank_symlink(int n); +class DoutLocker +{ +public: + DoutLocker() { + _dout_lock.Lock(); + } + ~DoutLocker() { + _dout_lock.Unlock(); + } +}; + static inline void _dout_begin_line(signed int prio) { if (unlikely(_dout_need_open)) _dout_open_log(true); @@ -66,7 +77,7 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) { if (0) {\ char __array[((v >= -1) && (v <= 200)) ? 0 : -1] __attribute__((unused)); \ }\ - Mutex::Locker _dout_locker(_dout_lock);\ + DoutLocker __dout_locker; \ _dout_begin_line(v); \ #define dout(v) \ diff --git a/src/config.cc b/src/config.cc index 9dea8f2403951..57adc8fabcfa2 100644 --- a/src/config.cc +++ b/src/config.cc @@ -1103,7 +1103,7 @@ void parse_startup_config_options(std::vector& args, // In the long term, it would be best to ensure that we read ceph.conf // before initializing dout(). For now, just force a reopen here with the // configuration we have just read. - Mutex::Locker l(_dout_lock); + DoutLocker _dout_locker; _dout_open_log(false); } diff --git a/src/test/TestDoutStreambuf.cc b/src/test/TestDoutStreambuf.cc index ca6f7c58c1337..769b9b9024b37 100644 --- a/src/test/TestDoutStreambuf.cc +++ b/src/test/TestDoutStreambuf.cc @@ -40,9 +40,10 @@ int main(int argc, const char **argv) DoutStreambuf *dos = new DoutStreambuf(); - _dout_lock.Lock(); - dos->read_global_config(); - _dout_lock.Unlock(); + { + DoutLocker _dout_locker; + dos->read_global_config(); + } derr << "using configuration: " << dos->config_to_str() << dendl; std::ostream oss(dos); -- 2.39.5