coding style fixes

master
Denes Matetelki 14 years ago
parent b328c6f9dd
commit 6792784464

@ -27,7 +27,8 @@ public:
* If currently locked, the call shall return immediately.
* @returns Zero if a lock acquired. Otherwise, an error number.
*/
int tryLock(const long int intervalSec = 0, const long int intervalNSec = 0);
int tryLock( const long int intervalSec = 0,
const long int intervalNSec = 0 );
pthread_mutex_t* getPThreadMutex();

@ -9,18 +9,16 @@ class Timer
public:
Timer(const int signal = SIGALRM );
virtual ~Timer() {}
virtual void timerExpired() {}
Timer( const int signal = SIGALRM );
virtual ~Timer() {}
virtual void timerExpired() {}
virtual void periodicTimerExpired() {}
void createTimer(const time_t interval_sec,
const long interval_nsec = 0,
const time_t initExpr_sec = 0,
const long initExpr_nsec = 0);
void createTimer( const time_t interval_sec,
const long interval_nsec = 0,
const time_t initExpr_sec = 0,
const long initExpr_nsec = 0 );
void wait();
@ -33,8 +31,8 @@ private:
// after turning on all warnings, gcc reports that the class has pointer
// data members (time_t, which is an int by the way) so copy ctor and
// assign op shall be inmplemented
Timer(const Timer& timer);
Timer& operator=(const Timer&) { return *this; }
Timer( const Timer& timer );
Timer& operator=( const Timer& );
int m_signal;
struct sigaction m_sigAction;

