Changeset 1043

Show
Ignore:
Timestamp:
04/26/08 08:20:56 (16 years ago)
Author:
ppalmers
Message:

- fix octlet byteswap bug for non-debug builds
- make Ieee1394Service thread safe

Files:

Legend:

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

    r1023 r1043  
    931931    swap_value |= m_notifier->getStart(); 
    932932 
    933     if (!get1394Service().lockCompareSwap64(  getNodeId() | 0xFFC0, addr, DICE_OWNER_NO_OWNER, 
    934                                        swap_value, &result )) { 
     933    if (!get1394Service().lockCompareSwap64(getNodeId() | 0xFFC0, 
     934                                            addr, DICE_OWNER_NO_OWNER, 
     935                                            swap_value, &result )) { 
    935936        debugWarning("Could not register ourselves as device owner\n"); 
    936937        return false; 
  • trunk/libffado/src/libieee1394/ieee1394service.cpp

    r1027 r1043  
    3636#include "libutil/SystemTimeSource.h" 
    3737#include "libutil/Watchdog.h" 
     38#include "libutil/PosixMutex.h" 
    3839 
    3940#include <errno.h> 
     
    4849 
    4950Ieee1394Service::Ieee1394Service() 
    50     : m_handle( 0 ), m_resetHandle( 0 ), m_util_handle( 0 ) 
     51    : m_handle( 0 ) 
     52    , m_handle_lock( new Util::PosixMutex() ) 
     53    , m_resetHandle( 0 ) 
     54    , m_util_handle( 0 ) 
    5155    , m_port( -1 ) 
    5256    , m_threadRunning( false ) 
     
    7276 
    7377Ieee1394Service::Ieee1394Service(bool rt, int prio) 
    74     : m_handle( 0 ), m_resetHandle( 0 ), m_util_handle( 0 ) 
     78    : m_handle( 0 ) 
     79    , m_handle_lock( new Util::PosixMutex() ) 
     80    , m_resetHandle( 0 ) 
     81    , m_util_handle( 0 ) 
    7582    , m_port( -1 ) 
    7683    , m_threadRunning( false ) 
     
    118125        raw1394_destroy_handle( m_handle ); 
    119126    } 
     127    delete m_handle_lock; 
     128 
    120129    if ( m_resetHandle ) { 
    121130        raw1394_destroy_handle( m_resetHandle ); 
     
    309318Ieee1394Service::getNodeCount() 
    310319{ 
     320    Util::MutexLockHelper lock(*m_handle_lock); 
    311321    return raw1394_get_nodecount( m_handle ); 
    312322} 
    313323 
    314324nodeid_t Ieee1394Service::getLocalNodeId() { 
     325    Util::MutexLockHelper lock(*m_handle_lock); 
    315326    return raw1394_get_local_id(m_handle) & 0x3F; 
    316327} 
     
    397408                       fb_quadlet_t* buffer ) 
    398409{ 
     410    Util::MutexLockHelper lock(*m_handle_lock); 
    399411    using namespace std; 
    400412    if ( raw1394_read( m_handle, nodeId, addr, length*4, buffer ) == 0 ) { 
     
    443455                        fb_quadlet_t* data ) 
    444456{ 
     457    Util::MutexLockHelper lock(*m_handle_lock); 
    445458    using namespace std; 
    446459 
     
    477490        return value; 
    478491    #elif __BYTE_ORDER == __LITTLE_ENDIAN 
    479         fb_octlet_t value_new; 
    480         fb_quadlet_t *in_ptr=reinterpret_cast<fb_quadlet_t *>(&value); 
    481         fb_quadlet_t *out_ptr=reinterpret_cast<fb_quadlet_t *>(&value_new); 
    482         *(out_ptr+1)=htonl(*(in_ptr)); 
    483         *(out_ptr)=htonl(*(in_ptr+1)); 
     492        fb_quadlet_t in_hi = (value >> 32) & 0xFFFFFFFF; 
     493        fb_quadlet_t in_lo = value & 0xFFFFFFFF; 
     494        in_hi = htonl(in_hi); 
     495        in_lo = htonl(in_lo); 
     496        fb_octlet_t value_new = in_lo; 
     497        value_new <<= 32; 
     498        value_new |= in_hi; 
    484499        return value_new; 
    485500    #else 
     
    506521        debugOutput(DEBUG_LEVEL_VERBOSE,"before = 0x%016llX\n", buffer); 
    507522    } 
    508  
    509523    #endif 
    510524 
    511525    // do endiannes swapping 
    512     compare_value=byteSwap_octlet(compare_value); 
    513     swap_value=byteSwap_octlet(swap_value); 
    514  
    515     int retval=raw1394_lock64(m_handle, nodeId, addr, RAW1394_EXTCODE_COMPARE_SWAP, 
    516                           swap_value, compare_value, result); 
     526    compare_value = byteSwap_octlet(compare_value); 
     527    swap_value    = byteSwap_octlet(swap_value); 
     528 
     529    // do separate locking here (no MutexLockHelper) since  
     530    // we use read_octlet in the DEBUG code in this function 
     531    m_handle_lock->Lock(); 
     532    int retval=raw1394_lock64(m_handle, nodeId, addr, 
     533                              RAW1394_EXTCODE_COMPARE_SWAP, 
     534                              swap_value, compare_value, result); 
     535    m_handle_lock->Unlock(); 
     536 
     537    if(retval) { 
     538        debugError("raw1394_lock64 failed: %s\n", strerror(errno)); 
     539    } 
    517540 
    518541    #ifdef DEBUG 
     
    524547    #endif 
    525548 
    526     *result=byteSwap_octlet(*result); 
     549    *result = byteSwap_octlet(*result); 
    527550 
    528551    return (retval == 0); 
     
    535558                                   unsigned int* resp_len ) 
    536559{ 
     560    // FIXME: this requires transactionBlockClose to unlock 
     561    m_handle_lock->Lock(); 
    537562    for (int i = 0; i < len; ++i) { 
    538563        buf[i] = ntohl( buf[i] ); 
     
    559584{ 
    560585    avc1394_transaction_block_close( m_handle ); 
     586    m_handle_lock->Unlock(); 
    561587    return true; 
    562588} 
     
    865891    debugOutput(DEBUG_LEVEL_VERBOSE, "Allocating ISO channel using generic method...\n" ); 
    866892 
     893    Util::MutexLockHelper lock(*m_handle_lock); 
    867894    struct ChannelInfo cinfo; 
    868895 
     
    925952 
    926953    debugOutput(DEBUG_LEVEL_VERBOSE, "Allocating ISO channel using IEC61883 CMP...\n" ); 
     954    Util::MutexLockHelper lock(*m_handle_lock); 
    927955 
    928956    struct ChannelInfo cinfo; 
     
    9791007bool Ieee1394Service::freeIsoChannel(signed int c) { 
    9801008    debugOutput(DEBUG_LEVEL_VERBOSE, "Freeing ISO channel %d...\n", c ); 
     1009    Util::MutexLockHelper lock(*m_handle_lock); 
    9811010 
    9821011    if (c < 0 || c > 63) { 
     
    10821111signed int Ieee1394Service::getAvailableBandwidth() { 
    10831112    quadlet_t buffer; 
     1113    Util::MutexLockHelper lock(*m_handle_lock); 
    10841114    signed int result = raw1394_read (m_handle, raw1394_get_irm_id (m_handle), 
    10851115        CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE, 
  • trunk/libffado/src/libieee1394/ieee1394service.h

    r1027 r1043  
    2828#include "fbtypes.h" 
    2929#include "libutil/Functors.h" 
     30#include "libutil/Mutex.h" 
    3031 
    3132#include "debugmodule/debugmodule.h" 
     
    226227 
    227228    bool transactionBlockClose(); 
    228  
     229// FIXME: private for thread safety !! 
    229230    raw1394handle_t getHandle() {return m_handle;}; 
    230231 
     
    240241     **/ 
    241242    unsigned int getGeneration() { 
     243        Util::MutexLockHelper lock(*m_handle_lock); 
    242244        return raw1394_get_generation( m_handle ); 
    243245    } 
     
    314316 
    315317    raw1394handle_t m_handle; 
     318    Util::Mutex*    m_handle_lock; 
    316319    raw1394handle_t m_resetHandle; 
    317320    raw1394handle_t m_util_handle; // a handle for operations from the rt thread 
  • trunk/libffado/src/libstreaming/StreamProcessorManager.cpp

    r1005 r1043  
    873873 
    874874    // grab the wait lock 
     875    // this ensures that bus reset handling doesn't interfere 
    875876    m_WaitLock.Lock(); 
    876877 
  • trunk/libffado/src/libutil/Mutex.h

    r967 r1043  
    4545}; 
    4646 
     47 
     48/** 
     49 * @brief A class to implement monitors 
     50 * Locks a mutex when an instance is created, 
     51 * unlocks it as soon as the instance is destroyed. 
     52 * when this class is created on the stack at function 
     53 * entry, this implements a monitor 
     54 */ 
     55class MutexLockHelper 
     56{ 
     57public: 
     58    MutexLockHelper(Mutex &m) 
     59    : m_mutex( m ) 
     60      {m.Lock();}; 
     61    virtual ~MutexLockHelper() {m_mutex.Unlock();}; 
     62private: 
     63    Mutex &m_mutex; 
     64}; 
     65 
    4766} // end of namespace 
    4867