[Cppunit-cvs] cppunit2/src/opentest sharedmemorytransport.cpp,1.7,1.8
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2006-03-08 22:01:26
|
Update of /cvsroot/cppunit/cppunit2/src/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10881/src/opentest Modified Files: sharedmemorytransport.cpp Log Message: * took out the DuplicateHandle used for reference couting (a different handle was returned, and the previous handle became invalid). Explicit life cycle management is used instead. Index: sharedmemorytransport.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/opentest/sharedmemorytransport.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** sharedmemorytransport.cpp 7 Mar 2006 23:02:56 -0000 1.7 --- sharedmemorytransport.cpp 8 Mar 2006 22:01:20 -0000 1.8 *************** *** 62,80 **** } - AutoHandle( const AutoHandle &other ) - : handle_( 0 ) - { - if ( other.handle_ ) - { - ::DuplicateHandle( GetCurrentProcess(), - other.handle_, - GetCurrentProcess(), - &handle_, - 0, - TRUE, // handle may be inherited by child process - DUPLICATE_SAME_ACCESS ); - } - } - ~AutoHandle() { --- 62,65 ---- *************** *** 88,92 **** } ! AutoHandle &operator =( HANDLE handle ) { if ( handle != handle_ ) --- 73,77 ---- } ! AutoHandle &reset( HANDLE handle ) { if ( handle != handle_ ) *************** *** 99,108 **** } - AutoHandle &operator =( const AutoHandle &other ) - { - return *this = other.handle_; - } - private: HANDLE handle_; }; --- 84,91 ---- } private: + AutoHandle( const AutoHandle &other ); + AutoHandle &operator =( const AutoHandle &other ); + HANDLE handle_; }; *************** *** 178,185 **** { SECURITY_ATTRIBUTES sa; ! hEvent_ = ::CreateEvent( setChildProcessCanInheritSecurity(sa), FALSE, FALSE, ! name ); return get(); } --- 161,168 ---- { SECURITY_ATTRIBUTES sa; ! hEvent_.reset( ::CreateEvent( setChildProcessCanInheritSecurity(sa), FALSE, FALSE, ! name ) ); return get(); } *************** *** 199,206 **** { SECURITY_ATTRIBUTES sa; ! hEvent_ = ::CreateEvent( setChildProcessCanInheritSecurity(sa), TRUE, FALSE, ! 0 ); } }; --- 182,189 ---- { SECURITY_ATTRIBUTES sa; ! hEvent_.reset( ::CreateEvent( setChildProcessCanInheritSecurity(sa), TRUE, FALSE, ! 0 ) ); } }; *************** *** 347,351 **** CppTL::Mutex messagesToSendLock_; CppTL::Mutex messagesToDispatchLock_; ! std::vector<AutoHandle> handles_; std::vector<HANDLE> waitObjects_; SharedMemoryConfig config_; --- 330,334 ---- CppTL::Mutex messagesToSendLock_; CppTL::Mutex messagesToDispatchLock_; ! std::vector<HANDLE> handles_; std::vector<HANDLE> waitObjects_; SharedMemoryConfig config_; *************** *** 356,359 **** --- 339,343 ---- AutoHandle thread_; SharedData *shared_; + CppTL::ConstString transportName_; unsigned int id_; TCHAR nameBuffer_[32]; *************** *** 374,377 **** --- 358,362 ---- CPPTL_ASSERT_MESSAGE( nameLength_ < sizeof(nameBuffer_)-1, "buffer overflow" ); + transportName_ = nameLength_; createSharedMemoryRegion(); *************** *** 411,414 **** --- 396,405 ---- { stopThread(); + while ( !handles_.empty() ) + { + ::CloseHandle( handles_.back() ); + handles_.pop_back(); + } + handles_.clear(); } *************** *** 421,430 **** DWORD fileMappingSize = sizeof(SharedData) + 2*config_.bufferSize_; ! hSharedMemory_ = ::CreateFileMapping( INVALID_HANDLE_VALUE, &saAttr, // inherits handle PAGE_READWRITE, 0, // max size (hi-order) fileMappingSize, // max size (low-order) ! nameBuffer_ ); // name if ( hSharedMemory_ == 0 ) throw SharedMemoryError( "Failed to create shared memory region." ); --- 412,421 ---- DWORD fileMappingSize = sizeof(SharedData) + 2*config_.bufferSize_; ! hSharedMemory_.reset( ::CreateFileMapping( INVALID_HANDLE_VALUE, &saAttr, // inherits handle PAGE_READWRITE, 0, // max size (hi-order) fileMappingSize, // max size (low-order) ! nameBuffer_ ) ); // name if ( hSharedMemory_ == 0 ) throw SharedMemoryError( "Failed to create shared memory region." ); *************** *** 447,451 **** SharedMemoryTransportImpl::transportName() const { ! return nameBuffer_; // @todo change this to work if TCHAR = wchar_t } --- 438,442 ---- SharedMemoryTransportImpl::transportName() const { ! return transportName_.c_str(); } *************** *** 454,460 **** SharedMemoryTransportImpl::openSharedMemoryRegion() { ! hSharedMemory_ = ::OpenFileMapping( FILE_MAP_ALL_ACCESS, TRUE, ! nameBuffer_ ); if ( hSharedMemory_ == 0 ) throw SharedMemoryError( "Failed to open specified shared memory region." ); --- 445,451 ---- SharedMemoryTransportImpl::openSharedMemoryRegion() { ! hSharedMemory_.reset( ::OpenFileMapping( FILE_MAP_ALL_ACCESS, TRUE, ! nameBuffer_ ) ); if ( hSharedMemory_ == 0 ) throw SharedMemoryError( "Failed to open specified shared memory region." ); *************** *** 490,495 **** SharedMemoryTransportImpl::autoManage( HANDLE handle ) { ! AutoHandle autoHandle( handle ); ! handles_.push_back( autoHandle ); return handle; } --- 481,485 ---- SharedMemoryTransportImpl::autoManage( HANDLE handle ) { ! handles_.push_back( handle ); return handle; } *************** *** 572,578 **** { DWORD threadId; ! thread_ = ::CreateThread( 0, 0, &SharedMemoryTransportImpl::threadBootstrap, ! this, 0, &threadId ); if ( thread_ == 0 ) throw SharedMemoryError( "Failed to create thread." ); --- 562,568 ---- { DWORD threadId; ! thread_.reset( ::CreateThread( 0, 0, &SharedMemoryTransportImpl::threadBootstrap, ! this, 0, &threadId ) ); if ( thread_ == 0 ) throw SharedMemoryError( "Failed to create thread." ); *************** *** 642,645 **** --- 632,636 ---- { OPENTEST_SHMEM_LOG( "thread aborted with an unspecified exception." ); + throw; } } *************** *** 665,671 **** --- 656,664 ---- RemoteMessages messages; { + OPENTEST_SHMEM_LOG( "Messaging thread acquiring messagesToSendLock_" ); CppTL::Mutex::ScopedLockGuard guard( messagesToSendLock_ ); messagesToSend_.swap( messages ); } + OPENTEST_SHMEM_LOG( "Messaging thread released messagesToSendLock_" ); BufferInfo &buffer = getWriteBuffer(); *************** *** 687,694 **** --- 680,689 ---- || getWriteBuffer().stream_.packets().hasPendingMessage() ) { + OPENTEST_SHMEM_LOG( "Acquiring shared_->mutex_" ); ScopedMutexLock guard( shared_->mutex_ ); readPendingData(); writePendingData(); } + OPENTEST_SHMEM_LOG( "Released shared_->mutex_" ); } |