From 373619264ef54e924c31509af5bee0c155978618 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Mon, 14 Feb 2011 05:56:52 -0800 Subject: [PATCH] dout: Convert _dout_lock to plain pthread_mutex_t Convert _dout_lock to plain pthread_mutex_t. This way, we don't have to depend on the order of global constructor initialization. It should also be slightly more efficient. The dout_lock was never subject to lockdep anyway, so that's not an issue. Signed-off-by: Colin McCabe --- src/common/DoutStreambuf.cc | 14 +++++++------- src/common/debug.cc | 8 ++------ src/common/debug.h | 6 +++--- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/common/DoutStreambuf.cc b/src/common/DoutStreambuf.cc index 9c60f0e745e05..b30d536d23154 100644 --- a/src/common/DoutStreambuf.cc +++ b/src/common/DoutStreambuf.cc @@ -38,7 +38,7 @@ extern DoutStreambuf *_doss; // TODO: get rid of this lock using thread-local storage -extern Mutex _dout_lock; +extern pthread_mutex_t _dout_lock; //////////////////////// Helper functions ////////////////////////// // Try a 0-byte write to a file descriptor to see if it open. @@ -241,14 +241,14 @@ DoutStreambuf::overflow(DoutStreambuf::int_type c) template void DoutStreambuf::handle_stderr_closed() { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here flags &= ~DOUTSB_FLAG_STDERR; } template void DoutStreambuf::read_global_config() { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here flags = 0; if (ofd != -1) { @@ -299,7 +299,7 @@ set_prio(int prio) template int DoutStreambuf::handle_pid_change() { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here if (!(flags & DOUTSB_FLAG_OFILE)) return 0; @@ -347,7 +347,7 @@ int DoutStreambuf::handle_pid_change() template int DoutStreambuf::create_rank_symlink(int n) { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here if (!(flags & DOUTSB_FLAG_OFILE)) return 0; @@ -372,7 +372,7 @@ int DoutStreambuf::create_rank_symlink(int n) template std::string DoutStreambuf::config_to_str() const { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here ostringstream oss; oss << "g_conf.log_to_stderr = " << g_conf.log_to_stderr << "\n"; oss << "g_conf.log_to_syslog = " << g_conf.log_to_syslog << "\n"; @@ -424,7 +424,7 @@ void DoutStreambuf::_clear_output_buffer() template std::string DoutStreambuf::_calculate_opath() const { - assert(_dout_lock.is_locked()); + // should hold the dout_lock here // If g_conf.log_file was specified, that takes the highest priority if (!empty(g_conf.log_file)) { diff --git a/src/common/debug.cc b/src/common/debug.cc index 4b1a81ae50c8a..b2d7f000f7770 100644 --- a/src/common/debug.cc +++ b/src/common/debug.cc @@ -15,19 +15,15 @@ bool _dout_need_open = true; /* * The dout lock protects calls to dout() - * - * By using an early init_priority, we ensure that the dout lock is - * initialized first and destroyed last. */ -Mutex _dout_lock __attribute__((init_priority(110))) - ("_dout_lock", false, false /* no lockdep */); +pthread_mutex_t _dout_lock = PTHREAD_MUTEX_INITIALIZER; #define _STR(x) #x #define STRINGIFY(x) _STR(x) void _dout_open_log(bool print_version) { - assert(_dout_lock.is_locked()); + // should hold _dout_lock here if (!_doss) { _doss = new DoutStreambuf (); diff --git a/src/common/debug.h b/src/common/debug.h index 8f098bf87bd2f..ecca170b1e5b8 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -26,7 +26,7 @@ extern std::ostream *_dout; extern DoutStreambuf *_doss; extern bool _dout_need_open; -extern Mutex _dout_lock; +extern pthread_mutex_t _dout_lock; extern void _dout_open_log(bool print_version); @@ -38,10 +38,10 @@ class DoutLocker { public: DoutLocker() { - _dout_lock.Lock(); + pthread_mutex_lock(&_dout_lock); } ~DoutLocker() { - _dout_lock.Unlock(); + pthread_mutex_unlock(&_dout_lock); } }; -- 2.39.5