Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [lttng-dev] [PATCH lttng-ust] Ignore unexpected old state when nesting ust_mutex in the same thread
@ 2019-05-28 16:18 Gabriel-Andrew Pollo-Guilbert
  0 siblings, 0 replies; only message in thread
From: Gabriel-Andrew Pollo-Guilbert @ 2019-05-28 16:18 UTC (permalink / raw)


We allow the ust_mutex lock to be nested within the same thread using the
ust_mutex_nest counter. When calling ust_lock(), ust_lock_nocheck() or
ust_unlock() twice or more in the same thread would result in an error
message being thrown.

This error message always appear when an application calls fork(3) (with
liblttng-ust-fork preloaded), the thread would lock before the fork(3) in
ust_before_fork() and the child would lock again during lttng_after_fork_child().

Signed-off-by: Gabriel-Andrew Pollo-Guilbert <gabriel.pollo-guilbert at efficios.com>
---
 liblttng-ust/lttng-ust-comm.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c
index 61dbb41b..a6449bbc 100644
--- a/liblttng-ust/lttng-ust-comm.c
+++ b/liblttng-ust/lttng-ust-comm.c
@@ -135,7 +135,9 @@ int ust_lock(void)
 		ERR("pthread_setcancelstate: %s", strerror(ret));
 	}
 	if (oldstate != PTHREAD_CANCEL_ENABLE) {
-		ERR("pthread_setcancelstate: unexpected oldstate");
+		if (!URCU_TLS(ust_mutex_nest)) {
+			ERR("pthread_setcancelstate: unexpected oldstate");
+		}
 	}
 	sigfillset(&sig_all_blocked);
 	ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
@@ -171,7 +173,9 @@ void ust_lock_nocheck(void)
 		ERR("pthread_setcancelstate: %s", strerror(ret));
 	}
 	if (oldstate != PTHREAD_CANCEL_ENABLE) {
-		ERR("pthread_setcancelstate: unexpected oldstate");
+		if (!URCU_TLS(ust_mutex_nest)) {
+			ERR("pthread_setcancelstate: unexpected oldstate");
+		}
 	}
 	sigfillset(&sig_all_blocked);
 	ret = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_mask);
@@ -210,7 +214,9 @@ void ust_unlock(void)
 		ERR("pthread_setcancelstate: %s", strerror(ret));
 	}
 	if (oldstate != PTHREAD_CANCEL_DISABLE) {
-		ERR("pthread_setcancelstate: unexpected oldstate");
+		if (URCU_TLS(ust_mutex_nest)) {
+			ERR("pthread_setcancelstate: unexpected oldstate");
+		}
 	}
 }
 
-- 
2.21.0



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-28 16:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 16:18 [lttng-dev] [PATCH lttng-ust] Ignore unexpected old state when nesting ust_mutex in the same thread Gabriel-Andrew Pollo-Guilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox