示例#1
0
 safeprint&  operator<<(const std::string& msg) {
     cout_lock.lock_shared();
     std::cout << msg;
     cout_lock.unlock();
     //std::cout << "public safe" << std::endl;
     return *this;
 }
示例#2
0
bool TrackManager::removeTrack( int pIndex)
{
	mySharedMutex.lock();
	bool isRemoved = myController->getTrackList()->removeObjById( pIndex);
	myController->createIndex();
	mySharedMutex.unlock();
	return isRemoved;
}
	void StatisticsMultiplexerSync::newDataAvailable() throw() {
		listenersLock.lock_shared();
		for( size_t i = listeners.size(); i--; ) {
			ListenerData& cur = listeners[i];
			cur.listener->newDataAvailable();
		}
		listenersLock.unlock_shared();
	}
	void StatisticsMultiplexerSync::notifyAvailableStatisticsChange( const std::vector<std::shared_ptr<Statistic> > & statistics, bool addedStatistics, bool removedStatistics ) throw() {
		listenersLock.lock_shared();
		for( size_t i = listeners.size(); i--; ) {
			ListenerData& cur = listeners[i];
			cur.listener->notifyAvailableStatisticsChange( statistics, addedStatistics, removedStatistics );
		}
		lastStatistics = & statistics;
		listenersLock.unlock_shared();
	}
	void StatisticsMultiplexerSync::unregisterListener( StatisticsMultiplexerListener * listener ) throw() {
		listenersLock.lock();
		for( size_t i = listeners.size(); i--; ) {
			if( listeners[i].listener == listener ) {
				listeners.erase(listeners.begin() + i);
			}
		}
		listenersLock.unlock();
	}
示例#6
0
void f1()
{
  time_point t0 = Clock::now();
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(m.try_lock_until(Clock::now() + ms(300) + ms(1000)) == true);
  time_point t1 = Clock::now();
  m.unlock();
  ns d = t1 - t0 - ms(250);
  BOOST_TEST(d < ns(5000000)+ms(1000)); // within 5ms
}
	void StatisticsMultiplexerSync::registerListener( StatisticsMultiplexerListener * listener ) throw() {
		listenersLock.lock();
		for( size_t i = listeners.size(); i--; ) if( listeners[i].listener == listener ) goto doUnlock;
		listeners.emplace_back( listener );
		if( lastStatistics != nullptr ){
			listener->notifyAvailableStatisticsChange( *lastStatistics, true, false );
		}
	doUnlock:
		listenersLock.unlock();
	}
示例#8
0
int main()
{
  m.lock();
  boost::thread t(f);
  boost::this_thread::sleep_for(ms(250));
  m.unlock();
  t.join();

  return boost::report_errors();
}
示例#9
0
int main()
{
  m.lock();
  boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
  boost::this_thread::sleep_for(ms(250));
#else
#endif
  m.unlock();
  t.join();

  return boost::report_errors();
}
示例#10
0
void thread3_func_workaround()
{
  while (true)
  {
    if (mutex.timed_lock_shared(boost::posix_time::milliseconds(200)))
    {
      std::cout << "Shared lock acquired" << std::endl
        << "Test successful" << std::endl;
      mutex.unlock_shared();
      break;
    }
    boost::this_thread::sleep(boost::posix_time::milliseconds(100));
  }
}
示例#11
0
bool TransferInfo::Finished() {
  checkbook_mutex_.lock_shared();
  bool finished = true;
  for (int i = 0; i < checkbook_->slice_size(); ++i) {
    VLOG(4) << i << " checkbook slice: " << checkbook_->slice(i).finished();
    if (!checkbook_->slice(i).finished()) {
      finished = false;
      VLOG(1) << "slice: " << i << " unfinished";
      checkbook_mutex_.unlock_shared();
      return false;
    }
  }
  checkbook_mutex_.unlock_shared();
  return true;
}
示例#12
0
int TrackManager::addTrack( const string pFileName, CTrackInfo & pTrackData)
{
	mySharedMutex.lock();
	MP3Data * currentMP3Data = myController->addMP3( pFileName.c_str());
	int id = currentMP3Data->getId();
	if( id != INVALID_INDEX)
	{
		pTrackData.mIndex = currentMP3Data->getId();
		pTrackData.mAlbum = currentMP3Data->getAlbum();
		pTrackData.mInterpret = currentMP3Data->getArtist();
		pTrackData.mTitle = currentMP3Data->getTitle();
	}
	myController->createIndex();
	mySharedMutex.unlock();	
	return id;
}
示例#13
0
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
  t0 = Clock::now();
  m.lock();
  t1 = Clock::now();
  m.unlock();
#else
  //time_point t0 = Clock::now();
  m.lock();
  //time_point t1 = Clock::now();
  m.unlock();
  //ns d = t1 - t0 - ms(250);
  //BOOST_TEST(d < max_diff);
#endif
}
void f2()
{
  time_point t0 = Clock::now();
  BOOST_TEST(m.try_lock_for(ms(250)) == false);
  time_point t1 = Clock::now();
  ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(d < ns(5000000)+ms(1000)); // within 5ms
}
示例#15
0
void f()
{
#if defined BOOST_THREAD_USES_CHRONO
  time_point t0 = Clock::now();
  m.lock();
  time_point t1 = Clock::now();
  m.unlock();
  ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#else
  //time_point t0 = Clock::now();
  m.lock();
  //time_point t1 = Clock::now();
  m.unlock();
  //ns d = t1 - t0 - ms(250);
  // This test is spurious as it depends on the time the thread system switches the threads
  //BOOST_TEST(d < ns(2500000)+ms(1000)); // within 2.5ms
#endif
}
示例#16
0
 void get ()
 {
    try
    {
       _m.lock() ;
    }
    catch(...)
    {
       SDB_ASSERT ( FALSE, "SLatch get failed" ) ;
    }
 }
