From: Sage Weil Date: Fri, 12 Sep 2014 22:24:50 +0000 (-0700) Subject: log: add Log::is_inside_log_lock() X-Git-Tag: v0.86~81^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=558463e815b7485d3424f9bf8bf96d5ff81afeb9;p=ceph.git log: add Log::is_inside_log_lock() Signed-off-by: Sage Weil --- diff --git a/src/log/Log.cc b/src/log/Log.cc index 39fd8c407440..8da77ef8b77e 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -37,6 +37,8 @@ static void log_on_exit(void *p) Log::Log(SubsystemMap *s) : m_indirect_this(NULL), m_subs(s), + m_queue_mutex_holder(0), + m_flush_mutex_holder(0), m_new(), m_recent(), m_fd(-1), m_syslog_log(-2), m_syslog_crash(-2), @@ -141,6 +143,7 @@ void Log::set_stderr_level(int log, int crash) void Log::submit_entry(Entry *e) { pthread_mutex_lock(&m_queue_mutex); + m_queue_mutex_holder = pthread_self(); // wait for flush to catch up while (m_new.m_len > m_max_new) @@ -148,6 +151,7 @@ void Log::submit_entry(Entry *e) m_new.enqueue(e); pthread_cond_signal(&m_cond_flusher); + m_queue_mutex_holder = 0; pthread_mutex_unlock(&m_queue_mutex); } @@ -171,10 +175,13 @@ Entry *Log::create_entry(int level, int subsys) void Log::flush() { pthread_mutex_lock(&m_flush_mutex); + m_flush_mutex_holder = pthread_self(); pthread_mutex_lock(&m_queue_mutex); + m_queue_mutex_holder = pthread_self(); EntryQueue t; t.swap(m_new); pthread_cond_broadcast(&m_cond_loggers); + m_queue_mutex_holder = 0; pthread_mutex_unlock(&m_queue_mutex); _flush(&t, &m_recent, false); @@ -183,6 +190,7 @@ void Log::flush() delete m_recent.dequeue(); } + m_flush_mutex_holder = 0; pthread_mutex_unlock(&m_flush_mutex); } @@ -254,10 +262,15 @@ void Log::_log_message(const char *s, bool crash) void Log::dump_recent() { pthread_mutex_lock(&m_flush_mutex); + m_flush_mutex_holder = pthread_self(); pthread_mutex_lock(&m_queue_mutex); + m_queue_mutex_holder = pthread_self(); + EntryQueue t; t.swap(m_new); + + m_queue_mutex_holder = 0; pthread_mutex_unlock(&m_queue_mutex); _flush(&t, &m_recent, false); @@ -287,6 +300,7 @@ void Log::dump_recent() _log_message("--- end dump of recent events ---", true); + m_flush_mutex_holder = 0; pthread_mutex_unlock(&m_flush_mutex); } @@ -313,20 +327,31 @@ void Log::stop() void *Log::entry() { pthread_mutex_lock(&m_queue_mutex); + m_queue_mutex_holder = pthread_self(); while (!m_stop) { if (!m_new.empty()) { + m_queue_mutex_holder = 0; pthread_mutex_unlock(&m_queue_mutex); flush(); pthread_mutex_lock(&m_queue_mutex); + m_queue_mutex_holder = pthread_self(); continue; } pthread_cond_wait(&m_cond_flusher, &m_queue_mutex); } + m_queue_mutex_holder = 0; pthread_mutex_unlock(&m_queue_mutex); flush(); return NULL; } +bool Log::is_inside_log_lock() +{ + return + pthread_self() == m_queue_mutex_holder || + pthread_self() == m_flush_mutex_holder; +} + } // ceph::log:: } // ceph:: diff --git a/src/log/Log.h b/src/log/Log.h index b5e16fdde793..b77be87e82e4 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -26,6 +26,9 @@ class Log : private Thread pthread_cond_t m_cond_loggers; pthread_cond_t m_cond_flusher; + pthread_t m_queue_mutex_holder; + pthread_t m_flush_mutex_holder; + EntryQueue m_new; ///< new entries EntryQueue m_recent; ///< recent (less new) entries we've already written at low detail @@ -68,6 +71,9 @@ public: void start(); void stop(); + + /// true if the log lock is held by our thread + bool is_inside_log_lock(); }; }