@ -14,8 +14,8 @@ class TimerUser
public:
virtual void timerExpired( void ) = 0;
virtual void timerDestroyed( void ) = 0;
virtual void timerExpired() = 0;
virtual void timerDestroyed() = 0;
virtual ~TimerUser() {}
@ -46,7 +46,7 @@ public:
void addTimerUser( TimerUser* user,
const timespec expiration,
const timespec periodTime = timespec_ctor() );
const timespec periodTime = timespec_init() );
bool removeTimerUser( TimerUser* timerUser );
@ -58,10 +58,10 @@ private:
void notifyAndRemove( const timespec t );
void* run( void );
void* run();
// ctor function
inline static timespec timespec_ctor() {
// init function
inline static timespec timespec_init() {
timespec tmp = { 0, 0 };
return tmp;
};
@ -69,7 +69,7 @@ private:
// compare class for the multimap
class timespec_cmp {
public :
bool operator()(const timespec& a, const timespec& b) const {
bool operator()( const timespec& a, const timespec& b ) const {
if ( a.tv_sec < b.tv_sec ) return true;
if ( a.tv_sec > b.tv_sec ) return false;
return a.tv_nsec < b.tv_nsec;

@ -1,18 +1,19 @@
#include "Mutex.hpp"
#include "Common.hpp"
#include "Common.hpp"
#include <time.h>
pthread_mutex_t& MutexCtor(pthread_mutex_t& mutex)
pthread_mutex_t& MutexCtor( pthread_mutex_t& mutex )
{
pthread_mutex_init( &mutex, 0 );
return mutex;
}
Mutex::Mutex(int kind)
: m_mutex(MutexCtor(m_mutex))
Mutex::Mutex( int kind )
: m_mutex( MutexCtor( m_mutex ) )
{
TRACE;
if ( kind != PTHREAD_MUTEX_DEFAULT ) {
@ -45,14 +46,14 @@ int Mutex::unlock()
}
int Mutex::tryLock(const long int intervalSec, const long int intervalNSec)
int Mutex::tryLock( const long int intervalSec, const long int intervalNSec )
{
TRACE;
if ( intervalSec == 0 and intervalNSec == 0 ) {
return pthread_mutex_trylock ( &m_mutex );
return pthread_mutex_trylock( &m_mutex );
} else {
timespec tspec = addTotimespec( intervalSec, intervalSec );
return pthread_mutex_timedlock ( &m_mutex, &tspec );
return pthread_mutex_timedlock( &m_mutex, &tspec );
}
}

@ -7,31 +7,31 @@
#include <string.h> // strerror
struct sigaction& sigActionCtor(struct sigaction &sigAct, const int signal)
struct sigaction& sigActionInit( struct sigaction &sigAct, const int signal )
{
sigAct.sa_flags = SA_SIGINFO;
sigemptyset(&sigAct.sa_mask);
sigemptyset( &sigAct.sa_mask );
sigaddset( &sigAct.sa_mask, signal );
sigaction( signal, &sigAct, 0 );
return sigAct;
}
Timer::Timer(const Timer& timer)
: m_signal(timer.m_signal)
, m_sigAction(sigActionCtor( m_sigAction , m_signal ) )
, m_timerId(0)
, m_periodic(false)
, m_running(true)
Timer::Timer( const Timer& timer )
: m_signal( timer.m_signal )
, m_sigAction( sigActionInit( m_sigAction , m_signal ) )
, m_timerId( 0 )
, m_periodic( false )
, m_running( true )
{
TRACE;
}
void Timer::createTimer(const time_t interval_sec,
const long interval_nsec,
const time_t initExpr_sec,
const long initExpr_nsec)
void Timer::createTimer( const time_t interval_sec,
const long interval_nsec,
const time_t initExpr_sec,
const long initExpr_nsec )
{
TRACE;
@ -40,10 +40,7 @@ void Timer::createTimer(const time_t interval_sec,
sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = m_signal;
sigev.sigev_value.sival_ptr = &m_timerId;
if ( timer_create( CLOCK_MONOTONIC, &sigev, &m_timerId ) == -1 ) {
LOG ( Logger::FINEST, "Error from timer_create: " /*strerror(errno)*/ );
return;
}
timer_create( CLOCK_MONOTONIC, &sigev, &m_timerId );
// arm it
struct itimerspec its;
@ -53,11 +50,7 @@ void Timer::createTimer(const time_t interval_sec,
its.it_interval.tv_nsec = initExpr_nsec;
if ( initExpr_sec != 0 or initExpr_nsec != 0 ) m_periodic = true;
if ( timer_settime( m_timerId, 0, &its, 0 ) == -1 ) {
LOG ( Logger::FINEST, "Error from timer_settime: " /*strerror(errno)*/ );
return;
}
timer_settime( m_timerId, 0, &its, 0 );
}
@ -97,12 +90,19 @@ void Timer::gracefulStop()
}
Timer::Timer(const int signal)
: m_signal(signal)
, m_sigAction(sigActionCtor( m_sigAction , m_signal ) )
, m_timerId(0)
, m_periodic(false)
, m_running(true)
Timer::Timer( const int signal )
: m_signal( signal )
, m_sigAction( sigActionInit( m_sigAction , m_signal ) )
, m_timerId( 0 )
, m_periodic( false )
, m_running( true )
{
TRACE;
}
Timer& Timer::operator=( const Timer& )
{
TRACE;
return *this;
}

@ -10,7 +10,7 @@
TimerThread::TimerThread()
: Thread()
, m_mutex()
, m_condVar(m_mutex)
, m_condVar( m_mutex )
, m_users()
{
TRACE;
@ -23,9 +23,9 @@ TimerThread::~TimerThread()
}
void TimerThread::addTimerUser(TimerUser* user,
const time_t expiration,
const time_t periodTime)
void TimerThread::addTimerUser( TimerUser* user,
const time_t expiration,
const time_t periodTime )
{
TRACE;
@ -37,8 +37,8 @@ void TimerThread::addTimerUser(TimerUser* user,
void TimerThread::addTimerUser( TimerUser* user,
const timespec expiration,
const timespec periodTime )
const timespec expiration,
const timespec periodTime )
{
TRACE;
ScopedLock sl( m_mutex );
@ -46,7 +46,7 @@ void TimerThread::addTimerUser( TimerUser* user,
timespec ts;
clock_gettime( CLOCK_REALTIME, &ts );
ts = timespecAdd ( ts, expiration );
ts = timespecAdd( ts, expiration );
UserEntry userEntry = { periodTime, user };
m_users.insert( std::pair<timespec, UserEntry>( ts, userEntry ) );
@ -62,12 +62,12 @@ bool TimerThread::removeTimerUser( TimerUser* timerUser )
if ( not m_isRunning ) return false;
std::multimap<timespec, UserEntry>::iterator it, tmp;
bool found(false);
bool found( false );
for ( it = m_users.begin(); it != m_users.end(); ) {
if ( (it->second.user) == timerUser ) {
if ( it->second.user == timerUser ) {
tmp = it++;
m_users.erase(tmp);
m_users.erase( tmp );
m_condVar.signal();
found = true; // one user can be registered multiple times
} else {
@ -133,7 +133,7 @@ void* TimerThread::run( void )
}
m_mutex.unlock();
if ( not m_isRunning) return 0;
if ( not m_isRunning ) return 0;
nextExpiration = m_users.begin()->first;
clock_gettime( CLOCK_REALTIME, &ts );

Loading…
Cancel
Save