]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
logging: use Mutex::Locker
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 14 Dec 2010 14:56:27 +0000 (06:56 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 14 Dec 2010 14:56:27 +0000 (06:56 -0800)
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 <colinm@hq.newdream.net>
src/common/debug.h

index af6fe9957e1b5241336efb3d067d37ab2528a727..9c33e4c500fbf7e47306f8421e8cca3b981e579e 100644 (file)
@@ -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);