From: Colin Patrick McCabe Date: Tue, 14 Dec 2010 14:56:27 +0000 (-0800) Subject: logging: use Mutex::Locker X-Git-Tag: v0.25~457 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3e076c397a4082e1eda6d29a7af8d154b9133f35;p=ceph.git logging: use Mutex::Locker Use Mutex::Locker to make logging exception-safe. That is, if you are doing "dout() << foo() << dendl;" and foo throws an exception, the dout mutex will not be left in a locked state. Signed-off-by: Colin McCabe --- diff --git a/src/common/debug.h b/src/common/debug.h index af6fe9957e1b..9c33e4c500fb 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -36,7 +36,6 @@ extern int dout_handle_daemonize(); extern int dout_create_rank_symlink(int n); static inline void _dout_begin_line(int prio) { - _dout_lock.Lock(); if (unlikely(_dout_need_open)) _dout_open_log(); @@ -49,10 +48,6 @@ static inline void _dout_begin_line(int prio) { << std::dec << " "; } -static inline void _dout_end_line() { - _dout_lock.Unlock(); -} - // intentionally conflict with endl class _bad_endl_use_dendl_t { public: _bad_endl_use_dendl_t(int) {} }; static const _bad_endl_use_dendl_t endl = 0; @@ -75,9 +70,11 @@ inline std::ostream& operator<<(std::ostream& out, _bad_endl_use_dendl_t) { #define DOUT_COND(l) l <= XDOUT_CONDVAR(DOUT_SUBSYS) #define dout(l) do { if (DOUT_COND(l)) {\ - _dout_begin_line(l); dout_prefix + Mutex::Locker _dout_locker(_dout_lock);\ + _dout_begin_line(l); \ + dout_prefix -#define dendl std::endl; _dout_end_line(); } } while (0) +#define dendl std::endl; } } while (0) extern void hex2str(const char *s, int len, char *buf, int dest_len);