Skip to content
Browse files

Fix problems in client status thread.

  • Loading branch information...
1 parent 5aec869 commit 661073e43076da88125f7ff41466c2ba6d9b7ae5 @ddennedy ddennedy committed
Showing with 9 additions and 10 deletions.
  1. +4 −6 src/mvcp-client/client.c
  2. +0 −1 src/mvcp-client/client.h
  3. +4 −3 src/mvcp/mvcp_notifier.c
  4. +1 −0 src/mvcp/mvcp_parser.c
View
10 src/mvcp-client/client.c
@@ -178,7 +178,7 @@ void client_queue_action( client demo, mvcp_status status )
queue->position = ( queue->position + 1 ) % 50;
if ( queue->position == queue->tail )
queue->position = queue->head;
- mvcp_unit_load( demo->dv_status, status->unit, queue->list[ queue->position ] );
+ mvcp_unit_load( demo->dv, status->unit, queue->list[ queue->position ] );
if ( status->status == unit_not_loaded )
mvcp_unit_play( demo->dv, queue->unit );
queue->ignore = 1;
@@ -187,7 +187,7 @@ void client_queue_action( client demo, mvcp_status status )
{
if ( queue->position == -1 )
queue->position = queue->head;
- mvcp_unit_load( demo->dv_status, status->unit, queue->list[ queue->position ] );
+ mvcp_unit_load( demo->dv, status->unit, queue->list[ queue->position ] );
if ( status->status == unit_not_loaded )
mvcp_unit_play( demo->dv, queue->unit );
queue->position = ( queue->position - 1 ) % 50;
@@ -203,11 +203,11 @@ static void *client_status_thread( void *arg )
{
client demo = arg;
mvcp_status_t status;
- mvcp_notifier notifier = mvcp_get_notifier( demo->dv_status );
+ mvcp_notifier notifier = mvcp_get_notifier( demo->dv );
while ( !demo->terminated )
{
- if ( mvcp_notifier_wait( notifier, &status ) != -1 )
+ if ( mvcp_notifier_wait( notifier, &status ) == 0 )
{
client_queue_action( demo, &status );
client_show_status( demo, &status );
@@ -995,7 +995,6 @@ mvcp_error_code client_run_menu( client demo, client_menu menu )
void client_run( client this )
{
this->dv = mvcp_init( this->parser );
- this->dv_status = mvcp_init( this->parser );
if ( mvcp_connect( this->dv ) == mvcp_ok )
{
pthread_create( &this->thread, NULL, client_status_thread, this );
@@ -1010,7 +1009,6 @@ void client_run( client this )
wait_for_any_key( "" );
}
- mvcp_close( this->dv_status );
mvcp_close( this->dv );
printf( "Demo Exit.\n" );
View
1 src/mvcp-client/client.h
@@ -48,7 +48,6 @@ typedef struct
int disconnected;
mvcp_parser parser;
mvcp dv;
- mvcp dv_status;
int selected_unit;
char current_directory[ 512 ];
char last_directory[ 512 ];
View
7 src/mvcp/mvcp_notifier.c
@@ -78,8 +78,9 @@ int mvcp_notifier_wait( mvcp_notifier this, mvcp_status status )
timeout.tv_sec = now.tv_sec + 1;
timeout.tv_nsec = now.tv_usec * 1000;
pthread_mutex_lock( &this->mutex );
- pthread_cond_timedwait( &this->cond, &this->mutex, &timeout );
- mvcp_status_copy( status, &this->last );
+ error = pthread_cond_timedwait( &this->cond, &this->mutex, &timeout );
+ if ( !error )
+ mvcp_status_copy( status, &this->last );
pthread_mutex_unlock( &this->mutex );
return error;
@@ -93,8 +94,8 @@ void mvcp_notifier_put( mvcp_notifier this, mvcp_status status )
pthread_mutex_lock( &this->mutex );
mvcp_status_copy( &this->store[ status->unit ], status );
mvcp_status_copy( &this->last, status );
- pthread_mutex_unlock( &this->mutex );
pthread_cond_broadcast( &this->cond );
+ pthread_mutex_unlock( &this->mutex );
}
/** Communicate a disconnected status for all units to all waiting.
View
1 src/mvcp/mvcp_parser.c
@@ -33,6 +33,7 @@
mvcp_response mvcp_parser_connect( mvcp_parser parser )
{
+ parser->notifier = mvcp_notifier_init( );
return parser->connect( parser->real );
}

0 comments on commit 661073e

Please sign in to comment.
Something went wrong with that request. Please try again.