示例#17
0
 void release ()
 {
    try
    {
       _m.unlock() ;
    }
    catch(...)
    {
       SDB_ASSERT ( FALSE, "SLatch release failed" ) ;
    }
 }
示例#18
0
 void get_shared ()
 {
    try
    {
       _m.lock_shared () ;
    }
    catch(...)
    {
       SDB_ASSERT ( FALSE, "SLatch get shared failed" ) ;
    }
 }
示例#19
0
 void release_shared ()
 {
    try
    {
       _m.unlock_shared() ;
    }
    catch(...)
    {
       SDB_ASSERT ( FALSE, "SLatch release shared failed" ) ;
    }
 }
示例#20
0
int TrackManager::trackSearchStart( const string & pTitleBeginn, TSearchID & pID)
{
	if( pTitleBeginn == "")
	{
		myController->getTrackList()->begin();
		pID = ALL_TRACKS_SEARCH_ID;
		return myController->getTrackList()->getLength();
	}
	else
	{
		mySharedMutex.lock();
		searchResultCount++;
		searchResultList[searchResultCount] = myController->getSearchResult( pTitleBeginn.c_str());
		pID = searchResultCount;
		std::cout << "search started, searchID: " << pID << std::endl;
		unsigned int length = searchResultList[searchResultCount]->getLength();
		mySharedMutex.unlock();
		return length;
	}
}
示例#21
0
 BOOLEAN try_get_shared()
 {
    try
    {
       return _m.timed_lock_shared ( boost::posix_time::milliseconds ( 0 ) ) ;
    }
    catch(...)
    {
       SDB_ASSERT ( FALSE, "SLatch try get shared failed" ) ;
    }
    return FALSE ;
 }
示例#22
0
void thread2_func()
{
  int i (0);
  while (true)
  {
    if (mutex.timed_lock(boost::posix_time::milliseconds(500)))
    {
      std::cout << "Unique lock acquired" << std::endl
        << "Test successful" << std::endl;
      mutex.unlock();
      break;
    }
    ++i;
    if (i == 100)
    {
      std::cout << "Test failed. App is deadlocked" << std::endl;
      break;
    }
    boost::this_thread::sleep(boost::posix_time::seconds(1));
  }
}
示例#23
0
int main()
{
  m.lock();
  boost::thread t(f);
#if defined BOOST_THREAD_USES_CHRONO
  time_point t2 = Clock::now();
  boost::this_thread::sleep_for(ms(250));
  time_point t3 = Clock::now();
#else
#endif
  m.unlock();
  t.join();

#if defined BOOST_THREAD_USES_CHRONO
  ns sleep_time = t3 - t2;
  ns d_ns = t1 - t0 - sleep_time;
  ms d_ms = boost::chrono::duration_cast<boost::chrono::milliseconds>(d_ns);
  // BOOST_TEST_GE(d_ms.count(), 0);
  BOOST_THREAD_TEST_IT(d_ms, max_diff);
  BOOST_THREAD_TEST_IT(d_ns, ns(max_diff));
#endif

  return boost::report_errors();
}
示例#24
0
bool TrackManager::trackGetNext( TSearchID pID, CTrackInfo & pNextTrack)
{
	MP3Data * t_Data = NULL;
	mySharedMutex.lock_shared();
	if(pID == ALL_TRACKS_SEARCH_ID) // Get whole track list
	{
		t_Data = myController->getTrackList()->getNext();
	
		if(t_Data != NULL)	// returns current iterator-item
		{
			pNextTrack.mAlbum = t_Data->getAlbum();
			pNextTrack.mInterpret = t_Data->getArtist();
			pNextTrack.mTitle = t_Data->getTitle();
			pNextTrack.mIndex = t_Data->getId();
			mySharedMutex.unlock_shared();
			return true;	// successfully retrieved item
		}
		else	// current iterator-item is NULL
		{
			mySharedMutex.unlock_shared();
			return false;
		}
	}
	else // get node list for the search-ID
	{	
		NodeList * t_searchResult = searchResultList[pID];

		if(t_searchResult)
		{
			t_Data = t_searchResult->getNext();

			if(t_Data != NULL) 
			{
				pNextTrack.mAlbum = t_Data->getAlbum();
				pNextTrack.mInterpret = t_Data->getArtist();
				pNextTrack.mTitle = t_Data->getTitle();
				pNextTrack.mIndex = t_Data->getId();
				mySharedMutex.unlock_shared();
				return true;
			}
			else
			{
				mySharedMutex.unlock_shared();
				return false;
			}
		}
		else
		{
			mySharedMutex.unlock_shared();
			return false;
		}

	}
}
示例#25
0
 safeprint&  operator<<(std::ostream& ) {
     cout_lock.lock_shared();
     std::cout << "public safe" << std::endl;
     cout_lock.unlock();
     return *this;
 }
示例#26
0
TopologyType RamTopology::registerType( const string& name ) throw() {
	TopologyType result;
	typesLock.lock_shared();
	IGNORE_EXCEPTIONS( result = typesByName.at( name ); );