From 509b6722eb9bde7a0e4f8e9c2221e8a5ae0a6db7 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 22 Jun 2022 12:21:40 +0300 Subject: [PATCH] Re-introduced modified mqueue usage for ua_stop_all --- app/src/main/cpp/baresip.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 6264b87c..0bc7d00e 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -364,6 +364,16 @@ enum { ID_UA_STOP_ALL }; +static struct mqueue *mq; + +static void mqueue_handler(int id, void *data, void *arg) +{ + if (id == ID_UA_STOP_ALL) { + LOGD("calling ua_stop_all with force %u\n", (unsigned)(uintptr_t)data); + ua_stop_all((bool)(uintptr_t)data); + } +} + #include static int pfd[2]; @@ -521,6 +531,13 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc goto out; } + err = mqueue_alloc(&mq, mqueue_handler, NULL); + if (err) { + LOGW("mqueue_alloc failed (%d)\n", err); + strcpy(start_error, "mqueue_alloc"); + goto out; + } + jmethodID startedId = (*env)->GetMethodID(env, g_ctx.mainActivityClz, "started", "()V"); (*env)->CallVoidMethod(env, g_ctx.mainActivityObj, startedId); @@ -536,6 +553,8 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc LOGI("main loop exit\n"); } + mq = mem_deref(mq); + LOGD("closing ..."); ua_close(); module_app_unload(); @@ -566,9 +585,7 @@ JNIEXPORT void JNICALL Java_com_tutpro_baresip_BaresipService_baresipStop(JNIEnv *env, jobject thiz, jboolean force) { LOGD("ua_stop_all upon baresipStop"); - re_thread_enter(); - ua_stop_all(force); - re_thread_leave(); + mqueue_push(mq, ID_UA_STOP_ALL, (void *)((long)force)); } JNIEXPORT jstring JNICALL