Remove unnecessary update lock, use threadsafe socket instead.

This commit is contained in:
Michael Jumper 2013-06-28 17:45:47 -07:00
parent 90697e35ba
commit a08180acfe
9 changed files with 7 additions and 69 deletions

View File

@ -88,8 +88,6 @@ void audio_stream_end(audio_stream* audio) {
double duration; double duration;
rdp_guac_client_data* data = (rdp_guac_client_data*) audio->client->data;
/* Flush stream and finish encoding */ /* Flush stream and finish encoding */
audio_stream_flush(audio); audio_stream_flush(audio);
audio->encoder->end_handler(audio); audio->encoder->end_handler(audio);
@ -98,15 +96,11 @@ void audio_stream_end(audio_stream* audio) {
duration = ((double) (audio->pcm_bytes_written * 1000 * 8)) duration = ((double) (audio->pcm_bytes_written * 1000 * 8))
/ audio->rate / audio->channels / audio->bps; / audio->rate / audio->channels / audio->bps;
pthread_mutex_lock(&(data->update_lock));
/* Send audio */ /* Send audio */
guac_protocol_send_audio(audio->stream->socket, guac_protocol_send_audio(audio->stream->socket,
0, audio->encoder->mimetype, 0, audio->encoder->mimetype,
duration, audio->encoded_data, audio->encoded_data_used); duration, audio->encoded_data, audio->encoded_data_used);
pthread_mutex_unlock(&(data->update_lock));
/* Clear data */ /* Clear data */
audio->encoded_data_used = 0; audio->encoded_data_used = 0;

View File

@ -522,15 +522,14 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_client_data->clipboard = NULL; guac_client_data->clipboard = NULL;
guac_client_data->audio = NULL; guac_client_data->audio = NULL;
/* Main socket needs to be threadsafe */
guac_socket_require_threadsafe(client->socket);
/* Recursive attribute for locks */ /* Recursive attribute for locks */
pthread_mutexattr_init(&(guac_client_data->attributes)); pthread_mutexattr_init(&(guac_client_data->attributes));
pthread_mutexattr_settype(&(guac_client_data->attributes), pthread_mutexattr_settype(&(guac_client_data->attributes),
PTHREAD_MUTEX_RECURSIVE); PTHREAD_MUTEX_RECURSIVE);
/* Init update lock */
pthread_mutex_init(&(guac_client_data->update_lock),
&(guac_client_data->attributes));
/* Init RDP lock */ /* Init RDP lock */
pthread_mutex_init(&(guac_client_data->rdp_lock), pthread_mutex_init(&(guac_client_data->rdp_lock),
&(guac_client_data->attributes)); &(guac_client_data->attributes));

View File

@ -186,11 +186,6 @@ typedef struct rdp_guac_client_data {
*/ */
audio_stream* audio; audio_stream* audio;
/**
* Lock which is locked and unlocked for each update.
*/
pthread_mutex_t update_lock;
/** /**
* Lock which is locked and unlocked for each RDP message. * Lock which is locked and unlocked for each RDP message.
*/ */

View File

@ -206,11 +206,8 @@ int rdp_guac_client_handle_messages(guac_client* client) {
pthread_mutex_unlock(&(guac_client_data->rdp_lock)); pthread_mutex_unlock(&(guac_client_data->rdp_lock));
/* Flush any audio */ /* Flush any audio */
if (guac_client_data->audio != NULL) { if (guac_client_data->audio != NULL)
pthread_mutex_lock(&(guac_client_data->update_lock));
guac_socket_flush(guac_client_data->audio->stream->socket); guac_socket_flush(guac_client_data->audio->stream->socket);
pthread_mutex_unlock(&(guac_client_data->update_lock));
}
/* Success */ /* Success */
return 0; return 0;

View File

@ -31,18 +31,14 @@ char* const guac_rdpdr_pdf_filter_command[] = {
static void* guac_rdpdr_print_filter_output_thread(void* data) { static void* guac_rdpdr_print_filter_output_thread(void* data) {
guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) data; guac_rdpdrPlugin* rdpdr = (guac_rdpdrPlugin*) data;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data;
int length; int length;
char buffer[8192]; char buffer[8192];
/* Write all output as blobs */ /* Write all output as blobs */
while ((length = read(rdpdr->printer_output, buffer, sizeof(buffer))) > 0) { while ((length = read(rdpdr->printer_output, buffer, sizeof(buffer))) > 0)
pthread_mutex_lock(&(client_data->update_lock));
guac_protocol_send_blob(rdpdr->client->socket, guac_protocol_send_blob(rdpdr->client->socket,
GUAC_RDPDR_PRINTER_BLOB, buffer, length); GUAC_RDPDR_PRINTER_BLOB, buffer, length);
pthread_mutex_unlock(&(client_data->update_lock));
}
/* Log any error */ /* Log any error */
if (length < 0) if (length < 0)
@ -158,7 +154,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s
int status=0, length; int status=0, length;
unsigned char* buffer; unsigned char* buffer;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data;
STREAM* output_stream = stream_new(24); STREAM* output_stream = stream_new(24);
stream_read_uint32(input_stream, length); stream_read_uint32(input_stream, length);
@ -166,9 +161,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s
stream_seek(input_stream, 20); /* Padding */ stream_seek(input_stream, 20); /* Padding */
buffer = stream_get_tail(input_stream); buffer = stream_get_tail(input_stream);
/* Send data */
pthread_mutex_lock(&(client_data->update_lock));
/* Create print job, if not yet created */ /* Create print job, if not yet created */
if (rdpdr->bytes_received == 0) { if (rdpdr->bytes_received == 0) {
@ -224,8 +216,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s
rdpdr->bytes_received += length; rdpdr->bytes_received += length;
pthread_mutex_unlock(&(client_data->update_lock));
/* If not yet failed, write received data */ /* If not yet failed, write received data */
if (status == 0) { if (status == 0) {
@ -256,7 +246,6 @@ void guac_rdpdr_process_print_job_write(guac_rdpdrPlugin* rdpdr, STREAM* input_s
void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) { void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_stream, int completion_id) {
rdp_guac_client_data* client_data = (rdp_guac_client_data*) rdpdr->client->data;
STREAM* output_stream = stream_new(24); STREAM* output_stream = stream_new(24);
/* Close input and wait for output thread to finish */ /* Close input and wait for output thread to finish */
@ -268,9 +257,7 @@ void guac_rdpdr_process_print_job_close(guac_rdpdrPlugin* rdpdr, STREAM* input_s
/* Close file */ /* Close file */
guac_client_log_info(rdpdr->client, "Print job closed"); guac_client_log_info(rdpdr->client, "Print job closed");
pthread_mutex_lock(&(client_data->update_lock));
guac_protocol_send_end(rdpdr->client->socket, GUAC_RDPDR_PRINTER_BLOB); guac_protocol_send_end(rdpdr->client->socket, GUAC_RDPDR_PRINTER_BLOB);
pthread_mutex_unlock(&(client_data->update_lock));
/* Write header */ /* Write header */
stream_write_uint16(output_stream, RDPDR_CTYP_CORE); stream_write_uint16(output_stream, RDPDR_CTYP_CORE);

View File

@ -65,9 +65,6 @@ void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) {
/* Cache image data if present */ /* Cache image data if present */
if (bitmap->data != NULL) { if (bitmap->data != NULL) {
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
/* Create surface from image data */ /* Create surface from image data */
cairo_surface_t* surface = cairo_image_surface_create_for_data( cairo_surface_t* surface = cairo_image_surface_create_for_data(
bitmap->data, CAIRO_FORMAT_RGB24, bitmap->data, CAIRO_FORMAT_RGB24,
@ -80,7 +77,6 @@ void guac_rdp_cache_bitmap(rdpContext* context, rdpBitmap* bitmap) {
/* Free surface */ /* Free surface */
cairo_surface_destroy(surface); cairo_surface_destroy(surface);
pthread_mutex_unlock(&(data->update_lock));
} }
/* Store buffer reference in bitmap */ /* Store buffer reference in bitmap */
@ -125,9 +121,6 @@ void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) {
int width = bitmap->right - bitmap->left + 1; int width = bitmap->right - bitmap->left + 1;
int height = bitmap->bottom - bitmap->top + 1; int height = bitmap->bottom - bitmap->top + 1;
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
/* If not cached, cache if necessary */ /* If not cached, cache if necessary */
if (((guac_rdp_bitmap*) bitmap)->layer == NULL if (((guac_rdp_bitmap*) bitmap)->layer == NULL
&& ((guac_rdp_bitmap*) bitmap)->used >= 1) && ((guac_rdp_bitmap*) bitmap)->used >= 1)
@ -162,7 +155,6 @@ void guac_rdp_bitmap_paint(rdpContext* context, rdpBitmap* bitmap) {
/* Increment usage counter */ /* Increment usage counter */
((guac_rdp_bitmap*) bitmap)->used++; ((guac_rdp_bitmap*) bitmap)->used++;
pthread_mutex_unlock(&(data->update_lock));
} }
void guac_rdp_bitmap_free(rdpContext* context, rdpBitmap* bitmap) { void guac_rdp_bitmap_free(rdpContext* context, rdpBitmap* bitmap) {

View File

@ -113,10 +113,8 @@ void guac_rdp_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) {
int w = dstblt->nWidth; int w = dstblt->nWidth;
int h = dstblt->nHeight; int h = dstblt->nHeight;
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
/* Clip operation to bounds */ /* Clip operation to bounds */
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
guac_rdp_clip_rect(data, &x, &y, &w, &h); guac_rdp_clip_rect(data, &x, &y, &w, &h);
switch (dstblt->bRop) { switch (dstblt->bRop) {
@ -164,8 +162,6 @@ void guac_rdp_gdi_dstblt(rdpContext* context, DSTBLT_ORDER* dstblt) {
} }
pthread_mutex_unlock(&(data->update_lock));
} }
@ -291,10 +287,8 @@ void guac_rdp_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) {
int x_src = scrblt->nXSrc; int x_src = scrblt->nXSrc;
int y_src = scrblt->nYSrc; int y_src = scrblt->nYSrc;
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
/* Clip operation to bounds */ /* Clip operation to bounds */
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
guac_rdp_clip_rect(data, &x, &y, &w, &h); guac_rdp_clip_rect(data, &x, &y, &w, &h);
/* Update source coordinates */ /* Update source coordinates */
@ -306,8 +300,6 @@ void guac_rdp_gdi_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) {
GUAC_DEFAULT_LAYER, x_src, y_src, w, h, GUAC_DEFAULT_LAYER, x_src, y_src, w, h,
GUAC_COMP_OVER, current_layer, x, y); GUAC_COMP_OVER, current_layer, x, y);
pthread_mutex_unlock(&(data->update_lock));
} }
void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) { void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) {
@ -333,8 +325,6 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) {
return; return;
} }
pthread_mutex_lock(&(data->update_lock));
/* Clip operation to bounds */ /* Clip operation to bounds */
guac_rdp_clip_rect(data, &x, &y, &w, &h); guac_rdp_clip_rect(data, &x, &y, &w, &h);
@ -422,8 +412,6 @@ void guac_rdp_gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt) {
} }
pthread_mutex_unlock(&(data->update_lock));
} }
void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) { void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect) {
@ -436,7 +424,6 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect
const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface; const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface;
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data; rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
int x = opaque_rect->nLeftRect; int x = opaque_rect->nLeftRect;
int y = opaque_rect->nTopRect; int y = opaque_rect->nTopRect;
@ -455,8 +442,6 @@ void guac_rdp_gdi_opaquerect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect
(color ) & 0xFF, (color ) & 0xFF,
255); 255);
pthread_mutex_unlock(&(data->update_lock));
} }
void guac_rdp_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) { void guac_rdp_gdi_palette_update(rdpContext* context, PALETTE_UPDATE* palette) {

View File

@ -204,8 +204,6 @@ void guac_rdp_glyph_enddraw(rdpContext* context,
rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface; const guac_layer* current_layer = ((rdp_guac_client_data*) client->data)->current_surface;
pthread_mutex_lock(&(guac_client_data->update_lock));
/* Use glyph surface to provide image data for glyph rectangle */ /* Use glyph surface to provide image data for glyph rectangle */
cairo_surface_t* glyph_surface = guac_client_data->glyph_surface; cairo_surface_t* glyph_surface = guac_client_data->glyph_surface;
int stride = cairo_image_surface_get_stride(glyph_surface); int stride = cairo_image_surface_get_stride(glyph_surface);
@ -241,6 +239,5 @@ void guac_rdp_glyph_enddraw(rdpContext* context,
/* Destroy cairo instance */ /* Destroy cairo instance */
cairo_destroy(guac_client_data->glyph_cairo); cairo_destroy(guac_client_data->glyph_cairo);
pthread_mutex_unlock(&(guac_client_data->update_lock));
} }

View File

@ -59,9 +59,6 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) {
cairo_surface_t* surface; cairo_surface_t* surface;
rdp_guac_client_data* client_data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(client_data->update_lock));
/* Convert to alpha cursor if mask data present */ /* Convert to alpha cursor if mask data present */
if (pointer->andMaskData && pointer->xorMaskData) if (pointer->andMaskData && pointer->xorMaskData)
freerdp_alpha_cursor_convert(data, freerdp_alpha_cursor_convert(data,
@ -84,7 +81,6 @@ void guac_rdp_pointer_new(rdpContext* context, rdpPointer* pointer) {
/* Remember buffer */ /* Remember buffer */
((guac_rdp_pointer*) pointer)->layer = buffer; ((guac_rdp_pointer*) pointer)->layer = buffer;
pthread_mutex_unlock(&(client_data->update_lock));
} }
void guac_rdp_pointer_set(rdpContext* context, rdpPointer* pointer) { void guac_rdp_pointer_set(rdpContext* context, rdpPointer* pointer) {
@ -92,15 +88,11 @@ void guac_rdp_pointer_set(rdpContext* context, rdpPointer* pointer) {
guac_client* client = ((rdp_freerdp_context*) context)->client; guac_client* client = ((rdp_freerdp_context*) context)->client;
guac_socket* socket = client->socket; guac_socket* socket = client->socket;
rdp_guac_client_data* data = (rdp_guac_client_data*) client->data;
pthread_mutex_lock(&(data->update_lock));
/* Set cursor */ /* Set cursor */
guac_protocol_send_cursor(socket, pointer->xPos, pointer->yPos, guac_protocol_send_cursor(socket, pointer->xPos, pointer->yPos,
((guac_rdp_pointer*) pointer)->layer, ((guac_rdp_pointer*) pointer)->layer,
0, 0, pointer->width, pointer->height); 0, 0, pointer->width, pointer->height);
pthread_mutex_unlock(&(data->update_lock));
} }
void guac_rdp_pointer_free(rdpContext* context, rdpPointer* pointer) { void guac_rdp_pointer_free(rdpContext* context, rdpPointer* pointer) {