Skip to content

Commit

Permalink
Various fixes in RDP thread locking
Browse files Browse the repository at this point in the history
  • Loading branch information
giox069 committed Mar 5, 2016
1 parent a034884 commit 582bcf1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
27 changes: 22 additions & 5 deletions remmina-plugins/rdp/rdp_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ void remmina_rdp_event_init(RemminaProtocolWidget* gp)
rfi->pressed_keys = g_array_new(FALSE, TRUE, sizeof (DWORD));
rfi->event_queue = g_async_queue_new_full(g_free);
rfi->ui_queue = g_async_queue_new();
pthread_mutex_init(&rfi->ui_queue_mutex, NULL);

if (pipe(rfi->event_pipe))
{
Expand Down Expand Up @@ -736,6 +737,7 @@ void remmina_rdp_event_uninit(RemminaProtocolWidget* gp)
rfi->event_queue = NULL;
g_async_queue_unref(rfi->ui_queue);
rfi->ui_queue = NULL;
pthread_mutex_destroy(&rfi->ui_queue_mutex);

if (rfi->event_handle)
{
Expand Down Expand Up @@ -986,27 +988,33 @@ static gboolean remmina_rdp_event_process_ui_queue(RemminaProtocolWidget* gp)
rfContext* rfi = GET_PLUGIN_DATA(gp);
RemminaPluginRdpUiObject* ui;

pthread_mutex_lock(&rfi->ui_queue_mutex);
ui = (RemminaPluginRdpUiObject*) g_async_queue_try_pop(rfi->ui_queue);
if (ui)
{
pthread_mutex_lock(&ui->sync_wait_mutex);
if (!rfi->thread_cancelled)
{
remmina_rdp_event_process_ui_event(gp, ui);
}
// Should we signal the subthread to unlock ?
if (ui->sync) {
pthread_mutex_lock(&ui->sync_wait_mutex);

ui->complete = TRUE;
pthread_cond_signal(&ui->sync_wait_cond);
pthread_mutex_unlock(&ui->sync_wait_mutex);

} else {
remmina_rdp_event_free_event(gp, ui);
}

pthread_mutex_unlock(&rfi->ui_queue_mutex);

return TRUE;
}
else
{
pthread_mutex_unlock(&rfi->ui_queue_mutex);
rfi->ui_handler = 0;
return FALSE;
}
Expand All @@ -1017,6 +1025,7 @@ int remmina_rdp_event_queue_ui(RemminaProtocolWidget* gp, RemminaPluginRdpUiObje
TRACE_CALL("remmina_rdp_event_queue_ui");
rfContext* rfi = GET_PLUGIN_DATA(gp);
gboolean ui_sync_save;
int oldcanceltype;
int rc;

if (remmina_plugin_service->is_main_thread()) {
Expand All @@ -1027,20 +1036,24 @@ int remmina_rdp_event_queue_ui(RemminaProtocolWidget* gp, RemminaPluginRdpUiObje
return rc;
}


if (rfi->thread_cancelled) {
remmina_rdp_event_free_event(gp, ui);
return 0;
}

pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldcanceltype);
pthread_mutex_lock(&rfi->ui_queue_mutex);

ui_sync_save = ui->sync;
ui->complete = FALSE;

if (ui_sync_save) {
pthread_mutex_init(&ui->sync_wait_mutex,NULL);
pthread_cond_init(&ui->sync_wait_cond, NULL);
}

ui->complete = FALSE;

g_async_queue_push(rfi->ui_queue, ui);

if (!rfi->ui_handler)
Expand All @@ -1049,16 +1062,20 @@ int remmina_rdp_event_queue_ui(RemminaProtocolWidget* gp, RemminaPluginRdpUiObje
if (ui_sync_save) {
/* Wait for main thread function completion before returning */
pthread_mutex_lock(&ui->sync_wait_mutex);
pthread_mutex_unlock(&rfi->ui_queue_mutex);
while(!ui->complete) {
pthread_cond_wait(&ui->sync_wait_cond, &ui->sync_wait_mutex);
}
rc = ui->retval;
pthread_mutex_destroy(&ui->sync_wait_mutex);
pthread_cond_destroy(&ui->sync_wait_cond);
pthread_mutex_destroy(&ui->sync_wait_mutex);
remmina_rdp_event_free_event(gp, ui);
return rc;
} else {
pthread_mutex_unlock(&rfi->ui_queue_mutex);
rc = 0;
}
return 0;
pthread_setcanceltype(oldcanceltype, NULL);
return rc;
}


Expand Down
1 change: 1 addition & 0 deletions remmina-plugins/rdp/rdp_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ struct rf_context
GHashTable* object_table;

GAsyncQueue* ui_queue;
pthread_mutex_t ui_queue_mutex;
guint ui_handler;

GArray* pressed_keys;
Expand Down

0 comments on commit 582bcf1

Please sign in to comment.