]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
dout: Convert _dout_lock to plain pthread_mutex_t
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 14 Feb 2011 13:56:52 +0000 (05:56 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Mon, 14 Feb 2011 13:56:52 +0000 (05:56 -0800)
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 <colin.mccabe@dreamhost.com>
src/common/DoutStreambuf.cc
src/common/debug.cc
src/common/debug.h

index 9c60f0e745e05f653f9ff672f5079221ad1da731..b30d536d231549ddb8abc273d8a110c101bbd7e7 100644 (file)
@@ -38,7 +38,7 @@
 extern DoutStreambuf <char> *_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<charT, traits>::overflow(DoutStreambuf<charT, traits>::int_type c)
 template <typename charT, typename traits>
 void DoutStreambuf<charT, traits>::handle_stderr_closed()
 {
-  assert(_dout_lock.is_locked());
+  // should hold the dout_lock here
   flags &= ~DOUTSB_FLAG_STDERR;
 }
 
 template <typename charT, typename traits>
 void DoutStreambuf<charT, traits>::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 <typename charT, typename traits>
 int DoutStreambuf<charT, traits>::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<charT, traits>::handle_pid_change()
 template <typename charT, typename traits>
 int DoutStreambuf<charT, traits>::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<charT, traits>::create_rank_symlink(int n)
 template <typename charT, typename traits>
 std::string DoutStreambuf<charT, traits>::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<charT, traits>::_clear_output_buffer()
 template <typename charT, typename traits>
 std::string DoutStreambuf<charT, traits>::_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)) {
index 4b1a81ae50c8a4136556f7225be7ad8be0cb82ed..b2d7f000f7770d104e1f3ba74e840daaa2defbf3 100644 (file)
@@ -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 <char>();
index 8f098bf87bd2fe0c8fd1558e2cfb621470f7c1c8..ecca170b1e5b87860ce0e2bfd7a543a1fb862d39 100644 (file)
@@ -26,7 +26,7 @@
 extern std::ostream *_dout;
 extern DoutStreambuf <char> *_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);
   }
 };