From 7c7aba1202a2c205facd64ab728dcb9472a0b6e1 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 26 Dec 2011 21:39:08 -0800 Subject: [PATCH] Fix to migrate the universal variable server off of dyn_queue_t --- env_universal.cpp | 8 ++++---- env_universal_common.cpp | 19 +++++++++---------- env_universal_common.h | 39 +++++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/env_universal.cpp b/env_universal.cpp index e3b95b304..d1726aa5a 100644 --- a/env_universal.cpp +++ b/env_universal.cpp @@ -358,7 +358,7 @@ void env_universal_barrier() */ msg= create_message( BARRIER, 0, 0); msg->count=1; - q_put( &env_universal_server.unsent, msg ); + env_universal_server.unsent->push(msg); /* Wait until barrier request has been sent @@ -369,7 +369,7 @@ void env_universal_barrier() try_send_all( &env_universal_server ); check_connection(); - if( q_empty( &env_universal_server.unsent ) ) + if( env_universal_server.unsent->empty() ) break; if( env_universal_server.fd == -1 ) @@ -433,7 +433,7 @@ void env_universal_set( const wchar_t *name, const wchar_t *value, int exportv ) } msg->count=1; - q_put( &env_universal_server.unsent, msg ); + env_universal_server.unsent->push(msg); env_universal_barrier(); } } @@ -461,7 +461,7 @@ int env_universal_remove( const wchar_t *name ) { msg= create_message( ERASE, name, 0); msg->count=1; - q_put( &env_universal_server.unsent, msg ); + env_universal_server.unsent->push(msg); env_universal_barrier(); } diff --git a/env_universal_common.cpp b/env_universal_common.cpp index 296baa5c7..50d728578 100644 --- a/env_universal_common.cpp +++ b/env_universal_common.cpp @@ -658,7 +658,7 @@ static void parse_message( wchar_t *msg, { message_t *msg = create_message( BARRIER_REPLY, 0, 0 ); msg->count = 1; - q_put( &src->unsent, msg ); + src->unsent->push(msg); try_send_all( src ); } else if( match( msg, BARRIER_REPLY_STR ) ) @@ -728,12 +728,12 @@ void try_send_all( connection_t *c ) /* debug( 3, L"Send all updates to connection on fd %d", c->fd );*/ - while( !q_empty( &c->unsent) ) + while( !c->unsent->empty() ) { - switch( try_send( (message_t *)q_peek( &c->unsent), c->fd ) ) + switch( try_send( c->unsent->front(), c->fd ) ) { case 1: - q_get( &c->unsent); + c->unsent->pop(); break; case 0: @@ -951,19 +951,18 @@ static void enqueue( void *k, { const wchar_t *key = (const wchar_t *)k; const var_uni_entry_t *val = (const var_uni_entry_t *)v; - dyn_queue_t *queue = (dyn_queue_t *)q; + message_queue_t *queue = (message_queue_t *)q; message_t *msg = create_message( val->exportv?SET_EXPORT:SET, key, val->val ); msg->count=1; - - q_put( queue, msg ); + queue->push(msg); } void enqueue_all( connection_t *c ) { hash_foreach2( &env_universal_var, &enqueue, - (void *)&c->unsent ); + (void *)c->unsent ); try_send_all( c ); } @@ -973,13 +972,13 @@ void connection_init( connection_t *c, int fd ) memset (c, 0, sizeof (connection_t)); c->fd = fd; b_init( &c->input ); - q_init( &c->unsent ); + c->unsent = new std::queue; c->buffer_consumed = c->buffer_used = 0; } void connection_destroy( connection_t *c) { - q_destroy( &c->unsent ); + if (c->unsent) delete c->unsent; b_destroy( &c->input ); /* diff --git a/env_universal_common.h b/env_universal_common.h index f85b51fe8..f69290475 100644 --- a/env_universal_common.h +++ b/env_universal_common.h @@ -2,7 +2,7 @@ #define FISH_ENV_UNIVERSAL_COMMON_H #include - +#include #include "util.h" /** @@ -54,6 +54,25 @@ enum */ #define ENV_UNIVERSAL_BUFFER_SIZE 1024 +/** + A struct representing a message to be sent between client and server +*/ +typedef struct +{ + /** + Number of queues that contain this message. Once this reaches zero, the message should be deleted + */ + int count; + /** + Message body. The message must be allocated using enough memory to actually contain the message. + */ + char body[1]; +} + message_t; + + +typedef std::queue message_queue_t; + /** This struct represents a connection between a universal variable server/client */ @@ -66,7 +85,7 @@ typedef struct connection /** Queue of onsent messages */ - dyn_queue_t unsent; + message_queue_t *unsent; /** Set to one when this connection should be killed */ @@ -100,22 +119,6 @@ typedef struct connection } connection_t; -/** - A struct representing a message to be sent between client and server -*/ -typedef struct -{ - /** - Number of queues that contain this message. Once this reaches zero, the message should be deleted - */ - int count; - /** - Message body. The message must be allocated using enough memory to actually contain the message. - */ - char body[1]; -} - message_t; - /** Read all available messages on this connection */