Created
August 10, 2021 17:44
-
-
Save alfredh/060cad7a99ece09702dfc884120e7e84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main/main.c b/src/main/main.c | |
index 78a47e3..7858aa9 100644 | |
--- a/src/main/main.c | |
+++ b/src/main/main.c | |
@@ -115,6 +115,7 @@ struct re { | |
#ifdef HAVE_PTHREAD | |
pthread_mutex_t mutex; /**< Mutex for thread synchronization */ | |
pthread_mutex_t *mutexp; /**< Pointer to active mutex */ | |
+ pthread_t tid; | |
#endif | |
}; | |
@@ -145,12 +146,16 @@ static struct re global_re = { | |
PTHREAD_MUTEX_INITIALIZER, | |
#endif | |
&global_re.mutex, | |
+ 0 | |
#endif | |
}; | |
#ifdef HAVE_PTHREAD | |
+extern pthread_t re_thread_get(void); | |
+ | |
+ | |
static void poll_close(struct re *re); | |
static pthread_once_t pt_once = PTHREAD_ONCE_INIT; | |
@@ -181,6 +186,11 @@ static struct re *re_get(void) | |
re = &global_re; | |
} | |
+ if (!re->tid) { | |
+ re->tid = pthread_self(); | |
+ re_printf(" *** RE MAIN THREAD INITED: tid=%p\n", re->tid); | |
+ } | |
+ | |
return re; | |
} | |
@@ -599,6 +609,15 @@ int fd_listen(int fd, int flags, fd_h *fh, void *arg) | |
DEBUG_INFO("fd_listen: fd=%d flags=0x%02x\n", fd, flags); | |
+#ifdef HAVE_PTHREAD | |
+ if (!pthread_equal(pthread_self(), re_thread_get())) { | |
+ DEBUG_WARNING("fd_listen: called from a NON-RE thread" | |
+ " (fd=%d, flags=0x%x, handler=%p, arg=%p)\n", | |
+ fd, flags, fh, arg); | |
+ return EPERM; | |
+ } | |
+#endif | |
+ | |
if (fd < 0) { | |
DEBUG_WARNING("fd_listen: corrupt fd %d\n", fd); | |
return EBADF; | |
@@ -1259,3 +1278,11 @@ struct list *tmrl_get(void) | |
{ | |
return &re_get()->tmrl; | |
} | |
+ | |
+ | |
+#ifdef HAVE_PTHREAD | |
+pthread_t re_thread_get(void) | |
+{ | |
+ return re_get()->tid; | |
+} | |
+#endif | |
diff --git a/src/tmr/tmr.c b/src/tmr/tmr.c | |
index 5e9022c..a6ce86c 100644 | |
--- a/src/tmr/tmr.c | |
+++ b/src/tmr/tmr.c | |
@@ -268,6 +268,11 @@ void tmr_init(struct tmr *tmr) | |
} | |
+#ifdef HAVE_PTHREAD | |
+ extern pthread_t re_thread_get(void); | |
+#endif | |
+ | |
+ | |
/** | |
* Start a timer | |
* | |
@@ -284,6 +289,16 @@ void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg) | |
if (!tmr) | |
return; | |
+#ifdef HAVE_PTHREAD | |
+ | |
+ if (!pthread_equal(pthread_self(), re_thread_get())) { | |
+ DEBUG_WARNING("tmr_start: called from a NON-RE thread" | |
+ " (tmr=%p, delay=%llu, handler=%p, arg=%p)\n", | |
+ tmr, delay, th, arg); | |
+ BREAKPOINT; | |
+ } | |
+#endif | |
+ | |
if (tmr->th) { | |
list_unlink(&tmr->le); | |
} |
juha-h
commented
Jun 6, 2022
via email
Sebastian Reimers writes:
Ok you can give this PR a try: baresip/re#389
Tried and the delay is still there. Now I started to get lots of these:
06-06 18:42:51.712 16953 17131 D Baresip Lib: main: thread check: called from a NON-RE thread without thread_enter()!
They disappeared when I added re_thread_enter()/leave() around this call:
JNIEXPORT void JNICALL
Java_com_tutpro_baresip_Api_net_1debug(JNIEnv *env, jobject thiz)
{
re_thread_enter();
net_debug_log();
re_thread_leave();
}
But as I wrote, the long delay when I make calls, is still there even
after fixing net_debug.
I noticed also, that sometimes explicit registering has long delay:
06-06 18:56:45.448 17867 17867 D Baresip Lib: ua event (REGISTERING)
06-06 18:57:08.284 17867 18041 D Baresip Lib: ***@***.***: (prio 0) {1/TLS/v4} 200 OK (OpenSIPg SIP Proxy (5.6.0-0b31 (x86_64/linux))) [1 binding]
06-06 18:57:08.286 17867 18040 D Baresip Lib: ua event (REGISTER_OK) 200 OK
It too needs to resolve outbound address.
…-- Juha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment