Exclude simultaneous access to the terminal structure by the input and output threads.

This commit is contained in:
Michael Jumper 2013-04-07 16:55:06 -07:00
parent 43f42cbb4c
commit 342824914a
3 changed files with 21 additions and 0 deletions

View File

@ -39,6 +39,7 @@
#define _SSH_GUAC_TERMINAL_H
#include <stdbool.h>
#include <pthread.h>
#include <pango/pangocairo.h>
@ -303,6 +304,12 @@ struct guac_terminal {
*/
guac_client* client;
/**
* Lock which restricts simultaneous access to this terminal via the root
* guac_terminal_* functions.
*/
pthread_mutex_t lock;
/**
* The description of the font to use for rendering.
*/

View File

@ -85,6 +85,9 @@ int ssh_guac_client_handle_messages(guac_client* client) {
int bytes_read = 0;
/* Lock terminal access */
pthread_mutex_lock(&(client_data->term->lock));
/* Clear cursor */
guac_terminal_toggle_reverse(client_data->term,
client_data->term->cursor_row,
@ -116,6 +119,9 @@ int ssh_guac_client_handle_messages(guac_client* client) {
/* Flush terminal delta */
guac_terminal_delta_flush(client_data->term->delta, client_data->term);
/* Unlock terminal access */
pthread_mutex_unlock(&(client_data->term->lock));
}
return 0;
@ -157,12 +163,16 @@ int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
/* Scroll up if wheel moved up */
if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_UP) {
pthread_mutex_lock(&(term->lock));
guac_terminal_scroll_display_up(term);
pthread_mutex_unlock(&(term->lock));
}
/* Scroll down if wheel moved down */
if (released_mask & GUAC_CLIENT_MOUSE_SCROLL_DOWN) {
pthread_mutex_lock(&(term->lock));
guac_terminal_scroll_display_down(term);
pthread_mutex_unlock(&(term->lock));
}
return 0;

View File

@ -38,6 +38,7 @@
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <cairo/cairo.h>
#include <pango/pangocairo.h>
@ -156,6 +157,9 @@ guac_terminal* guac_terminal_create(guac_client* client,
guac_terminal_clear(term,
0, 0, term->term_height, term->term_width);
/* Init terminal lock */
pthread_mutex_init(&(term->lock), NULL);
return term;
}