aboutsummaryrefslogtreecommitdiff
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)
downloadmessenger-gtk-c10387490c9fb7eac8d14076b12eb5971721bb90.tar.gz
messenger-gtk-c10387490c9fb7eac8d14076b12eb5971721bb90.zip
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,
77 app->chat.tid = 0; 77 app->chat.tid = 0;
78 app->chat.signal = MESSENGER_NONE; 78 app->chat.signal = MESSENGER_NONE;
79 79
80 pthread_mutex_init(&(app->chat.mutex), NULL);
81
80 app->ui.mobile = FALSE; 82 app->ui.mobile = FALSE;
81 83
82 app->ui.bindings = g_hash_table_new(g_direct_hash, g_direct_equal); 84 app->ui.bindings = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -159,6 +161,8 @@ application_run(MESSENGER_Application *app)
159 161
160 g_hash_table_destroy(app->ui.bindings); 162 g_hash_table_destroy(app->ui.bindings);
161 163
164 pthread_mutex_destroy(&(app->chat.mutex));
165
162 notify_uninit(); 166 notify_uninit();
163 167
164 g_object_unref(app->application); 168 g_object_unref(app->application);
@@ -213,7 +217,10 @@ _application_message_event_call(gpointer user_data)
213 MESSENGER_ApplicationMessageEventCall *call; 217 MESSENGER_ApplicationMessageEventCall *call;
214 218
215 call = (MESSENGER_ApplicationMessageEventCall*) user_data; 219 call = (MESSENGER_ApplicationMessageEventCall*) user_data;
220
221 pthread_mutex_lock(&(call->app->chat.mutex));
216 call->event(call->app, call->context, call->message); 222 call->event(call->app, call->context, call->message);
223 pthread_mutex_unlock(&(call->app->chat.mutex));
217 224
218 GNUNET_free(call); 225 GNUNET_free(call);
219 return FALSE; 226 return FALSE;
@@ -227,6 +234,9 @@ application_call_message_event(MESSENGER_Application *app,
227{ 234{
228 MESSENGER_ApplicationMessageEventCall *call; 235 MESSENGER_ApplicationMessageEventCall *call;
229 236
237 if (!event)
238 return;
239
230 call = (MESSENGER_ApplicationMessageEventCall*) GNUNET_malloc( 240 call = (MESSENGER_ApplicationMessageEventCall*) GNUNET_malloc(
231 sizeof(MESSENGER_ApplicationMessageEventCall) 241 sizeof(MESSENGER_ApplicationMessageEventCall)
232 ); 242 );
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
62 char *identity; 62 char *identity;
63 63
64 MESSENGER_ApplicationSignal signal; 64 MESSENGER_ApplicationSignal signal;
65 pthread_mutex_t mutex;
65 66
66 CHAT_MESSENGER_Handle messenger; 67 CHAT_MESSENGER_Handle messenger;
67 } chat; 68 } 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,
74{ 74{
75 MESSENGER_Application *app = (MESSENGER_Application*) cls; 75 MESSENGER_Application *app = (MESSENGER_Application*) cls;
76 76
77 pthread_mutex_lock(&(app->chat.mutex));
78
77 const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message); 79 const enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(message);
78 const struct GNUNET_CHAT_Contact* sender = GNUNET_CHAT_message_get_sender(message); 80 const struct GNUNET_CHAT_Contact* sender = GNUNET_CHAT_message_get_sender(message);
79 81
@@ -157,6 +159,8 @@ _chat_messenger_message(void *cls,
157 break; 159 break;
158 } 160 }
159 161
162 pthread_mutex_unlock(&(app->chat.mutex));
163
160 return GNUNET_YES; 164 return GNUNET_YES;
161} 165}
162 166