[Asterisk-code-review] channel.c: Make CHECK BLOCKING() save thread LWP id for mess... (asterisk[master])

George Joseph asteriskteam at digium.com
Thu Jun 21 10:26:33 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/9223 )

Change subject: channel.c: Make CHECK_BLOCKING() save thread LWP id for messages.
......................................................................

channel.c: Make CHECK_BLOCKING() save thread LWP id for messages.

* Removed an unnecessary call to ast_channel_blocker_set() in
__ast_read().

ASTERISK-27625

Change-Id: I342168b999984666fb869cd519fe779583a73834
---
M include/asterisk/channel.h
M main/channel.c
M main/channel_internal_api.c
3 files changed, 21 insertions(+), 8 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  Sean Bright: Looks good to me, approved
  George Joseph: Approved for Submit



diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 79a1477..3f22cdd 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -2725,11 +2725,12 @@
 	do { \
 		if (ast_test_flag(ast_channel_flags(c), AST_FLAG_BLOCKING)) { \
 			/* This should not happen as there should only be one thread handling a channel's media at a time. */ \
-			ast_log(LOG_DEBUG, "Thread %p is blocking '%s', already blocked by thread %p in procedure %s\n", \
-				(void *) pthread_self(), ast_channel_name(c), \
-				(void *) ast_channel_blocker(c), ast_channel_blockproc(c)); \
+			ast_log(LOG_DEBUG, "Thread LWP %d is blocking '%s', already blocked by thread LWP %d in procedure %s\n", \
+				ast_get_tid(), ast_channel_name(c), \
+				ast_channel_blocker_tid(c), ast_channel_blockproc(c)); \
 			ast_assert(0); \
 		} \
+		ast_channel_blocker_tid_set((c), ast_get_tid()); \
 		ast_channel_blocker_set((c), pthread_self()); \
 		ast_channel_blockproc_set((c), __PRETTY_FUNCTION__); \
 		ast_set_flag(ast_channel_flags(c), AST_FLAG_BLOCKING); \
@@ -4369,6 +4370,9 @@
 pthread_t ast_channel_blocker(const struct ast_channel *chan);
 void ast_channel_blocker_set(struct ast_channel *chan, pthread_t value);
 
+int ast_channel_blocker_tid(const struct ast_channel *chan);
+void ast_channel_blocker_tid_set(struct ast_channel *chan, int tid);
+
 ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan);
 void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value);
 
diff --git a/main/channel.c b/main/channel.c
index d92de81..c4b63c6 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -2618,10 +2618,10 @@
 	ast_channel_generator_set(chan, NULL);
 
 	if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING)) {
-		ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
-			"is blocked by thread %ld in procedure %s!  Expect a failure\n",
-			(long) pthread_self(), ast_channel_name(chan), (long)ast_channel_blocker(chan), ast_channel_blockproc(chan));
-		ast_assert(ast_test_flag(ast_channel_flags(chan), AST_FLAG_BLOCKING) == 0);
+		ast_log(LOG_WARNING, "Hard hangup called by thread LWP %d on %s, while blocked by thread LWP %d in procedure %s!  Expect a failure\n",
+			ast_get_tid(), ast_channel_name(chan), ast_channel_blocker_tid(chan),
+			ast_channel_blockproc(chan));
+		ast_assert(0);
 	}
 
 	if (ast_channel_tech(chan)->hangup) {
@@ -3661,7 +3661,6 @@
 			}
 		}
 	} else {
-		ast_channel_blocker_set(chan, pthread_self());
 		if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_EXCEPTION)) {
 			if (ast_channel_tech(chan)->exception)
 				f = ast_channel_tech(chan)->exception(chan);
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index d31ce94..b926514 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -165,6 +165,7 @@
 	unsigned long insmpl;				/*!< Track the read/written samples for monitor use */
 	unsigned long outsmpl;				/*!< Track the read/written samples for monitor use */
 
+	int blocker_tid;					/*!< If anyone is blocking, this is their thread id */
 	AST_VECTOR(, int) fds;				/*!< File descriptors for channel -- Drivers will poll on
 							 *   these file descriptors, so at least one must be non -1.
 							 *   See \arg \ref AstFileDesc */
@@ -1178,6 +1179,15 @@
 	chan->blocker = value;
 }
 
+int ast_channel_blocker_tid(const struct ast_channel *chan)
+{
+	return chan->blocker_tid;
+}
+void ast_channel_blocker_tid_set(struct ast_channel *chan, int value)
+{
+	chan->blocker_tid = value;
+}
+
 ast_timing_func_t ast_channel_timingfunc(const struct ast_channel *chan)
 {
 	return chan->timingfunc;

-- 
To view, visit https://gerrit.asterisk.org/9223
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I342168b999984666fb869cd519fe779583a73834
Gerrit-Change-Number: 9223
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180621/41e77591/attachment.html>


More information about the asterisk-code-review mailing list