Mixer: Fix race condition causing invalid read in process thread of Meter_Indicator_Module.

This commit is contained in:
Jonathan Moore Liles 2010-01-15 01:53:29 -06:00
parent 352c930559
commit 26230bac61
4 changed files with 56 additions and 6 deletions

View File

@ -36,6 +36,7 @@ JACK_Module::JACK_Module ( )
p.hints.type = Port::Hints::INTEGER; p.hints.type = Port::Hints::INTEGER;
p.hints.minimum = 0; p.hints.minimum = 0;
p.hints.maximum = 6; p.hints.maximum = 6;
p.hints.ranged = true;
p.connect_to( new float ); p.connect_to( new float );
p.control_value_no_callback( 0 ); p.control_value_no_callback( 0 );
@ -48,6 +49,7 @@ JACK_Module::JACK_Module ( )
p.hints.type = Port::Hints::INTEGER; p.hints.type = Port::Hints::INTEGER;
p.hints.minimum = 0; p.hints.minimum = 0;
p.hints.maximum = 6; p.hints.maximum = 6;
p.hints.ranged = true;
p.connect_to( new float ); p.connect_to( new float );
p.control_value_no_callback( 0 ); p.control_value_no_callback( 0 );
@ -153,6 +155,8 @@ JACK_Module::initialize ( void )
void void
JACK_Module::handle_control_changed ( Port *p ) JACK_Module::handle_control_changed ( Port *p )
{ {
THREAD_ASSERT( UI );
if ( 0 == strcmp( p->name(), "Inputs" ) ) if ( 0 == strcmp( p->name(), "Inputs" ) )
{ {
DMESSAGE( "Adjusting number of inputs (JACK outputs)" ); DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
@ -163,14 +167,20 @@ JACK_Module::handle_control_changed ( Port *p )
else if ( 0 == strcmp( p->name(), "Outputs" ) ) else if ( 0 == strcmp( p->name(), "Outputs" ) )
{ {
DMESSAGE( "Adjusting number of outputs (JACK inputs)" ); DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
if ( chain() && chain()->can_configure_outputs( this, p->control_value() ) )
if ( ! chain() )
{
configure_outputs( p->control_value() );
}
else if ( chain()->can_configure_outputs( this, p->control_value() ) )
{ {
configure_outputs( p->control_value() ); configure_outputs( p->control_value() );
chain()->configure_ports(); chain()->configure_ports();
} }
else else
configure_outputs( p->control_value() ); {
p->connected_port()->control_value( noutputs() );
}
} }
} }

View File

@ -59,7 +59,7 @@ Meter_Indicator_Module::set ( Log_Entry &e )
{ {
Module::set( e ); Module::set( e );
int port; int port = -1;
Module *module = NULL; Module *module = NULL;
for ( int i = 0; i < e.size(); ++i ) for ( int i = 0; i < e.size(); ++i )
@ -146,7 +146,7 @@ Meter_Indicator_Module::update_cb ( void )
if ( dpm_pack->children() != p->hints.dimensions ) if ( dpm_pack->children() != p->hints.dimensions )
{ {
engine->lock(); /* engine->lock(); */
dpm_pack->clear(); dpm_pack->clear();
@ -165,7 +165,7 @@ Meter_Indicator_Module::update_cb ( void )
dpm->value( -70.0f ); dpm->value( -70.0f );
} }
engine->unlock(); /* engine->unlock(); */
} }
else else
{ {
@ -203,6 +203,39 @@ Meter_Indicator_Module::handle ( int m )
void
Meter_Indicator_Module::handle_control_changed ( Port *p )
{
THREAD_ASSERT( UI );
/* The engine is already locked by the UI thread at this point in
the call-graph, so we can be sure that process() won't be
executed concurrently. */
if ( p->connected() )
{
p = p->connected_port();
if ( dpm_pack->children() != p->hints.dimensions )
{
dpm_pack->clear();
control_value = new float[p->hints.dimensions];
for ( int i = p->hints.dimensions; i--; )
{
DPM *dpm = new DPM( x(), y(), w(), h() );
dpm->type( FL_VERTICAL );
align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) );
dpm_pack->add( dpm );
control_value[i] = -70.0f;
dpm->value( -70.0f );
}
}
}
}
void void
Meter_Indicator_Module::process ( void ) Meter_Indicator_Module::process ( void )
{ {

View File

@ -39,6 +39,8 @@ class Meter_Indicator_Module : public Module
public: public:
void handle_control_changed ( Port *p );
Meter_Indicator_Module ( bool is_default = false ); Meter_Indicator_Module ( bool is_default = false );
virtual ~Meter_Indicator_Module ( ); virtual ~Meter_Indicator_Module ( );

View File

@ -88,6 +88,8 @@ Meter_Module::update_cb ( void )
bool bool
Meter_Module::configure_inputs ( int n ) Meter_Module::configure_inputs ( int n )
{ {
THREAD_ASSERT( UI );
int tx, ty, tw, th; int tx, ty, tw, th;
bbox( tx,ty,tw,th ); bbox( tx,ty,tw,th );
@ -141,6 +143,9 @@ Meter_Module::configure_inputs ( int n )
for ( int i = n; i--; ) for ( int i = n; i--; )
control_value[i] = -70.0f; control_value[i] = -70.0f;
if ( control_output[0].connected() )
control_output[0].connected_port()->module()->handle_control_changed( control_output[0].connected_port() );
return true; return true;
} }