Fix to migrate the universal variable server off of dyn_queue_t

This commit is contained in:
ridiculousfish 2011-12-26 21:39:08 -08:00
parent 74a1d70b8a
commit 7c7aba1202
3 changed files with 34 additions and 32 deletions

View file

@ -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();
}

View file

@ -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<message_t *>;
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 );
/*

View file

@ -2,7 +2,7 @@
#define FISH_ENV_UNIVERSAL_COMMON_H
#include <wchar.h>
#include <queue>
#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_t *> 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
*/