void TimerThreadMultimap::notifyAndRemove( const timespec t )
{
  TRACE;
  ScopedLock sl( m_mutex );
  if ( not m_isRunning ) return;

  timespec ts;
  std::multimap<timespec, UserEntry, timespec_cmp> tmp;
  std::multimap<timespec, UserEntry>::iterator it;
  std::pair<std::multimap<timespec, UserEntry>::iterator,
            std::multimap<timespec, UserEntry>::iterator> ret;

  ret = m_users.equal_range( t );

  /// @todo modify key values in multimap, must be a better way
  tmp.clear();
  for ( it = ret.first; it != ret.second; it++ ) {
    it->second.user->timerExpired();
    if ( it->second.periodTime.tv_sec != 0 or it->second.periodTime.tv_nsec != 0) {

      clock_gettime( CLOCK_REALTIME, &ts );
      ts = timespecAdd( ts, it->second.periodTime );

      tmp.insert(std::pair<timespec, UserEntry>( ts, it->second ) );
      m_condVar.signal();
    }
  }
  m_users.erase( t );
  m_users.insert( tmp.begin(), tmp.end() );
}
示例#2
0
void
timespecSetAbstime(struct timespec *abstime, struct timespec *delay)
{
	CLOCK now;

	CLOCK_GET(&now);
	CLOCK_SET_TIMESPEC(abstime, &now);
	timespecAdd(abstime, delay);
}
void TimerThreadMultimap::addTimerUser( TimerUser* user,
                                const timespec expiration,
                                const timespec periodTime )
{
  TRACE;
  ScopedLock sl( m_mutex );
  if ( not m_isRunning ) return;

  timespec ts;
  clock_gettime( CLOCK_REALTIME, &ts );
  ts = timespecAdd( ts, expiration );

  UserEntry userEntry = { periodTime, user };
  m_users.insert( std::pair<timespec, UserEntry>( ts, userEntry ) );

  m_condVar.signal();
}