summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-21 00:51:45 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-21 00:51:45 +0100
commitc10387490c9fb7eac8d14076b12eb5971721bb90 (patch)
treec1eccd6da2a0a3598fedb0a613fdd05071de3943
parent35f830ec5f9ea6ff42d2c98e2a0efb40de3dd1f2 (diff)
Added mutex for thread safety
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/application.c10
-rw-r--r--src/application.h1
-rw-r--r--src/chat/messenger.c4
3 files changed, 15 insertions, 0 deletions
diff --git a/src/application.c b/src/application.c
index 2062b82..24b6490 100644
--- a/src/application.c
+++ b/src/application.c
@@ -77,6 +77,8 @@ application_init(MESSENGER_Application *app,
app->chat.tid = 0;
app->chat.signal = MESSENGER_NONE;
+ pthread_mutex_init(&(app->chat.mutex), NULL);
+
app->ui.mobile = FALSE;
app->ui.bindings = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -159,6 +161,8 @@ application_run(MESSENGER_Application *app)
g_hash_table_destroy(app->ui.bindings);
+ pthread_mutex_destroy(&(app->chat.mutex));
+
notify_uninit();
g_object_unref(app->application);
@@ -213,7 +217,10 @@ _application_message_event_call(gpointer user_data)
MESSENGER_ApplicationMessageEventCall *call;
call = (MESSENGER_ApplicationMessageEventCall*) user_data;
+
+ pthread_mutex_lock(&(call->app->chat.mutex));
call->event(call->app, call->context, call->message);
+ pthread_mutex_unlock(&(call->app->chat.mutex));
GNUNET_free(call);
return FALSE;
@@ -227,6 +234,9 @@ application_call_message_event(MESSENGER_Application *app,
{
MESSENGER_ApplicationMessageEventCall *call;
+ if (!event)
+ return;
+
call = (MESSENGER_ApplicationMessageEventCall*) GNUNET_malloc(
sizeof(MESSENGER_ApplicationMessageEventCall)
);
diff --git a/src/application.h b/src/application.h
index 2e18f64..825b140 100644
--- a/src/application.h
+++ b/src/application.h
@@ -62,6 +62,7 @@ typedef struct MESSENGER_Application
char *identity;
MESSENGER_ApplicationSignal signal;
+ pthread_mutex_t mutex;
CHAT_MESSENGER_Handle messenger;
} chat;
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index c0f16be..c7eb033 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -74,6 +74,8 @@ _chat_messenger_message(void *cls,
{
MESSENGER_Application *app = (MESSENGER_Application*) cls;
+ pthread_mutex_lock(&(app->chat.mutex));
+
const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
const struct GNUNET_CHAT_Contact* sender = GNUNET_CHAT_message_get_sender(message);
@@ -157,6 +159,8 @@ _chat_messenger_message(void *cls,
break;
}
+ pthread_mutex_unlock(&(app->chat.mutex));
+
return GNUNET_YES;
}