Changeset 1132

Show
Ignore:
Timestamp:
05/07/08 13:39:26 (16 years ago)
Author:
ppalmers
Message:

fix locking bug, convert to monitor

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/ffadodevice.cpp

    r1063 r1132  
    147147FFADODevice::setId( unsigned int id) 
    148148{ 
    149     m_DeviceMutex.Lock(); 
     149    Util::MutexLockHelper lock(m_DeviceMutex); 
    150150    bool retval; 
    151151    // FIXME: decent ID system nescessary 
     
    155155 
    156156    retval=setOption("id",idstr.str()); 
    157     m_DeviceMutex.Unlock(); 
    158157    return retval; 
    159158} 
     
    179178    sleep(1); 
    180179 
    181     m_DeviceMutex.Lock(); 
     180    Util::MutexLockHelper lock(m_DeviceMutex); 
    182181    getConfigRom().setVerboseLevel(getDebugLevel()); 
    183182    getConfigRom().updatedNodeId(); 
    184     m_DeviceMutex.Unlock(); 
    185183} 
    186184 
  • trunk/libffado/src/genericavc/avc_avdevice.cpp

    r1131 r1132  
    9898AvDevice::discover() 
    9999{ 
    100     m_DeviceMutex.Lock(); 
     100    Util::MutexLockHelper lock(m_DeviceMutex); 
    101101    // check if we already have a valid VendorModel entry 
    102102    // e.g. because a subclass called this function 
     
    111111 
    112112        if (!GenericAVC::VendorModel::isValid(m_model)) { 
    113             m_DeviceMutex.Unlock(); 
    114113            return false; 
    115114        } 
     
    120119    if ( !Unit::discover() ) { 
    121120        debugError( "Could not discover unit\n" ); 
    122         m_DeviceMutex.Unlock(); 
    123121        return false; 
    124122    } 
     
    126124    if((getAudioSubunit( 0 ) == NULL)) { 
    127125        debugError( "Unit doesn't have an Audio subunit.\n"); 
    128         m_DeviceMutex.Unlock(); 
    129126        return false; 
    130127    } 
    131128    if((getMusicSubunit( 0 ) == NULL)) { 
    132129        debugError( "Unit doesn't have a Music subunit.\n"); 
    133         m_DeviceMutex.Unlock(); 
    134         return false; 
    135     } 
    136     m_DeviceMutex.Unlock(); 
     130        return false; 
     131    } 
    137132 
    138133    return true; 
     
    142137AvDevice::setVerboseLevel(int l) 
    143138{ 
    144     m_DeviceMutex.Lock(); 
     139    Util::MutexLockHelper lock(m_DeviceMutex); 
    145140    setDebugLevel(l); 
    146141    m_pPlugManager->setVerboseLevel(l); 
     
    148143    AVC::Unit::setVerboseLevel(l); 
    149144    debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 
    150     m_DeviceMutex.Unlock(); 
    151145} 
    152146 
     
    176170AvDevice::setSamplingFrequency( int s ) 
    177171{ 
    178     m_DeviceMutex.Lock(); 
     172    Util::MutexLockHelper lock(m_DeviceMutex); 
    179173    bool snoopMode=false; 
    180174    if(!getOption("snoopMode", snoopMode)) { 
     
    187181            debugError("In snoop mode it is impossible to set the sample rate.\n"); 
    188182            debugError("Please start the client with the correct setting.\n"); 
    189             m_DeviceMutex.Unlock(); 
    190             return false; 
    191         } 
    192         m_DeviceMutex.Unlock(); 
     183            return false; 
     184        } 
    193185        return true; 
    194186    } else { 
     
    196188        if ( !plug ) { 
    197189            debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    198             m_DeviceMutex.Unlock(); 
    199190            return false; 
    200191        } 
     
    203194        { 
    204195            debugError( "setSampleRate: Setting sample rate failed\n" ); 
    205             m_DeviceMutex.Unlock(); 
    206196            return false; 
    207197        } 
     
    210200        if ( !plug ) { 
    211201            debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
    212             m_DeviceMutex.Unlock(); 
    213202            return false; 
    214203        } 
     
    217206        { 
    218207            debugError( "setSampleRate: Setting sample rate failed\n" ); 
    219             m_DeviceMutex.Unlock(); 
    220208            return false; 
    221209        } 
     
    224212                     "setSampleRate: Set sample rate to %d\n", 
    225213                     s ); 
    226         m_DeviceMutex.Unlock(); 
    227214        return true; 
    228215    } 
    229216    // not executable 
    230     m_DeviceMutex.Unlock(); 
    231217    return false; 
    232218 
     
    237223    FFADODevice::ClockSourceVector r; 
    238224 
    239     m_DeviceMutex.Lock(); 
     225    Util::MutexLockHelper lock(m_DeviceMutex); 
    240226 
    241227    PlugVector syncMSUInputPlugs = m_pPlugManager->getPlugsByType( 
     
    275261        } 
    276262    } 
    277  
    278     m_DeviceMutex.Unlock(); 
    279263    return r; 
    280264} 
     
    288272    } 
    289273 
    290     m_DeviceMutex.Lock(); 
     274    Util::MutexLockHelper lock(m_DeviceMutex); 
    291275    for ( SyncInfoVector::const_iterator it 
    292276              = getSyncInfos().begin(); 
     
    297281 
    298282        if (si.m_source==src) { 
    299             m_DeviceMutex.Unlock(); 
    300283            return setActiveSync(si); 
    301284        } 
    302285    } 
    303     m_DeviceMutex.Unlock(); 
    304  
    305286    return false; 
    306287} 
     
    392373AvDevice::lock() { 
    393374    bool snoopMode=false; 
    394     m_DeviceMutex.Lock(); 
     375    Util::MutexLockHelper lock(m_DeviceMutex); 
    395376    if(!getOption("snoopMode", snoopMode)) { 
    396377        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     
    402383//         return Unit::reserve(4); 
    403384    } 
    404     m_DeviceMutex.Unlock(); 
    405385 
    406386    return true; 
     
    410390AvDevice::unlock() { 
    411391    bool snoopMode=false; 
    412     m_DeviceMutex.Lock(); 
     392    Util::MutexLockHelper lock(m_DeviceMutex); 
    413393    if(!getOption("snoopMode", snoopMode)) { 
    414394        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     
    420400//         return Unit::reserve(0); 
    421401    } 
    422     m_DeviceMutex.Unlock(); 
    423402    return true; 
    424403} 
     
    436415AvDevice::prepare() { 
    437416    bool snoopMode=false; 
    438     m_DeviceMutex.Lock(); 
     417    Util::MutexLockHelper lock(m_DeviceMutex); 
    439418    if(!getOption("snoopMode", snoopMode)) { 
    440419        debugWarning("Could not retrieve snoopMode parameter, defauling to false\n"); 
     
    447426    if ( !inputPlug ) { 
    448427        debugError( "setSampleRate: Could not retrieve iso input plug 0\n" ); 
    449         m_DeviceMutex.Unlock(); 
    450428        return false; 
    451429    } 
     
    453431    if ( !outputPlug ) { 
    454432        debugError( "setSampleRate: Could not retrieve iso output plug 0\n" ); 
    455         m_DeviceMutex.Unlock(); 
    456433        return false; 
    457434    } 
     
    463440    if ( outputPlug->getNrOfChannels() == 0 ) { 
    464441        debugError("Receive plug has no channels\n"); 
    465         m_DeviceMutex.Unlock(); 
    466442        return false; 
    467443    } 
     
    472448        debugFatal("Could not initialize receive processor!\n"); 
    473449        delete p; 
    474         m_DeviceMutex.Unlock(); 
    475450        return false; 
    476451    } 
     
    480455        debugFatal("Could not add plug to processor!\n"); 
    481456        delete p; 
    482         m_DeviceMutex.Unlock(); 
    483457        return false; 
    484458    } 
     
    508482            (snoopMode?" in snoop mode":"")); 
    509483        delete p; 
    510         m_DeviceMutex.Unlock(); 
    511484        return false; 
    512485    } 
     
    516489            Streaming::Port::E_Capture)) { 
    517490            debugFatal("Could not add plug to processor!\n"); 
    518             m_DeviceMutex.Unlock(); 
    519491            return false; 
    520492        } 
     
    523495            Streaming::Port::E_Playback)) { 
    524496            debugFatal("Could not add plug to processor!\n"); 
    525             m_DeviceMutex.Unlock(); 
    526497            return false; 
    527498        } 
     
    534505    m_transmitProcessors.push_back(p); 
    535506 
    536     m_DeviceMutex.Unlock(); 
    537507    return true; 
    538508} 
     
    637607AvDevice::getStreamCount() { 
    638608    int retval; 
    639     m_DeviceMutex.Lock(); 
     609    Util::MutexLockHelper lock(m_DeviceMutex); 
    640610    retval = m_receiveProcessors.size() + m_transmitProcessors.size(); 
    641     m_DeviceMutex.Unlock(); 
    642611    return retval; 
    643     //return 1; 
    644612} 
    645613