Changeset 1080

Show
Ignore:
Timestamp:
05/01/08 07:33:48 (13 years ago)
Author:
ppalmers
Message:

use Mutex class for locking

Files:

Legend:

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

    r1027 r1080  
    2727#include "ieee1394service.h" 
    2828#include "libutil/PosixThread.h" 
     29#include "libutil/PosixMutex.h" 
    2930#include "libutil/Atomic.h" 
    3031#include "libutil/Watchdog.h" 
     
    7273    , m_realtime ( false ) 
    7374    , m_priority ( 0 ) 
     75    , m_update_lock( new Util::PosixMutex() ) 
    7476    , m_busreset_functor ( NULL) 
    7577    , m_unhandled_busreset ( false ) 
    7678{ 
    7779    debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 
    78     pthread_mutex_init(&mb_update_lock, NULL); 
    7980} 
    8081 
     
    9899    , m_realtime ( rt ) 
    99100    , m_priority ( prio ) 
     101    , m_update_lock( new Util::PosixMutex() ) 
    100102    , m_busreset_functor ( NULL) 
    101103    , m_unhandled_busreset ( false ) 
    102104{ 
    103105    debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 
    104     pthread_mutex_init(&mb_update_lock, NULL); 
    105106} 
    106107 
     
    117118        delete m_busreset_functor; 
    118119    } 
    119     pthread_mutex_destroy(&mb_update_lock)
     120    delete m_update_lock
    120121} 
    121122 
     
    150151        return false; 
    151152    } 
     153 
     154    // sleep until the thread has updated at least once 
     155    Util::SystemTimeSource::SleepUsecRelative(IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC*2); 
    152156    return true; 
    153157} 
     
    157161{ 
    158162    debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Init values...\n", this ); 
    159     pthread_mutex_lock(&mb_update_lock); 
     163    Util::MutexLockHelper lock(*m_update_lock); 
     164 
    160165    // initialize the 'prev ctr' values 
    161166    uint64_t local_time; 
     
    165170        if(!m_Parent.readCycleTimerReg(&m_cycle_timer_prev, &local_time)) { 
    166171            debugError("Could not read cycle timer register\n"); 
    167             pthread_mutex_unlock(&mb_update_lock); 
    168172            return false; 
    169173        } 
     
    191195    if(!initDLL()) { 
    192196        debugError("(%p) Could not init DLL\n", this); 
    193         pthread_mutex_unlock(&mb_update_lock); 
    194197        return false; 
    195198    } 
     
    197200    m_first_run = true; 
    198201#endif 
    199     pthread_mutex_unlock(&mb_update_lock); 
    200202    debugOutput( DEBUG_LEVEL_VERBOSE, "ready...\n" ); 
    201203    return true; 
     
    275277} 
    276278 
     279/* 
     280 * call with lock held 
     281 */ 
    277282bool 
    278283CycleTimerHelper::initDLL() { 
     
    283288    if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { 
    284289        debugError("Could not read cycle timer register\n"); 
    285         pthread_mutex_unlock(&mb_update_lock); 
    286290        return false; 
    287291    } 
     
    319323CycleTimerHelper::Execute() 
    320324{ 
    321     debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "Execute %p...\n", this); 
     325    debugOutput( DEBUG_LEVEL_VERBOSE, "Execute %p...\n", this); 
    322326 
    323327    #ifdef DEBUG 
     
    326330    if(diff < 100) { 
    327331        debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 
    328                            "(%p) short loop detected (%d usec), cnt: %d\n", 
    329                            this, diff, m_successive_short_loops); 
     332                        "(%p) short loop detected (%d usec), cnt: %d\n", 
     333                        this, diff, m_successive_short_loops); 
    330334        m_successive_short_loops++; 
    331335        if(m_successive_short_loops > 100) { 
     
    342346    if (!m_first_run) { 
    343347        // wait for the next update period 
    344         #if DEBUG_EXTREME_ENABLE 
     348        //#if DEBUG_EXTREME_ENABLE 
     349        #ifdef DEBUG 
    345350        ffado_microsecs_t now = Util::SystemTimeSource::getCurrentTimeAsUsecs(); 
    346351        int sleep_time = m_sleep_until - now; 
    347         debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, "(%p) Sleep until %lld/%f (now: %lld, diff=%d) ...\n", 
     352        debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Sleep until %lld/%f (now: %lld, diff=%d) ...\n", 
    348353                    this, m_sleep_until, m_next_time_usecs, now, sleep_time); 
    349354        #endif 
    350355        Util::SystemTimeSource::SleepUsecAbsolute(m_sleep_until); 
    351         debugOutputExtreme( DEBUG_LEVEL_VERY_VERBOSE, " (%p) back...\n", this); 
     356        debugOutput( DEBUG_LEVEL_VERBOSE, " (%p) back...\n", this); 
    352357    } 
    353358 
     
    364369    // (looks like a non-atomic update of the register) 
    365370    do { 
     371        debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) reading cycle timer register...\n", this); 
    366372        if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { 
    367373            debugError("Could not read cycle timer register\n"); 
     
    386392    // also grab it after reading the CTR register such that the jitter between 
    387393    // wakeup and read is as small as possible 
    388     pthread_mutex_lock(&mb_update_lock); 
     394    Util::MutexLockHelper lock(*m_update_lock); 
    389395 
    390396    // // simulate a random scheduling delay between (0-10ms) 
     
    396402                    "(%p) Skipping DLL update due to unhandled busreset\n", this); 
    397403        m_sleep_until += m_usecs_per_update; 
    398         pthread_mutex_unlock(&mb_update_lock); 
    399404        // keep the thread running 
    400405        return true; 
     
    413418        if(!initDLL()) { 
    414419            debugError("(%p) Could not init DLL\n", this); 
    415             pthread_mutex_unlock(&mb_update_lock); 
    416420            return false; 
    417421        } 
     
    550554    // then we can update the current index 
    551555    m_current_shadow_idx = next_idx; 
    552  
    553     pthread_mutex_unlock(&mb_update_lock); 
    554556 
    555557#ifdef DEBUG 
  • trunk/libffado/src/libieee1394/CycleTimerHelper.h

    r1027 r1080  
    5555 
    5656#include "libutil/Functors.h" 
     57#include "libutil/Mutex.h" 
    5758 
    5859#include "debugmodule/debugmodule.h" 
     
    151152    bool            m_realtime; 
    152153    unsigned int    m_priority; 
    153     pthread_mutex_t mb_update_lock; 
     154    Util::Mutex*    m_update_lock; 
    154155 
    155156    // busreset handling