Changeset 1292

Show
Ignore:
Timestamp:
07/12/08 06:29:17 (13 years ago)
Author:
ppalmers
Message:

- Improve bus reset handling. Bus resets now don't mess up a ffado client on an unrelated bus.

- add string id's to threads and mutexes to aid debugging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libffado-2.0/src/bebob/focusrite/focusrite_saffire.cpp

    r1286 r1292  
    465465                c.valid = true; 
    466466                c.address = FOCUSRITE_SAFFIRE_STEREO_MATRIXMIX_OFFSET + c.row * FOCUSRITE_SAFFIRE_STEREO_MATRIXMIX_NB_COLS + c.col; 
    467                 debugOutput(DEBUG_LEVEL_NORMAL, "Add row %d col %d, address %d\n", c.row, c.col, c.address); 
    468467                m_CellInfo.at(i).at(j) =  c; 
    469468            } 
     
    512511                c.valid = true; 
    513512                c.address = FOCUSRITE_SAFFIRE_MONO_MATRIXMIX_OFFSET + c.row * FOCUSRITE_SAFFIRE_MONO_MATRIXMIX_NB_COLS + c.col; 
    514                 debugOutput(DEBUG_LEVEL_NORMAL, "Add row %d col %d, address %d\n", c.row, c.col, c.address); 
    515513                m_CellInfo.at(i).at(j) =  c; 
    516514            } 
  • branches/libffado-2.0/src/bebob/focusrite/focusrite_saffirepro.cpp

    r1249 r1292  
    571571        const int max_tries = 2; 
    572572        int ntries = max_tries+1; 
    573          
    574         // FIXME: not very clean 
    575         getDeviceManager().ignoreBusResets(true); 
    576          
     573 
     574        // the device behaves like a pig when changing samplerate, 
     575        // generating a bunch of bus-resets. 
     576        // we don't want the busreset handler to run while we are 
     577        // changing the samplerate. however it has to run after the 
     578        // device finished, since the bus resets might have influenced 
     579        // other attached devices. 
     580        getDeviceManager().lockBusResetHandler(); 
    577581        unsigned int gen_before = get1394Service().getGeneration(); 
    578          
     582 
    579583        while(--ntries) { 
    580584            if (rebootOnSamplerateChange) { 
     
    614618                    if (!timeout) { 
    615619                        debugError( "Device did not reset itself after forced reboot...\n"); 
     620                        getDeviceManager().unlockBusResetHandler(); 
    616621                        return false; 
    617622                    } 
     
    633638                if (!timeout) { 
    634639                    debugError( "Device did not recover from reboot...\n"); 
     640                    getDeviceManager().unlockBusResetHandler(); 
    635641                    return false; 
    636642                } 
     
    651657            } 
    652658 
    653             int verify=getSamplingFrequency(); 
     659            int verify = getSamplingFrequency(); 
    654660            debugOutput( DEBUG_LEVEL_VERBOSE, 
    655661                        "setSampleRate (try %d): requested samplerate %d, device now has %d\n",  
     
    662668        } 
    663669 
    664         // FIXME: not very clea
    665         getDeviceManager().ignoreBusResets(false); 
     670        // make the busreset handlers ru
     671        getDeviceManager().unlockBusResetHandler(); 
    666672 
    667673        if (ntries==0) { 
  • branches/libffado-2.0/src/devicemanager.cpp

    r1263 r1292  
    3131#include "libieee1394/configrom.h" 
    3232#include "libieee1394/ieee1394service.h" 
     33#include "libieee1394/IsoHandlerManager.h" 
    3334 
    3435#include "libstreaming/generic/StreamProcessor.h" 
     
    6667DeviceManager::DeviceManager() 
    6768    : Control::Container(NULL, "devicemanager") // this is the control root node 
    68     , m_avDevicesLock( new Util::PosixMutex() ) 
    69     , m_BusResetLock( new Util::PosixMutex() ) 
     69    , m_DeviceListLock( new Util::PosixMutex("DEVLST") ) 
     70    , m_BusResetLock( new Util::PosixMutex("DEVBR") ) 
    7071    , m_processorManager( new Streaming::StreamProcessorManager( *this ) ) 
    7172    , m_deviceStringParser( new DeviceStringParser() ) 
    7273    , m_used_cache_last_time( false ) 
    73     , m_ignore_busreset( false ) 
    7474    , m_thread_realtime( false ) 
    7575    , m_thread_priority( 0 ) 
     
    8181DeviceManager::~DeviceManager() 
    8282{ 
    83     m_avDevicesLock->Lock(); // make sure nobody is using this 
     83    m_BusResetLock->Lock(); // make sure we are not handling a busreset. 
     84    m_DeviceListLock->Lock(); // make sure nobody is using this 
    8485    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
    8586          it != m_avDevices.end(); 
     
    9192        delete *it; 
    9293    } 
    93     m_avDevicesLock->Unlock(); 
    94     delete m_avDevicesLock; 
     94    m_DeviceListLock->Unlock(); 
    9595 
    9696    // the SP's are automatically unregistered from the SPM 
    9797    delete m_processorManager; 
    9898 
     99    // the device list is empty, so wake up any waiting 
     100    // reset handlers 
     101    m_BusResetLock->Unlock(); 
     102 
     103    // remove the bus-reset handlers 
    99104    for ( FunctorVectorIterator it = m_busreset_functors.begin(); 
    100105          it != m_busreset_functors.end(); 
     
    103108        delete *it; 
    104109    } 
    105     delete m_BusResetLock; 
    106110 
    107111    for ( Ieee1394ServiceVectorIterator it = m_1394Services.begin(); 
     
    112116    } 
    113117 
     118    delete m_DeviceListLock; 
     119    delete m_BusResetLock; 
    114120    delete m_deviceStringParser; 
    115121} 
     
    166172        } 
    167173        // add the bus reset handler 
    168         Util::Functor* tmp_busreset_functor = new Util::MemberFunctor0< DeviceManager*, 
    169                     void (DeviceManager::*)()
    170                     ( this, &DeviceManager::busresetHandler, false ); 
     174        Util::Functor* tmp_busreset_functor = new Util::MemberFunctor1< DeviceManager*, 
     175                    void (DeviceManager::*)(Ieee1394Service &), Ieee1394Service &
     176                    ( this, &DeviceManager::busresetHandler, *tmp1394Service, false ); 
    171177        if ( !tmp_busreset_functor ) { 
    172178            debugFatal( "Could not create busreset handler for port %d\n", port ); 
     
    202208 
    203209void 
    204 DeviceManager::busresetHandler(
     210DeviceManager::busresetHandler(Ieee1394Service &service
    205211{ 
    206212    // serialize bus reset handling since it can be that a new one occurs while we're 
    207213    // doing stuff. 
     214    debugOutput( DEBUG_LEVEL_NORMAL, "Bus reset detected on service %p...\n", &service ); 
    208215    Util::MutexLockHelper lock(*m_BusResetLock); 
    209     debugOutput( DEBUG_LEVEL_VERBOSE, "Bus reset...\n" ); 
    210     if(m_ignore_busreset) { 
    211         debugOutput( DEBUG_LEVEL_VERBOSE, " ignoring...\n" ); 
    212         return; 
    213     } 
    214  
    215     // FIXME: what port was the bus reset on? 
    216     // FIXME: what if the devices are gone? 
     216    debugOutput( DEBUG_LEVEL_NORMAL, " handling busreset...\n" ); 
     217 
     218    // FIXME: what if the devices are gone? (device should detect this!) 
    217219    // propagate the bus reset to all avDevices 
    218     m_avDevicesLock->Lock(); // make sure nobody is using this 
     220    m_DeviceListLock->Lock(); // make sure nobody is using this 
    219221    for ( FFADODeviceVectorIterator it = m_avDevices.begin(); 
    220222          it != m_avDevices.end(); 
    221223          ++it ) 
    222224    { 
    223         (*it)->handleBusReset(); 
    224     } 
    225     m_avDevicesLock->Unlock(); 
     225        if(&service == &((*it)->get1394Service())) { 
     226            debugOutput(DEBUG_LEVEL_NORMAL, 
     227                        "issue busreset on device GUID %s\n", 
     228                        (*it)->getConfigRom().getGuidString().c_str()); 
     229            (*it)->handleBusReset(); 
     230        } else { 
     231            debugOutput(DEBUG_LEVEL_NORMAL, 
     232                        "skipping device GUID %s since not on service %p\n", 
     233                        (*it)->getConfigRom().getGuidString().c_str(), &service); 
     234        } 
     235    } 
     236    m_DeviceListLock->Unlock(); 
     237 
     238    // now that the devices have been updates, we can request to update the iso streams 
     239    if(!service.getIsoHandlerManager().handleBusReset()) { 
     240        debugError("IsoHandlerManager failed to handle busreset\n"); 
     241    } 
    226242 
    227243    // notify the streamprocessormanager of the busreset 
    228     if(m_processorManager) { 
    229         m_processorManager->handleBusReset(); 
    230     } else { 
    231         debugWarning("No valid SPM\n"); 
    232     } 
     244//     if(m_processorManager) { 
     245//         m_processorManager->handleBusReset(service); 
     246//     } else { 
     247//         debugWarning("No valid SPM\n"); 
     248//     } 
    233249 
    234250    // rediscover to find new devices 
     
    242258 
    243259    // display the new state 
    244     showDeviceInfo(); 
     260    if(getDebugLevel() >= DEBUG_LEVEL_VERBOSE) { 
     261        showDeviceInfo(); 
     262    } 
    245263} 
    246264 
     
    298316DeviceManager::discover( bool useCache, bool rediscover ) 
    299317{ 
     318    debugOutput( DEBUG_LEVEL_NORMAL, "Starting discovery...\n" ); 
    300319    useCache = useCache && ENABLE_DISCOVERY_CACHE; 
    301320    m_used_cache_last_time = useCache; 
     
    351370    // notify that we are going to manipulate the list 
    352371    signalNotifiers(m_preUpdateNotifiers); 
    353     m_avDevicesLock->Lock(); // make sure nobody starts using the list 
     372    m_DeviceListLock->Lock(); // make sure nobody starts using the list 
    354373    if(rediscover) { 
    355374 
     
    616635    } 
    617636 
    618     m_avDevicesLock->Unlock(); 
     637    m_DeviceListLock->Unlock(); 
    619638    // notify any clients 
    620639    signalNotifiers(m_postUpdateNotifiers); 
  • branches/libffado-2.0/src/devicemanager.h

    r1229 r1292  
    105105    Streaming::StreamProcessor *getSyncSource(); 
    106106 
    107     void ignoreBusResets(bool b) {m_ignore_busreset = b;}; 
     107    /** 
     108     * prevents the busreset handler from running. use with care! 
     109     */ 
     110    void lockBusResetHandler() {m_BusResetLock->Lock();}; 
     111    /** 
     112     * releases the busreset handlers 
     113     */ 
     114    void unlockBusResetHandler() {m_BusResetLock->Unlock();}; 
    108115    bool registerBusresetNotification(Util::Functor *f) 
    109116        {return registerNotification(m_busResetNotifiers, f);}; 
     
    137144    FFADODevice* getSlaveDriver( std::auto_ptr<ConfigRom>( configRom ) ); 
    138145 
    139     void busresetHandler(); 
     146    void busresetHandler(Ieee1394Service &); 
    140147 
    141148protected: 
     
    147154 
    148155    // the lock protecting the device list 
    149     Util::Mutex*            m_avDevicesLock; 
     156    Util::Mutex*            m_DeviceListLock; 
    150157    // the lock to serialize bus reset handling 
    151158    Util::Mutex*            m_BusResetLock; 
     
    158165    DeviceStringParser*                 m_deviceStringParser; 
    159166    bool                                m_used_cache_last_time; 
    160     bool                                m_ignore_busreset; 
    161167 
    162168    typedef std::vector< Util::Functor* > notif_vec_t; 
  • branches/libffado-2.0/src/fbtypes.h

    r864 r1292  
    2727#include <libraw1394/raw1394.h> 
    2828 
     29#define INVALID_NODE_ID 0xFF 
     30 
    2931typedef quadlet_t   fb_quadlet_t; 
    3032typedef byte_t      fb_byte_t; 
  • branches/libffado-2.0/src/fireworks/fireworks_device.cpp

    r1291 r1292  
    5252Device::Device(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom )) 
    5353    : GenericAVC::AvDevice( d, configRom) 
    54     , m_poll_lock( new Util::PosixMutex() ) 
     54    , m_poll_lock( new Util::PosixMutex("DEVPOLL") ) 
    5555    , m_efc_discovery_done ( false ) 
    5656    , m_MixerContainer ( NULL ) 
  • branches/libffado-2.0/src/libavc/general/avc_unit.cpp

    r1238 r1292  
    844844Unit::show() 
    845845{ 
    846     m_pPlugManager->showPlugs(); 
     846    if (getDebugLevel() >= DEBUG_LEVEL_VERY_VERBOSE) { 
     847        m_pPlugManager->showPlugs(); 
     848    } 
    847849    //SubunitMusic* s=getMusicSubunit(0); 
    848850    //if(s) s->showMusicPlugs(); 
  • branches/libffado-2.0/src/libcontrol/Element.cpp

    r1201 r1292  
    5050    // this means we have to create a lock 
    5151    if(parent == NULL) { 
    52         m_element_lock = new Util::PosixMutex(); 
     52        m_element_lock = new Util::PosixMutex("CTLEL"); 
    5353    } 
    5454} 
     
    6565    // this means we have to create a lock 
    6666    if(parent == NULL) { 
    67         m_element_lock = new Util::PosixMutex(); 
     67        m_element_lock = new Util::PosixMutex("CTLEL"); 
    6868    } 
    6969} 
  • branches/libffado-2.0/src/libieee1394/configrom.cpp

    r1186 r1292  
    546546    } 
    547547 
    548     debugOutput( DEBUG_LEVEL_NORMAL
    549                  "Device with GUID 0x%08x%08x could not be found on " 
     548    debugOutput( DEBUG_LEVEL_VERBOSE
     549                 "Device with GUID 0x%016llX could not be found on " 
    550550                 "the bus anymore (removed?)\n", 
    551                  m_guid >> 32, 
    552                  m_guid & 0xffffffff )
     551                 getGuid() ); 
     552    m_nodeId = INVALID_NODE_ID
    553553    return false; 
    554554} 
  • branches/libffado-2.0/src/libieee1394/configrom.h

    r1154 r1292  
    112112    } 
    113113 
     114    bool isPresentOnBus() { 
     115        return m_nodeId != INVALID_NODE_ID; 
     116    }; 
    114117 protected: 
    115118    void processUnitDirectory( struct csr1212_csr*    csr, 
  • branches/libffado-2.0/src/libieee1394/CycleTimerHelper.cpp

    r1281 r1292  
    7373    , m_realtime ( false ) 
    7474    , m_priority ( 0 ) 
    75     , m_update_lock( new Util::PosixMutex() ) 
     75    , m_update_lock( new Util::PosixMutex("CTRUPD") ) 
    7676    , m_busreset_functor ( NULL) 
    7777    , m_unhandled_busreset ( false ) 
     
    9999    , m_realtime ( rt ) 
    100100    , m_priority ( prio ) 
    101     , m_update_lock( new Util::PosixMutex() ) 
     101    , m_update_lock( new Util::PosixMutex("CTRUPD") ) 
    102102    , m_busreset_functor ( NULL) 
    103103    , m_unhandled_busreset ( false ) 
     
    131131    } 
    132132 
    133     m_Thread = new Util::PosixThread(this, m_realtime, m_priority,  
     133    m_Thread = new Util::PosixThread(this, "CTRHLP", m_realtime, m_priority,  
    134134                                     PTHREAD_CANCEL_DEFERRED); 
    135135    if(!m_Thread) { 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.cpp

    r1219 r1292  
    4545#include <iomanip> 
    4646 
     47using namespace std; 
     48 
    4749IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL ); 
    4850 
    4951Ieee1394Service::Ieee1394Service() 
    5052    : m_handle( 0 ) 
    51     , m_handle_lock( new Util::PosixMutex() ) 
     53    , m_handle_lock( new Util::PosixMutex("SRCVHND") ) 
    5254    , m_resetHandle( 0 ) 
    5355    , m_util_handle( 0 ) 
    5456    , m_port( -1 ) 
    55     , m_RHThread_lock( new Util::PosixMutex() ) 
     57    , m_RHThread_lock( new Util::PosixMutex("SRVCRH") ) 
    5658    , m_threadRunning( false ) 
    5759    , m_realtime ( false ) 
     
    7577Ieee1394Service::Ieee1394Service(bool rt, int prio) 
    7678    : m_handle( 0 ) 
    77     , m_handle_lock( new Util::PosixMutex() ) 
     79    , m_handle_lock( new Util::PosixMutex("SRCVHND") ) 
    7880    , m_resetHandle( 0 ) 
    7981    , m_util_handle( 0 ) 
    8082    , m_port( -1 ) 
    81     , m_RHThread_lock( new Util::PosixMutex() ) 
     83    , m_RHThread_lock( new Util::PosixMutex("SRVCRH") ) 
    8284    , m_threadRunning( false ) 
    8385    , m_realtime ( rt ) 
     
    399401{ 
    400402    Util::MutexLockHelper lock(*m_handle_lock); 
    401     using namespace std; 
     403    if (nodeId == INVALID_NODE_ID) { 
     404        debugWarning("operation on invalid node\n"); 
     405        return false; 
     406    } 
    402407    if ( raw1394_read( m_handle, nodeId, addr, length*4, buffer ) == 0 ) { 
    403408 
     
    444449{ 
    445450    Util::MutexLockHelper lock(*m_handle_lock); 
    446     using namespace std; 
     451    if (nodeId == INVALID_NODE_ID) { 
     452        debugWarning("operation on invalid node\n"); 
     453        return false; 
     454    } 
    447455 
    448456    #ifdef DEBUG 
     
    473481 
    474482bool 
    475 Ieee1394Service::lockCompareSwap64(  fb_nodeid_t nodeId, 
    476                         fb_nodeaddr_t addr, 
    477                         fb_octlet_t  compare_value, 
    478                         fb_octlet_t  swap_value, 
    479                         fb_octlet_t* result ) 
    480 
     483Ieee1394Service::lockCompareSwap64( fb_nodeid_t nodeId, 
     484                                    fb_nodeaddr_t addr, 
     485                                    fb_octlet_t compare_value, 
     486                                    fb_octlet_t swap_value, 
     487                                    fb_octlet_t* result ) 
     488
     489    if (nodeId == INVALID_NODE_ID) { 
     490        debugWarning("operation on invalid node\n"); 
     491        return false; 
     492    } 
    481493    #ifdef DEBUG 
    482494    debugOutput(DEBUG_LEVEL_VERBOSE,"lockCompareSwap64: node 0x%X, addr = 0x%016llX\n", 
     
    527539                                   unsigned int* resp_len ) 
    528540{ 
     541    if (nodeId == INVALID_NODE_ID) { 
     542        debugWarning("operation on invalid node\n"); 
     543        return false; 
     544    } 
    529545    // FIXME: this requires transactionBlockClose to unlock 
    530546    m_handle_lock->Lock(); 
     
    611627    quadlet_t buf=0; 
    612628 
     629    m_handle_lock->Lock(); 
     630    raw1394_update_generation(m_handle, generation); 
     631    m_handle_lock->Unlock(); 
     632 
    613633    // do a simple read on ourself in order to update the internal structures 
    614634    // this avoids failures after a bus reset 
     
    652672{ 
    653673    if ( m_threadRunning ) { 
     674        // wait for the thread to finish it's work 
    654675        m_RHThread_lock->Lock(); 
    655676        pthread_cancel (m_thread); 
     
    666687 
    667688    while (true) { 
    668         raw1394_loop_iterate (pIeee1394Service->m_resetHandle); 
     689        // protect ourselves from dying 
     690        { 
     691            // use a scoped lock such that it is unlocked 
     692            // even if we are cancelled while running 
     693            // FIXME: check if this is true! 
     694//             Util::MutexLockHelper lock(*(pIeee1394Service->m_RHThread_lock)); 
     695            raw1394_loop_iterate (pIeee1394Service->m_resetHandle); 
     696        } 
    669697        pthread_testcancel (); 
    670698    } 
     
    778806    nodeid_t recv_node, int recv_plug 
    779807    ) { 
     808 
     809    if (xmit_node == INVALID_NODE_ID) { 
     810        debugWarning("operation on invalid node (XMIT)\n"); 
     811        return -1; 
     812    } 
     813    if (recv_node == INVALID_NODE_ID) { 
     814        debugWarning("operation on invalid node (RECV)\n"); 
     815        return -1; 
     816    } 
    780817 
    781818    debugOutput(DEBUG_LEVEL_VERBOSE, "Allocating ISO channel using IEC61883 CMP...\n" ); 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.h

    r1190 r1292  
    226226 
    227227    bool transactionBlockClose(); 
    228 // FIXME: private for thread safety !! 
    229     raw1394handle_t getHandle() {return m_handle;}; 
    230228 
    231229    int getVerboseLevel(); 
     
    278276    bool registerIsoChannel(unsigned int c, struct ChannelInfo cinfo); 
    279277 
     278public: 
     279// FIXME: should be private, but is used to do the PCR control in GenericAVC::AvDevice 
     280    raw1394handle_t getHandle() {return m_handle;}; 
     281 
    280282private: 
    281  
    282283    bool startRHThread(); 
    283284    void stopRHThread(); 
     
    288289 
    289290    static int resetHandlerLowLevel( raw1394handle_t handle, 
    290                     unsigned int generation ); 
     291                                     unsigned int generation ); 
    291292    bool resetHandler( unsigned int generation ); 
    292293 
  • branches/libffado-2.0/src/libieee1394/IsoHandler.cpp

    r1269 r1292  
    7171} 
    7272 
    73 int IsoHandler::busreset_handler(raw1394handle_t handle, unsigned int generation) 
    74 { 
    75     debugOutput( DEBUG_LEVEL_VERBOSE, "Busreset happened, generation %d...\n", generation); 
    76  
    77     IsoHandler *handler = static_cast<IsoHandler *>(raw1394_get_userdata(handle)); 
    78     // FIXME: we should update the generation. 
    79     assert(handler); 
    80     return handler->handleBusReset(generation); 
    81 } 
    82  
    8373IsoHandler::IsoHandler(IsoHandlerManager& manager, enum EHandlerType t) 
    8474   : m_manager( manager ) 
     
    240230    raw1394_set_userdata(m_handle, static_cast<void *>(this)); 
    241231 
    242     // bus reset handling 
    243     if(raw1394_busreset_notify (m_handle, RAW1394_NOTIFY_ON)) { 
    244         debugWarning("Could not enable busreset notification.\n"); 
    245         debugWarning(" Error message: %s\n",strerror(errno)); 
    246         debugWarning("Continuing without bus reset support.\n"); 
    247     } else { 
    248         // apparently this cannot fail 
    249         raw1394_set_bus_reset_handler(m_handle, busreset_handler); 
    250     } 
    251  
    252232    // update the internal state 
    253233    m_State=E_Initialized; 
     
    267247    } 
    268248 
     249    debugOutput( DEBUG_LEVEL_VERBOSE, "(%p, %s) wake up handle...\n",  
     250                 this, (m_type==eHT_Receive?"Receive":"Transmit")); 
     251 
    269252    // wake up any waiting reads/polls 
    270253    raw1394_wake_up(m_handle); 
     
    273256    // Runaway context problem 
    274257    // don't know if it will help though. 
    275     if(m_State != E_Error) { // if the handler is dead, this might block forever 
     258/*    if(m_State != E_Error) { // if the handler is dead, this might block forever 
    276259        raw1394_iso_xmit_sync(m_handle); 
    277     } 
     260    }*/ 
     261    debugOutput( DEBUG_LEVEL_VERBOSE, "(%p, %s) stop...\n",  
     262                 this, (m_type==eHT_Receive?"Receive":"Transmit")); 
    278263    raw1394_iso_stop(m_handle); 
    279264    m_State = E_Prepared; 
     
    287272 */ 
    288273 
    289 int 
    290 IsoHandler::handleBusReset(unsigned int generation
     274bool 
     275IsoHandler::handleBusReset(
    291276{ 
    292277    debugOutput( DEBUG_LEVEL_NORMAL, "bus reset...\n"); 
     278    m_last_packet_handled_at = 0xFFFFFFFF; 
    293279 
    294280    #define CSR_CYCLE_TIME            0x200 
     
    300286                 CSR_REGISTER_BASE | CSR_CYCLE_TIME, 4, &buf); 
    301287 
    302     // notify the client of the fact that we have died 
    303     m_Client->handlerDied(); 
    304  
    305     if(!disable()) { 
    306         debugError("(%p) Could not disable IsoHandler\n", this); 
    307     } 
    308  
    309     // request the manager to update it's shadow map 
    310     m_manager.requestShadowMapUpdate(); 
    311     return 0; 
     288    return m_Client->handleBusReset(); 
    312289} 
    313290 
  • branches/libffado-2.0/src/libieee1394/IsoHandler.h

    r1266 r1292  
    169169 
    170170    void notifyOfDeath(); 
     171    bool handleBusReset(); 
     172 
    171173private: 
    172174    IsoHandlerManager& m_manager; 
     
    182184    Streaming::StreamProcessor *m_Client; // FIXME: implement with functors 
    183185 
    184     int handleBusReset(unsigned int generation); 
    185  
    186     static int busreset_handler(raw1394handle_t handle, unsigned int generation); 
    187  
    188186    enum raw1394_iso_speed m_speed; 
    189187    unsigned int m_prebuffers; 
  • branches/libffado-2.0/src/libieee1394/IsoHandlerManager.cpp

    r1263 r1292  
    4848    , m_handlerType( t ) 
    4949    , m_running( false ) 
     50    , m_in_busreset( false ) 
    5051{ 
    5152} 
     
    8485    INC_ATOMIC(&request_update); 
    8586 
     87    // get the thread going again 
     88    signalActivity(); 
     89 
    8690    if (m_running) { 
    8791        int timeout = 1000; 
     
    9599    debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) exit\n", this); 
    96100    return true; 
     101} 
     102 
     103bool 
     104IsoTask::handleBusReset() 
     105{ 
     106    bool retval = true; 
     107    m_in_busreset = true; 
     108    requestShadowMapUpdate(); 
     109    if(request_update) { 
     110        debugError("shadow map update request not honored\n"); 
     111        return false; 
     112    } 
     113 
     114    unsigned int i, max; 
     115    max = m_manager.m_IsoHandlers.size(); 
     116    for (i = 0; i < max; i++) { 
     117        IsoHandler *h = m_manager.m_IsoHandlers.at(i); 
     118        assert(h); 
     119 
     120        // skip the handlers not intended for us 
     121        if(h->getType() != m_handlerType) continue; 
     122 
     123        if (!h->handleBusReset()) { 
     124            debugWarning("Failed to handle busreset on %p\n"); 
     125            retval = false; 
     126        } 
     127    } 
     128 
     129    // re-enable processing 
     130    m_in_busreset = false; 
     131    requestShadowMapUpdate(); 
     132    if(request_update) { 
     133        debugError("shadow map update request not honored\n"); 
     134        return false; 
     135    } 
     136    return retval; 
    97137} 
    98138 
     
    104144{ 
    105145    debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) updating shadow vars...\n", this); 
     146    // we are handling a busreset 
     147    if(m_in_busreset) { 
     148        m_poll_nfds_shadow = 0; 
     149        return; 
     150    } 
    106151    unsigned int i, cnt, max; 
    107152    max = m_manager.m_IsoHandlers.size(); 
     
    283328        uint64_t last_packet_seen_ticks = CYCLE_TIMER_TO_TICKS(last_packet_seen); 
    284329        // we use a relatively large value to distinguish between "death" and xrun 
    285         int64_t max_diff_ticks = TICKS_PER_SECOND * 1
     330        int64_t max_diff_ticks = TICKS_PER_SECOND * 2
    286331        int64_t measured_diff_ticks = diffTicks(ctr_at_poll_return_ticks, last_packet_seen_ticks); 
    287332 
     
    451496} 
    452497 
     498bool 
     499IsoHandlerManager::handleBusReset() 
     500{ 
     501    debugOutput( DEBUG_LEVEL_NORMAL, "bus reset...\n"); 
     502    // A few things can happen on bus reset: 
     503    // 1) no devices added/removed => streams are still valid, but might have to be restarted 
     504    // 2) a device was removed => some streams become invalid 
     505    // 3) a device was added => same as 1, new device is ignored 
     506    if (!m_IsoTaskTransmit) { 
     507        debugError("No xmit task\n"); 
     508        return false; 
     509    } 
     510    if (!m_IsoTaskReceive) { 
     511        debugError("No receive task\n"); 
     512        return false; 
     513    } 
     514    if (!m_IsoTaskTransmit->handleBusReset()) { 
     515        debugWarning("could no handle busreset on xmit\n"); 
     516    } 
     517    if (!m_IsoTaskReceive->handleBusReset()) { 
     518        debugWarning("could no handle busreset on recv\n"); 
     519    } 
     520    return true; 
     521} 
     522 
    453523void 
    454524IsoHandlerManager::requestShadowMapUpdate() 
     
    504574    } 
    505575    m_IsoTaskTransmit->setVerboseLevel(getDebugLevel()); 
    506     m_IsoThreadTransmit = new Util::PosixThread(m_IsoTaskTransmit, m_realtime, 
     576    m_IsoThreadTransmit = new Util::PosixThread(m_IsoTaskTransmit, "ISOXMT", m_realtime, 
    507577                                                m_priority + ISOHANDLERMANAGER_ISO_PRIO_INCREASE 
    508578                                                + ISOHANDLERMANAGER_ISO_PRIO_INCREASE_XMIT, 
     
    522592    } 
    523593    m_IsoTaskReceive->setVerboseLevel(getDebugLevel()); 
    524     m_IsoThreadReceive = new Util::PosixThread(m_IsoTaskReceive, m_realtime, 
     594    m_IsoThreadReceive = new Util::PosixThread(m_IsoTaskReceive, "ISORCV", m_realtime, 
    525595                                               m_priority + ISOHANDLERMANAGER_ISO_PRIO_INCREASE 
    526596                                               + ISOHANDLERMANAGER_ISO_PRIO_INCREASE_RECV, 
  • branches/libffado-2.0/src/libieee1394/IsoHandlerManager.h

    r1263 r1292  
    8585        enum eActivityResult waitForActivity(); 
    8686 
     87        /** 
     88         * @brief This should be called when a busreset has happened. 
     89         */ 
     90        bool handleBusReset(); 
     91 
    8792        void setVerboseLevel(int i); 
    8893    protected: 
     
    113118        enum IsoHandler::EHandlerType m_handlerType; 
    114119        bool m_running; 
     120        bool m_in_busreset; 
    115121 
    116122        // debug stuff 
     
    187193        void requestShadowMapUpdate(); 
    188194 
     195        /** 
     196         * This should be called when a busreset has happened. 
     197         */ 
     198        bool handleBusReset(); 
    189199    // the state machine 
    190200    private: 
  • branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.cpp

    r1271 r1292  
    9393} 
    9494 
    95 void 
     95bool 
     96StreamProcessor::handleBusResetDo() 
     97
     98    debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) handling busreset\n", this); 
     99    m_state = ePS_Error; 
     100    // this will result in the SPM dying 
     101    m_in_xrun = true; 
     102    SIGNAL_ACTIVITY_ALL; 
     103    return true; 
     104
     105 
     106bool 
    96107StreamProcessor::handleBusReset() 
    97108{ 
    98109    debugOutput(DEBUG_LEVEL_VERBOSE, "(%p) handling busreset\n", this); 
    99     // for now, we try and make sure everything is cleanly shutdown 
    100     if(!stopRunning(-1)) { 
    101         debugError("Failed to stop SP\n"); 
    102     } 
    103     SIGNAL_ACTIVITY_ALL; 
     110 
     111    // we are sure that we're not iterated since this is called from within the ISO manager thread 
     112 
     113    // lock the wait loop of the SPM, such that the client leaves us alone 
     114    m_StreamProcessorManager.lockWaitLoop(); 
     115 
     116    // pass on to the implementing classes 
     117    bool retval = handleBusResetDo(); 
     118 
     119    // resume wait loop 
     120    m_StreamProcessorManager.unlockWaitLoop(); 
     121 
     122    return retval; 
    104123} 
    105124 
     
    301320    } 
    302321 
     322    if (m_state == ePS_Error) { 
     323        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "skip due to error state\n"); 
     324        return RAW1394_ISO_OK; 
     325    } 
     326 
    303327    // store the previous timestamp 
    304328    m_last_timestamp2 = m_last_timestamp; 
     
    489513        return RAW1394_ISO_OK; 
    490514    } 
     515 
     516    if (m_state == ePS_Error) { 
     517        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, "skip due to error state\n"); 
     518        return RAW1394_ISO_OK; 
     519    } 
     520 
    491521    uint64_t prev_timestamp; 
    492  
    493522    // note that we can ignore skipped cycles since 
    494523    // the protocol will take care of that 
     
    17681797        case ePS_Running: return "ePS_Running"; 
    17691798        case ePS_WaitingForStreamDisable: return "ePS_WaitingForStreamDisable"; 
     1799        case ePS_Error: return "ePS_Error"; 
    17701800        default: return "error: unknown state"; 
    17711801    } 
  • branches/libffado-2.0/src/libstreaming/generic/StreamProcessor.h

    r1263 r1292  
    7878        ePS_Running, 
    7979        ePS_WaitingForStreamDisable, 
     80        ePS_Error, 
    8081    }; 
    8182 
     
    112113    bool isWaitingForStream() 
    113114            {return m_state == ePS_WaitingForStream;}; 
     115    bool inError() 
     116            {return m_state == ePS_Error;}; 
    114117 
    115118    // these schedule and wait for the state transition 
     
    130133    bool prepare(); 
    131134 
    132     void handleBusReset(); 
     135    bool handleBusReset(); 
     136 
     137    // the one to be implemented by the child class 
     138    virtual bool handleBusResetDo(); 
     139 
     140    FFADODevice& getParent() {return m_Parent;}; 
    133141 
    134142public: // constructor/destructor 
  • branches/libffado-2.0/src/libstreaming/StreamProcessorManager.cpp

    r1273 r1292  
    5353    , m_shutdown_needed(false) 
    5454    , m_nbperiods(0) 
    55     , m_WaitLock( new Util::PosixMutex
     55    , m_WaitLock( new Util::PosixMutex("SPMWAIT")
    5656{ 
    5757    addOption(Util::OptionContainer::Option("slaveMode",false)); 
     
    7373    , m_shutdown_needed(false) 
    7474    , m_nbperiods(0) 
    75     , m_WaitLock( new Util::PosixMutex
     75    , m_WaitLock( new Util::PosixMutex("SPMWAIT")
    7676{ 
    7777    addOption(Util::OptionContainer::Option("slaveMode",false)); 
     
    8585} 
    8686 
    87 void 
    88 StreamProcessorManager::handleBusReset() 
    89 
    90     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Handle bus reset...\n", this); 
    91  
    92     // FIXME: we request shutdown for now. 
    93     m_shutdown_needed=true; 
    94  
    95     // note that all receive streams are gone once a device is unplugged 
    96  
    97     // synchronize with the wait lock 
    98     Util::MutexLockHelper lock(*m_WaitLock); 
    99  
    100     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) got wait lock...\n", this); 
    101     // cause all SP's to bail out 
    102     for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
    103           it != m_ReceiveProcessors.end(); 
    104           ++it ) 
    105     { 
    106         (*it)->handleBusReset(); 
    107     } 
    108     for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    109           it != m_TransmitProcessors.end(); 
    110           ++it ) 
    111     { 
    112         (*it)->handleBusReset(); 
    113     } 
    114 
     87// void 
     88// StreamProcessorManager::handleBusReset(Ieee1394Service &s) 
     89// { 
     90// //     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Handle bus reset on service %p...\n", this, &s); 
     91// //  
     92// //     bool handled_at_least_one = false; 
     93// //     // note that all receive streams are gone once a device is unplugged 
     94// //  
     95// //     // synchronize with the wait lock 
     96// //     Util::MutexLockHelper lock(*m_WaitLock); 
     97// //  
     98// //     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) got wait lock...\n", this); 
     99// //     // cause all SP's to bail out 
     100// //     for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     101// //           it != m_ReceiveProcessors.end(); 
     102// //           ++it ) 
     103// //     { 
     104// //         if(&s == &((*it)->getParent().get1394Service())) { 
     105// //             debugOutput(DEBUG_LEVEL_NORMAL, 
     106// //                         "issue busreset on receive SPM on channel %d\n", 
     107// //                         (*it)->getChannel()); 
     108// //             (*it)->handleBusReset(); 
     109// //             handled_at_least_one = true; 
     110// //         } else { 
     111// //             debugOutput(DEBUG_LEVEL_NORMAL, 
     112// //                         "skipping receive SPM on channel %d since not on service %p\n", 
     113// //                         (*it)->getChannel(), &s); 
     114// //         } 
     115// //     } 
     116// //     for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     117// //           it != m_TransmitProcessors.end(); 
     118// //           ++it ) 
     119// //     { 
     120// //         if(&s == &((*it)->getParent().get1394Service())) { 
     121// //             debugOutput(DEBUG_LEVEL_NORMAL, 
     122// //                         "issue busreset on transmit SPM on channel %d\n", 
     123// //                         (*it)->getChannel()); 
     124// //             (*it)->handleBusReset(); 
     125// //             handled_at_least_one = true; 
     126// //         } else { 
     127// //             debugOutput(DEBUG_LEVEL_NORMAL, 
     128// //                         "skipping transmit SPM on channel %d since not on service %p\n", 
     129// //                         (*it)->getChannel(), &s); 
     130// //         } 
     131// //     } 
     132// //  
     133// //     // FIXME: we request shutdown for now. 
     134// //     m_shutdown_needed = handled_at_least_one; 
     135// } 
    115136 
    116137void 
     
    346367            it != m_TransmitProcessors.end(); 
    347368            ++it ) { 
     369        if ((*it)->inError()) { 
     370            debugOutput(DEBUG_LEVEL_VERBOSE, "SP %p in error state\n", *it); 
     371            return false; 
     372        } 
    348373        if (!(*it)->isDryRunning()) { 
    349374            if(!(*it)->scheduleStartDryRunning(-1)) { 
     
    358383            it != m_ReceiveProcessors.end(); 
    359384            ++it ) { 
     385        if ((*it)->inError()) { 
     386            debugOutput(DEBUG_LEVEL_VERBOSE, "SP %p in error state\n", *it); 
     387            return false; 
     388        } 
    360389        if (!(*it)->isDryRunning()) { 
    361390            if(!(*it)->scheduleStartDryRunning(-1)) { 
     
    750779            it != m_ReceiveProcessors.end(); 
    751780            ++it ) { 
    752             ready &= ((*it)->isDryRunning() || (*it)->isStopped() || (*it)->isWaitingForStream()); 
     781            ready &= ((*it)->isDryRunning() || (*it)->isStopped() || (*it)->isWaitingForStream() || (*it)->inError()); 
    753782        } 
    754783        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    755784            it != m_TransmitProcessors.end(); 
    756785            ++it ) { 
    757             ready &= ((*it)->isDryRunning() || (*it)->isStopped() || (*it)->isWaitingForStream()); 
     786            ready &= ((*it)->isDryRunning() || (*it)->isStopped() || (*it)->isWaitingForStream() || (*it)->inError()); 
    758787        } 
    759788        SleepRelativeUsec(125); 
     
    779808          it != m_ReceiveProcessors.end(); 
    780809          ++it ) { 
    781         if(!(*it)->scheduleStopDryRunning(-1)) { 
     810        if ((*it)->inError()) { 
     811            debugOutput(DEBUG_LEVEL_VERBOSE, "SP %p in error state\n", *it); 
     812        } else if(!(*it)->scheduleStopDryRunning(-1)) { 
    782813            debugError("%p->scheduleStopDryRunning(-1) failed\n", *it); 
    783814            return false; 
     
    787818          it != m_TransmitProcessors.end(); 
    788819          ++it ) { 
    789         if(!(*it)->scheduleStopDryRunning(-1)) { 
     820        if ((*it)->inError()) { 
     821            debugOutput(DEBUG_LEVEL_VERBOSE, "SP %p in error state\n", *it); 
     822        } else if(!(*it)->scheduleStopDryRunning(-1)) { 
    790823            debugError("%p->scheduleStopDryRunning(-1) failed\n", *it); 
    791824            return false; 
     
    800833            it != m_ReceiveProcessors.end(); 
    801834            ++it ) { 
    802             ready &= (*it)->isStopped(); 
     835            ready &= ((*it)->isStopped() || (*it)->inError()); 
    803836        } 
    804837        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
    805838            it != m_TransmitProcessors.end(); 
    806839            ++it ) { 
    807             ready &= (*it)->isStopped(); 
     840            ready &= ((*it)->isStopped() || (*it)->inError()); 
    808841        } 
    809842        SleepRelativeUsec(125); 
     
    895928    if(m_shutdown_needed) return false; 
    896929    bool xrun_occurred = false; 
     930    bool in_error = false; 
    897931    bool period_not_ready = true; 
    898932 
     
    947981        debugOutputExtreme(DEBUG_LEVEL_VERBOSE, " period not ready? %d...\n", period_not_ready); 
    948982 
    949         // check for underruns on the ISO side, 
     983        // check for underruns/errors on the ISO side, 
    950984        // those should make us bail out of the wait loop 
    951985        for ( StreamProcessorVectorIterator it = m_ReceiveProcessors.begin(); 
     
    954988            // a xrun has occurred on the Iso side 
    955989            xrun_occurred |= (*it)->xrunOccurred(); 
     990            in_error |= (*it)->inError(); 
    956991        } 
    957992        for ( StreamProcessorVectorIterator it = m_TransmitProcessors.begin(); 
     
    960995            // a xrun has occurred on the Iso side 
    961996            xrun_occurred |= (*it)->xrunOccurred(); 
    962         } 
    963         if(xrun_occurred) break; 
    964         // FIXME: make sure we also exit this loop when something else happens (e.g. signal, iso error) 
    965  
    966         // if we have to shutdown due to some async event (busreset), do so 
    967         if(m_shutdown_needed) break; 
     997            in_error |= (*it)->inError(); 
     998        } 
     999        if(xrun_occurred | in_error | m_shutdown_needed) break; 
    9681000    } 
    9691001 
    9701002    if(xrun_occurred) { 
    9711003        debugOutput( DEBUG_LEVEL_VERBOSE, "exit due to xrun...\n"); 
     1004    } 
     1005    if(in_error) { 
     1006        debugOutput( DEBUG_LEVEL_VERBOSE, "exit due to error...\n"); 
     1007        m_shutdown_needed = true; 
    9721008    } 
    9731009 
  • branches/libffado-2.0/src/libstreaming/StreamProcessorManager.h

    r1263 r1292  
    6262                           unsigned int rate, unsigned int nb_buffers); 
    6363    virtual ~StreamProcessorManager(); 
    64  
    65     void handleBusReset(); 
    6664 
    6765    bool prepare(); ///< to be called after the processors are registered 
     
    116114    bool transfer(); 
    117115    bool transfer(enum StreamProcessor::eProcessorType); 
     116 
     117    // for bus reset handling 
     118    void lockWaitLoop() {m_WaitLock->Lock();}; 
     119    void unlockWaitLoop() {m_WaitLock->Unlock();}; 
     120 
    118121private: 
    119122    bool transferSilence(); 
  • branches/libffado-2.0/src/libutil/PosixMutex.cpp

    r1267 r1292  
    4949PosixMutex::PosixMutex() 
    5050{ 
     51    m_id = "?"; 
    5152    pthread_mutexattr_t attr; 
    5253    pthread_mutexattr_init(&attr); 
     
    6465} 
    6566 
     67PosixMutex::PosixMutex(std::string id) 
     68{ 
     69    m_id = id; 
     70    pthread_mutexattr_t attr; 
     71    pthread_mutexattr_init(&attr); 
     72    #ifdef DEBUG 
     73        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); 
     74    #else 
     75        pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); 
     76    #endif 
     77    pthread_mutex_init(&m_mutex, &attr); 
     78    pthread_mutexattr_destroy(&attr); 
     79 
     80    #if DEBUG_LOCK_COLLISION_TRACING 
     81    m_locked_by = NULL; 
     82    #endif 
     83} 
     84 
    6685PosixMutex::~PosixMutex() 
    6786{ 
     
    7392{ 
    7493    int err; 
    75     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) lock\n", this); 
     94    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) lock\n", m_id.c_str(), this); 
    7695    #if DEBUG_LOCK_COLLISION_TRACING 
    7796    if(TryLock()) { 
     
    84103 
    85104        debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, 
    86                     "(%p) %s obtained lock\n", 
    87                     this, name); 
     105                    "(%s, %p) %s obtained lock\n", 
     106                    m_id.c_str(), this, name); 
    88107        return; 
    89108    } else { 
     
    97116        debugGetFunctionNameFromAddr(m_locked_by, name2, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN); 
    98117 
    99         debugWarning("(%p) lock collision: %s wants lock, %s has lock\n", 
    100                     this, name1, name2); 
     118        debugWarning("(%s, %p) lock collision: %s wants lock, %s has lock\n", 
     119                    m_id.c_str(), this, name1, name2); 
    101120        if((err = pthread_mutex_lock(&m_mutex))) { 
    102121            if (err == EDEADLK) { 
    103                 debugError("Resource deadlock detected\n"); 
     122                debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this); 
    104123                debugPrintBacktrace(10); 
    105124            } else { 
    106                 debugError("Error locking the mutex: %d\n", err); 
     125                debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err); 
    107126            } 
    108127        } else { 
    109             debugWarning("(%p) lock collision: %s got lock (from %s?)\n", 
    110                         this, name1, name2); 
     128            debugWarning("(%s, %p) lock collision: %s got lock (from %s?)\n", 
     129                        m_id.c_str(), this, name1, name2); 
    111130        } 
    112131    } 
     
    115134    if((err = pthread_mutex_lock(&m_mutex))) { 
    116135        if (err == EDEADLK) { 
    117             debugError("Resource deadlock detected\n"); 
     136            debugError("(%s, %p) Resource deadlock detected\n", m_id.c_str(), this); 
    118137            debugPrintBacktrace(10); 
    119138        } else { 
    120             debugError("Error locking the mutex: %d\n", err); 
     139            debugError("(%s, %p) Error locking the mutex: %d\n", m_id.c_str(), this, err); 
    121140        } 
    122141    } 
     
    130149PosixMutex::TryLock() 
    131150{ 
    132     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) trying to lock\n", this); 
     151    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) trying to lock\n", m_id.c_str(), this); 
    133152    return pthread_mutex_trylock(&m_mutex) == 0; 
    134153} 
     
    137156PosixMutex::isLocked() 
    138157{ 
    139     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) checking lock\n", this); 
     158    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) checking lock\n", m_id.c_str(), this); 
    140159    int res = pthread_mutex_trylock(&m_mutex); 
    141160    if(res == 0) { 
     
    146165            // this means that the current thread already has the lock, 
    147166            // iow it's locked. 
    148             debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) lock taken by current thread\n", this); 
     167            debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) lock taken by current thread\n", m_id.c_str(), this); 
    149168        } else if(res == EBUSY) { 
    150             debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) lock taken\n", this); 
     169            debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) lock taken\n", m_id.c_str(), this); 
    151170        } else { 
    152             debugError("Bogus error code: %d\n", res); 
     171            debugError("(%s, %p) Bogus error code: %d\n", m_id.c_str(), this, res); 
    153172        } 
    154173        return true; 
     
    159178PosixMutex::Unlock() 
    160179{ 
    161     debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%p) unlock\n", this); 
     180    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, "(%s, %p) unlock\n", m_id.c_str(), this); 
    162181    #if DEBUG_LOCK_COLLISION_TRACING 
    163182    // unlocking 
     
    168187    debugGetFunctionNameFromAddr(unlocker, name, DEBUG_LOCK_COLLISION_TRACING_NAME_MAXLEN); 
    169188    debugOutput(DEBUG_LEVEL_ULTRA_VERBOSE, 
    170                 "(%p) %s releases lock\n", 
    171                 this, name); 
     189                "(%s, %p) %s releases lock\n", 
     190                m_id.c_str(), this, name); 
    172191    #endif 
    173192 
     
    175194    int err; 
    176195    if((err = pthread_mutex_unlock(&m_mutex))) { 
    177         debugError("Error unlocking the mutex: %d\n", err); 
     196        debugError("(%s, %p) Error unlocking the mutex: %d\n", m_id.c_str(), this, err); 
    178197    } 
    179198    #else 
     
    185204PosixMutex::show() 
    186205{ 
    187     debugOutput(DEBUG_LEVEL_NORMAL, "(%p) mutex (%s)\n", this, (isLocked() ? "Locked" : "Unlocked")); 
     206    debugOutput(DEBUG_LEVEL_NORMAL, "(%s, %p) mutex (%s)\n", m_id.c_str(), this, (isLocked() ? "Locked" : "Unlocked")); 
    188207} 
    189208 
  • branches/libffado-2.0/src/libutil/PosixMutex.h

    r1172 r1292  
    2929#include "Mutex.h" 
    3030#include <pthread.h> 
     31#include <string> 
    3132 
    3233#include "debugmodule/debugmodule.h" 
     
    4344public: 
    4445    PosixMutex(); 
     46    PosixMutex(std::string id); 
    4547    virtual ~PosixMutex(); 
    4648 
     
    6062    pthread_mutex_t m_mutex; 
    6163 
     64    std::string m_id; 
     65 
    6266    #if DEBUG_LOCK_COLLISION_TRACING 
    6367    void *m_locked_by; 
  • branches/libffado-2.0/src/libutil/PosixThread.cpp

    r1096 r1292  
    7474    } 
    7575 
    76     debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: start %p\n", obj); 
     76    debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) ThreadHandler: start %p\n", obj->m_id.c_str(), obj); 
    7777 
    7878    // If Init succeed start the thread loop 
    7979    bool res = true; 
    8080    while (obj->fRunning && res) { 
    81         debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "ThreadHandler: run %p\n", obj); 
     81        debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "(%s) ThreadHandler: run %p\n", obj->m_id.c_str(), obj); 
    8282        res = runnable->Execute(); 
    8383        pthread_testcancel(); 
    8484    } 
    8585 
    86     debugOutput( DEBUG_LEVEL_VERBOSE, "ThreadHandler: exit %p\n", obj); 
     86    debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) ThreadHandler: exit %p\n", obj->m_id.c_str(), obj); 
    8787    return 0; 
    8888} 
     
    9595    if (fRealTime) { 
    9696 
    97         debugOutput( DEBUG_LEVEL_VERBOSE, "Create RT thread %p with priority %d\n", this, fPriority); 
     97        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Create RT thread %p with priority %d\n", m_id.c_str(), this, fPriority); 
    9898 
    9999        /* Get the client thread to run as an RT-FIFO 
     
    139139        return 0; 
    140140    } else { 
    141         debugOutput( DEBUG_LEVEL_VERBOSE, "Create non RT thread %p\n", this); 
     141        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Create non RT thread %p\n", m_id.c_str(), this); 
    142142 
    143143        if ((res = pthread_create(&fThread, 0, ThreadHandler, this))) { 
     
    153153{ 
    154154    if (fThread) { // If thread has been started 
    155         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Kill %p (thread: %p)\n", this, fThread); 
     155        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Kill %p (thread: %p)\n", m_id.c_str(), this, fThread); 
    156156        void* status; 
    157157        pthread_cancel(fThread); 
    158158        pthread_join(fThread, &status); 
    159         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Killed %p (thread: %p)\n", this, fThread); 
     159        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Killed %p (thread: %p)\n", m_id.c_str(), this, fThread); 
    160160        return 0; 
    161161    } else { 
     
    167167{ 
    168168    if (fThread) { // If thread has been started 
    169         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Stop %p (thread: %p)\n", this, fThread); 
     169        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Stop %p (thread: %p)\n", m_id.c_str(), this, fThread); 
    170170        void* status; 
    171171        fRunning = false; // Request for the thread to stop 
    172172        pthread_join(fThread, &status); 
    173         debugOutput( DEBUG_LEVEL_VERBOSE, "PosixThread::Stopped %p (thread: %p)\n", this, fThread); 
     173        debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Stopped %p (thread: %p)\n", m_id.c_str(), this, fThread); 
    174174        return 0; 
    175175    } else { 
     
    182182    struct sched_param rtparam; 
    183183    int res; 
    184     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Aquire realtime, prio %d\n", this, fPriority); 
     184    debugOutput( DEBUG_LEVEL_VERBOSE, "(%s, %p) Aquire realtime, prio %d\n", m_id.c_str(), this, fPriority); 
    185185 
    186186    if (!fThread) 
     
    211211    struct sched_param rtparam; 
    212212    int res; 
    213     debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Drop realtime\n", this); 
     213    debugOutput( DEBUG_LEVEL_VERBOSE, "(%s, %p) Drop realtime\n", m_id.c_str(), this); 
    214214 
    215215    if (!fThread) 
  • branches/libffado-2.0/src/libutil/PosixThread.h

    r864 r1292  
    8787        {} 
    8888 
     89        PosixThread(RunnableInterface* runnable, std::string id, bool real_time, int priority, int cancellation) 
     90                : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation) 
     91        {} 
     92        PosixThread(RunnableInterface* runnable, std::string id) 
     93                : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(PTHREAD_CANCEL_DEFERRED) 
     94        {} 
     95        PosixThread(RunnableInterface* runnable, std::string id, int cancellation) 
     96                : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(cancellation) 
     97        {} 
     98 
    8999        virtual ~PosixThread() 
    90100        {} 
  • branches/libffado-2.0/src/libutil/Thread.h

    r1263 r1292  
    5656#include "Atomic.h" 
    5757#include <pthread.h> 
     58#include <string> 
    5859 
    5960namespace Util 
     
    9495    public: 
    9596 
    96         Thread(RunnableInterface* runnable): fRunnable(runnable) 
     97        Thread(RunnableInterface* runnable) 
     98        : fRunnable(runnable) 
     99        , m_id( "UNKNOWN" ) 
     100        {} 
     101        Thread(RunnableInterface* runnable, std::string id) 
     102        : fRunnable(runnable) 
     103        , m_id( id ) 
    97104        {} 
    98105        virtual ~Thread() 
     
    113120 
    114121        virtual void setVerboseLevel(int l) 
    115             {   setDebugLevel(l); 
    116                 debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l ); 
     122            { 
     123                setDebugLevel(l); 
     124                debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Setting verbose level to %d...\n", m_id.c_str(), l ); 
    117125            }; 
    118126    protected: 
    119             DECLARE_DEBUG_MODULE; 
     127        std::string m_id; 
     128        DECLARE_DEBUG_MODULE; 
    120129 
    121130}; 
  • branches/libffado-2.0/src/libutil/Watchdog.cpp

    r1165 r1292  
    205205        return false; 
    206206    } 
    207     m_HartbeatThread = new Util::PosixThread(m_HartbeatTask, false, 
     207    m_HartbeatThread = new Util::PosixThread(m_HartbeatTask, "WDGHBT", false, 
    208208                                             0, PTHREAD_CANCEL_ASYNCHRONOUS); 
    209209    if(!m_HartbeatThread) { 
     
    221221        return false; 
    222222    } 
    223     m_CheckThread = new Util::PosixThread(m_CheckTask, false, 
     223    m_CheckThread = new Util::PosixThread(m_CheckTask,"WDGCHK", false, 
    224224                                          0, PTHREAD_CANCEL_ASYNCHRONOUS); 
    225225    if(!m_CheckThread) {