Changeset 8629

Show
Ignore:
Timestamp:
01/30/09 17:28:46 (4 years ago)
Author:
mcarrick
Message:

reventing multiple threads to be created when start() is called several times without calling stop(). Threads are not leaked and memory seems to be handled correctly, merged carlos' changes from trunk

Location:
ossiedev/branches/0.7.x/components/TxDemo
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/0.7.x/components/TxDemo/TxDemo.cpp

    r8363 r8629  
    3333    // initialize packet delay to be 5 seconds 
    3434    packet_delay = 5000; 
    35  
    36     //Create the thread for the writer's processing function  
    37     processing_thread = new omni_thread(Run, (void *) this); 
    38  
    39     //Start the thread containing the writer's processing function  
    40     processing_thread->start(); 
    41  
    4235} 
    4336 
     
    7366{ 
    7467    DEBUG(3, TxDemo, "start() invoked") 
    75     thread_started=true; 
     68    omni_mutex_lock l(processing_mutex); 
     69    if (false == thread_started){ 
     70        thread_started = true;    //initialize 
     71        //Create the thread for the writer's processing function  
     72        processing_thread = new omni_thread(Run, (void *) this); 
     73 
     74        //Start the thread containing the writer's processing function  
     75        processing_thread->start(); 
     76    } 
    7677} 
    7778 
     
    7980 
    8081    DEBUG(3, TxDemo, "stop() invoked") 
     82    omni_mutex_lock l(processing_mutex); 
    8183    thread_started=false; 
    8284} 
     
    131133    } 
    132134 
    133     while(true) { 
    134         if (thread_started) { 
    135             // push data to output 
    136             dataOutPort->pushPacket(I_out, Q_out); 
    137  
    138             // wait 
    139             usleep(packet_delay*1000); 
    140         } 
    141     } 
    142 } 
    143  
     135    while(continue_processing()) { 
     136        // push data to output 
     137        dataOutPort->pushPacket(I_out, Q_out); 
     138 
     139        // wait 
     140        usleep(packet_delay*1000); 
     141    } 
     142} 
     143bool TxDemo_i::continue_processing(void) 
     144{ 
     145    omni_mutex_lock l(processing_mutex); 
     146    return thread_started; 
     147} 
    144148 
    145149unsigned char data_i[512] = { 
  • ossiedev/branches/0.7.x/components/TxDemo/TxDemo.h

    r8363 r8629  
    8585    /// Main signal processing method 
    8686    void ProcessData(); 
    87     bool thread_started; 
     87    bool continue_processing(void);     ///< for start - stop processing 
     88    volatile bool thread_started; 
     89    omni_mutex processing_mutex; 
    8890    
    8991    omni_condition *component_running;  ///< for component shutdown