Changeset 1080 for trunk/libffado/src/libieee1394
- Timestamp:
- 05/01/08 07:33:48 (16 years ago)
- Files:
-
- trunk/libffado/src/libieee1394/CycleTimerHelper.cpp (modified) (19 diffs)
- trunk/libffado/src/libieee1394/CycleTimerHelper.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/libieee1394/CycleTimerHelper.cpp
r1027 r1080 27 27 #include "ieee1394service.h" 28 28 #include "libutil/PosixThread.h" 29 #include "libutil/PosixMutex.h" 29 30 #include "libutil/Atomic.h" 30 31 #include "libutil/Watchdog.h" … … 72 73 , m_realtime ( false ) 73 74 , m_priority ( 0 ) 75 , m_update_lock( new Util::PosixMutex() ) 74 76 , m_busreset_functor ( NULL) 75 77 , m_unhandled_busreset ( false ) 76 78 { 77 79 debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 78 pthread_mutex_init(&mb_update_lock, NULL);79 80 } 80 81 … … 98 99 , m_realtime ( rt ) 99 100 , m_priority ( prio ) 101 , m_update_lock( new Util::PosixMutex() ) 100 102 , m_busreset_functor ( NULL) 101 103 , m_unhandled_busreset ( false ) 102 104 { 103 105 debugOutput( DEBUG_LEVEL_VERBOSE, "Create %p...\n", this); 104 pthread_mutex_init(&mb_update_lock, NULL);105 106 } 106 107 … … 117 118 delete m_busreset_functor; 118 119 } 119 pthread_mutex_destroy(&mb_update_lock);120 delete m_update_lock; 120 121 } 121 122 … … 150 151 return false; 151 152 } 153 154 // sleep until the thread has updated at least once 155 Util::SystemTimeSource::SleepUsecRelative(IEEE1394SERVICE_CYCLETIMER_DLL_UPDATE_INTERVAL_USEC*2); 152 156 return true; 153 157 } … … 157 161 { 158 162 debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) Init values...\n", this ); 159 pthread_mutex_lock(&mb_update_lock); 163 Util::MutexLockHelper lock(*m_update_lock); 164 160 165 // initialize the 'prev ctr' values 161 166 uint64_t local_time; … … 165 170 if(!m_Parent.readCycleTimerReg(&m_cycle_timer_prev, &local_time)) { 166 171 debugError("Could not read cycle timer register\n"); 167 pthread_mutex_unlock(&mb_update_lock);168 172 return false; 169 173 } … … 191 195 if(!initDLL()) { 192 196 debugError("(%p) Could not init DLL\n", this); 193 pthread_mutex_unlock(&mb_update_lock);194 197 return false; 195 198 } … … 197 200 m_first_run = true; 198 201 #endif 199 pthread_mutex_unlock(&mb_update_lock);200 202 debugOutput( DEBUG_LEVEL_VERBOSE, "ready...\n" ); 201 203 return true; … … 275 277 } 276 278 279 /* 280 * call with lock held 281 */ 277 282 bool 278 283 CycleTimerHelper::initDLL() { … … 283 288 if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { 284 289 debugError("Could not read cycle timer register\n"); 285 pthread_mutex_unlock(&mb_update_lock);286 290 return false; 287 291 } … … 319 323 CycleTimerHelper::Execute() 320 324 { 321 debugOutput Extreme( DEBUG_LEVEL_VERY_VERBOSE, "Execute %p...\n", this);325 debugOutput( DEBUG_LEVEL_VERBOSE, "Execute %p...\n", this); 322 326 323 327 #ifdef DEBUG … … 326 330 if(diff < 100) { 327 331 debugOutputExtreme(DEBUG_LEVEL_VERY_VERBOSE, 328 329 332 "(%p) short loop detected (%d usec), cnt: %d\n", 333 this, diff, m_successive_short_loops); 330 334 m_successive_short_loops++; 331 335 if(m_successive_short_loops > 100) { … … 342 346 if (!m_first_run) { 343 347 // wait for the next update period 344 #if DEBUG_EXTREME_ENABLE 348 //#if DEBUG_EXTREME_ENABLE 349 #ifdef DEBUG 345 350 ffado_microsecs_t now = Util::SystemTimeSource::getCurrentTimeAsUsecs(); 346 351 int sleep_time = m_sleep_until - now; 347 debugOutput Extreme( 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", 348 353 this, m_sleep_until, m_next_time_usecs, now, sleep_time); 349 354 #endif 350 355 Util::SystemTimeSource::SleepUsecAbsolute(m_sleep_until); 351 debugOutput Extreme( DEBUG_LEVEL_VERY_VERBOSE, " (%p) back...\n", this);356 debugOutput( DEBUG_LEVEL_VERBOSE, " (%p) back...\n", this); 352 357 } 353 358 … … 364 369 // (looks like a non-atomic update of the register) 365 370 do { 371 debugOutput( DEBUG_LEVEL_VERBOSE, "(%p) reading cycle timer register...\n", this); 366 372 if(!readCycleTimerWithRetry(&cycle_timer, &local_time, 10)) { 367 373 debugError("Could not read cycle timer register\n"); … … 386 392 // also grab it after reading the CTR register such that the jitter between 387 393 // wakeup and read is as small as possible 388 pthread_mutex_lock(&mb_update_lock);394 Util::MutexLockHelper lock(*m_update_lock); 389 395 390 396 // // simulate a random scheduling delay between (0-10ms) … … 396 402 "(%p) Skipping DLL update due to unhandled busreset\n", this); 397 403 m_sleep_until += m_usecs_per_update; 398 pthread_mutex_unlock(&mb_update_lock);399 404 // keep the thread running 400 405 return true; … … 413 418 if(!initDLL()) { 414 419 debugError("(%p) Could not init DLL\n", this); 415 pthread_mutex_unlock(&mb_update_lock);416 420 return false; 417 421 } … … 550 554 // then we can update the current index 551 555 m_current_shadow_idx = next_idx; 552 553 pthread_mutex_unlock(&mb_update_lock);554 556 555 557 #ifdef DEBUG trunk/libffado/src/libieee1394/CycleTimerHelper.h
r1027 r1080 55 55 56 56 #include "libutil/Functors.h" 57 #include "libutil/Mutex.h" 57 58 58 59 #include "debugmodule/debugmodule.h" … … 151 152 bool m_realtime; 152 153 unsigned int m_priority; 153 pthread_mutex_t mb_update_lock;154 Util::Mutex* m_update_lock; 154 155 155 156 // busreset handling