Changeset 1043
- Timestamp:
- 04/26/08 08:20:56 (15 years ago)
- Files:
-
- trunk/libffado/src/dice/dice_avdevice.cpp (modified) (1 diff)
- trunk/libffado/src/libieee1394/ieee1394service.cpp (modified) (16 diffs)
- trunk/libffado/src/libieee1394/ieee1394service.h (modified) (4 diffs)
- trunk/libffado/src/libstreaming/StreamProcessorManager.cpp (modified) (1 diff)
- trunk/libffado/src/libutil/Mutex.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/dice/dice_avdevice.cpp
r1023 r1043 931 931 swap_value |= m_notifier->getStart(); 932 932 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 )) { 935 936 debugWarning("Could not register ourselves as device owner\n"); 936 937 return false; trunk/libffado/src/libieee1394/ieee1394service.cpp
r1027 r1043 36 36 #include "libutil/SystemTimeSource.h" 37 37 #include "libutil/Watchdog.h" 38 #include "libutil/PosixMutex.h" 38 39 39 40 #include <errno.h> … … 48 49 49 50 Ieee1394Service::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 ) 51 55 , m_port( -1 ) 52 56 , m_threadRunning( false ) … … 72 76 73 77 Ieee1394Service::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 ) 75 82 , m_port( -1 ) 76 83 , m_threadRunning( false ) … … 118 125 raw1394_destroy_handle( m_handle ); 119 126 } 127 delete m_handle_lock; 128 120 129 if ( m_resetHandle ) { 121 130 raw1394_destroy_handle( m_resetHandle ); … … 309 318 Ieee1394Service::getNodeCount() 310 319 { 320 Util::MutexLockHelper lock(*m_handle_lock); 311 321 return raw1394_get_nodecount( m_handle ); 312 322 } 313 323 314 324 nodeid_t Ieee1394Service::getLocalNodeId() { 325 Util::MutexLockHelper lock(*m_handle_lock); 315 326 return raw1394_get_local_id(m_handle) & 0x3F; 316 327 } … … 397 408 fb_quadlet_t* buffer ) 398 409 { 410 Util::MutexLockHelper lock(*m_handle_lock); 399 411 using namespace std; 400 412 if ( raw1394_read( m_handle, nodeId, addr, length*4, buffer ) == 0 ) { … … 443 455 fb_quadlet_t* data ) 444 456 { 457 Util::MutexLockHelper lock(*m_handle_lock); 445 458 using namespace std; 446 459 … … 477 490 return value; 478 491 #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; 484 499 return value_new; 485 500 #else … … 506 521 debugOutput(DEBUG_LEVEL_VERBOSE,"before = 0x%016llX\n", buffer); 507 522 } 508 509 523 #endif 510 524 511 525 // 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 } 517 540 518 541 #ifdef DEBUG … … 524 547 #endif 525 548 526 *result =byteSwap_octlet(*result);549 *result = byteSwap_octlet(*result); 527 550 528 551 return (retval == 0); … … 535 558 unsigned int* resp_len ) 536 559 { 560 // FIXME: this requires transactionBlockClose to unlock 561 m_handle_lock->Lock(); 537 562 for (int i = 0; i < len; ++i) { 538 563 buf[i] = ntohl( buf[i] ); … … 559 584 { 560 585 avc1394_transaction_block_close( m_handle ); 586 m_handle_lock->Unlock(); 561 587 return true; 562 588 } … … 865 891 debugOutput(DEBUG_LEVEL_VERBOSE, "Allocating ISO channel using generic method...\n" ); 866 892 893 Util::MutexLockHelper lock(*m_handle_lock); 867 894 struct ChannelInfo cinfo; 868 895 … … 925 952 926 953 debugOutput(DEBUG_LEVEL_VERBOSE, "Allocating ISO channel using IEC61883 CMP...\n" ); 954 Util::MutexLockHelper lock(*m_handle_lock); 927 955 928 956 struct ChannelInfo cinfo; … … 979 1007 bool Ieee1394Service::freeIsoChannel(signed int c) { 980 1008 debugOutput(DEBUG_LEVEL_VERBOSE, "Freeing ISO channel %d...\n", c ); 1009 Util::MutexLockHelper lock(*m_handle_lock); 981 1010 982 1011 if (c < 0 || c > 63) { … … 1082 1111 signed int Ieee1394Service::getAvailableBandwidth() { 1083 1112 quadlet_t buffer; 1113 Util::MutexLockHelper lock(*m_handle_lock); 1084 1114 signed int result = raw1394_read (m_handle, raw1394_get_irm_id (m_handle), 1085 1115 CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE, trunk/libffado/src/libieee1394/ieee1394service.h
r1027 r1043 28 28 #include "fbtypes.h" 29 29 #include "libutil/Functors.h" 30 #include "libutil/Mutex.h" 30 31 31 32 #include "debugmodule/debugmodule.h" … … 226 227 227 228 bool transactionBlockClose(); 228 229 // FIXME: private for thread safety !! 229 230 raw1394handle_t getHandle() {return m_handle;}; 230 231 … … 240 241 **/ 241 242 unsigned int getGeneration() { 243 Util::MutexLockHelper lock(*m_handle_lock); 242 244 return raw1394_get_generation( m_handle ); 243 245 } … … 314 316 315 317 raw1394handle_t m_handle; 318 Util::Mutex* m_handle_lock; 316 319 raw1394handle_t m_resetHandle; 317 320 raw1394handle_t m_util_handle; // a handle for operations from the rt thread trunk/libffado/src/libstreaming/StreamProcessorManager.cpp
r1005 r1043 873 873 874 874 // grab the wait lock 875 // this ensures that bus reset handling doesn't interfere 875 876 m_WaitLock.Lock(); 876 877 trunk/libffado/src/libutil/Mutex.h
r967 r1043 45 45 }; 46 46 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 */ 55 class MutexLockHelper 56 { 57 public: 58 MutexLockHelper(Mutex &m) 59 : m_mutex( m ) 60 {m.Lock();}; 61 virtual ~MutexLockHelper() {m_mutex.Unlock();}; 62 private: 63 Mutex &m_mutex; 64 }; 65 47 66 } // end of namespace 48 67