messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

commit c10387490c9fb7eac8d14076b12eb5971721bb90
parent 35f830ec5f9ea6ff42d2c98e2a0efb40de3dd1f2
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Tue, 21 Dec 2021 00:51:45 +0100

Added mutex for thread safety

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/application.c | 10++++++++++
Msrc/application.h | 1+
Msrc/chat/messenger.c | 4++++
3 files changed, 15 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 @@ -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; }