Spacing
parent
fcf6eb2631
commit
a798e874fe
|
|
@ -116,25 +116,32 @@ Condition::~Condition() {
|
|||
|
||||
void Condition::wait() {
|
||||
// Locking done outside of this function
|
||||
if ( pthread_cond_wait( &mCondition, mMutex.getMutex() ) < 0 )
|
||||
throw ThreadException( stringtf( "Unable to wait pthread condition: %s", strerror(errno) ) );
|
||||
if ( pthread_cond_wait(&mCondition, mMutex.getMutex()) < 0 )
|
||||
throw ThreadException(stringtf("Unable to wait pthread condition: %s", strerror(errno)));
|
||||
}
|
||||
|
||||
bool Condition::wait( int secs ) {
|
||||
bool Condition::wait(int secs) {
|
||||
// Locking done outside of this function
|
||||
Debug( 8, "Waiting for %d seconds", secs );
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
if ( pthread_cond_timedwait( &mCondition, mMutex.getMutex(), &timeout ) < 0 && errno != ETIMEDOUT )
|
||||
throw ThreadException( stringtf( "Unable to timedwait pthread condition: %s", strerror(errno) ) );
|
||||
return( errno != ETIMEDOUT );
|
||||
Debug(8, "Waiting for %d seconds", secs);
|
||||
struct timespec timeout = getTimeout(secs);
|
||||
if (
|
||||
( pthread_cond_timedwait(&mCondition, mMutex.getMutex(), &timeout) < 0 )
|
||||
&&
|
||||
( errno != ETIMEDOUT )
|
||||
)
|
||||
throw ThreadException(stringtf("Unable to timedwait pthread condition: %s", strerror(errno)));
|
||||
return errno != ETIMEDOUT;
|
||||
}
|
||||
|
||||
bool Condition::wait( double secs ) {
|
||||
// Locking done outside of this function
|
||||
struct timespec timeout = getTimeout( secs );
|
||||
if ( pthread_cond_timedwait( &mCondition, mMutex.getMutex(), &timeout ) < 0 && errno != ETIMEDOUT )
|
||||
if (
|
||||
(pthread_cond_timedwait( &mCondition, mMutex.getMutex(), &timeout ) < 0)
|
||||
&&
|
||||
(errno != ETIMEDOUT) )
|
||||
throw ThreadException( stringtf( "Unable to timedwait pthread condition: %s", strerror(errno) ) );
|
||||
return( errno != ETIMEDOUT );
|
||||
return errno != ETIMEDOUT;
|
||||
}
|
||||
|
||||
void Condition::signal() {
|
||||
|
|
@ -177,11 +184,11 @@ template <class T> const T ThreadData<T>::getUpdatedValue(double secs) const {
|
|||
mMutex.lock();
|
||||
mChanged = false;
|
||||
//do {
|
||||
mCondition.wait( secs );
|
||||
mCondition.wait(secs);
|
||||
//} while ( !mChanged );
|
||||
const T valueCopy = mValue;
|
||||
mMutex.unlock();
|
||||
Debug(9, "Got value update, %p", this );
|
||||
Debug(9, "Got value update, %p", this);
|
||||
return valueCopy;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,9 @@ private:
|
|||
pthread_t pid() { return( pthread_self() ); }
|
||||
#endif
|
||||
public:
|
||||
explicit ThreadException( const std::string &message ) : Exception( stringtf("(%d) ", (long int)pid())+message ) {
|
||||
explicit ThreadException(const std::string &message) :
|
||||
Exception(stringtf("(%d) ", (long int)pid())+message)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -169,38 +171,36 @@ private:
|
|||
mutable Condition mCondition;
|
||||
|
||||
public:
|
||||
__attribute__((used)) ThreadData() : mValue(0), mCondition( mMutex ) {
|
||||
__attribute__((used)) ThreadData() :
|
||||
mValue(0), mCondition(mMutex)
|
||||
{
|
||||
mChanged = false;
|
||||
}
|
||||
explicit __attribute__((used)) ThreadData( T value ) : mValue( value ), mCondition( mMutex ) {
|
||||
explicit __attribute__((used)) ThreadData(T value) :
|
||||
mValue(value), mCondition(mMutex) {
|
||||
mChanged = false;
|
||||
}
|
||||
//~ThreadData() {}
|
||||
|
||||
__attribute__((used)) operator T() const
|
||||
{
|
||||
return( getValue() );
|
||||
__attribute__((used)) operator T() const {
|
||||
return getValue();
|
||||
}
|
||||
__attribute__((used)) const T operator=( const T value )
|
||||
{
|
||||
return( setValue( value ) );
|
||||
__attribute__((used)) const T operator=( const T value ) {
|
||||
return setValue(value);
|
||||
}
|
||||
|
||||
__attribute__((used)) const T getValueImmediate() const
|
||||
{
|
||||
return( mValue );
|
||||
__attribute__((used)) const T getValueImmediate() const {
|
||||
return mValue;
|
||||
}
|
||||
__attribute__((used)) T setValueImmediate( const T value )
|
||||
{
|
||||
return( mValue = value );
|
||||
__attribute__((used)) T setValueImmediate( const T value ) {
|
||||
return mValue = value;
|
||||
}
|
||||
__attribute__((used)) const T getValue() const;
|
||||
__attribute__((used)) T setValue( const T value );
|
||||
__attribute__((used)) const T getUpdatedValue() const;
|
||||
__attribute__((used)) const T getUpdatedValue( double secs ) const;
|
||||
__attribute__((used)) const T getUpdatedValue( int secs ) const;
|
||||
__attribute__((used)) void updateValueSignal( const T value );
|
||||
__attribute__((used)) void updateValueBroadcast( const T value );
|
||||
__attribute__((used)) const T getUpdatedValue(double secs) const;
|
||||
__attribute__((used)) const T getUpdatedValue(int secs) const;
|
||||
__attribute__((used)) void updateValueSignal(const T value);
|
||||
__attribute__((used)) void updateValueBroadcast(const T value);
|
||||
};
|
||||
|
||||
class Thread {
|
||||
|
|
|
|||
Loading…
Reference in New Issue