diff mbox

[05/12] libmultipath: fix log_pthread processing

Message ID 1521049605-22050-6-git-send-email-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show

Commit Message

Benjamin Marzinski March 14, 2018, 5:46 p.m. UTC
log_pthread() was waiting for notification on logev_cond, without
checking if it had already happened.  This means it could end up
waiting, while there is work that it should be doing.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/log_pthread.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Martin Wilck March 19, 2018, 10:22 a.m. UTC | #1
On Wed, 2018-03-14 at 12:46 -0500, Benjamin Marzinski wrote:
> log_pthread() was waiting for notification on logev_cond, without
> checking if it had already happened.  This means it could end up
> waiting, while there is work that it should be doing.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>
diff mbox

Patch

diff --git a/libmultipath/log_pthread.c b/libmultipath/log_pthread.c
index f491386..bb35dfc 100644
--- a/libmultipath/log_pthread.c
+++ b/libmultipath/log_pthread.c
@@ -21,6 +21,7 @@  static pthread_mutex_t logev_lock;
 static pthread_cond_t logev_cond;
 
 static int logq_running;
+static int log_messages_pending;
 
 void log_safe (int prio, const char * fmt, va_list ap)
 {
@@ -34,6 +35,7 @@  void log_safe (int prio, const char * fmt, va_list ap)
 	pthread_mutex_unlock(&logq_lock);
 
 	pthread_mutex_lock(&logev_lock);
+	log_messages_pending = 1;
 	pthread_cond_signal(&logev_cond);
 	pthread_mutex_unlock(&logev_lock);
 }
@@ -64,7 +66,9 @@  static void * log_thread (void * et)
 
 	while (1) {
 		pthread_mutex_lock(&logev_lock);
-		pthread_cond_wait(&logev_cond, &logev_lock);
+		if (logq_running && !log_messages_pending)
+			pthread_cond_wait(&logev_cond, &logev_lock);
+		log_messages_pending = 0;
 		running = logq_running;
 		pthread_mutex_unlock(&logev_lock);
 		if (!running)