git-svn-id: svn://db.shs.com.ru/pip@758 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -259,7 +259,7 @@ template<typename T> inline void piSwap(T & f, T & s) {T t = f; f = s; s = t;}
|
|||||||
/*! \brief Templated function for swap two values without "="
|
/*! \brief Templated function for swap two values without "="
|
||||||
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
* \details Example:\n \snippet piincludes.cpp swapBinary */
|
||||||
template<typename T> inline void piSwapBinary(T & f, T & s) {
|
template<typename T> inline void piSwapBinary(T & f, T & s) {
|
||||||
static size_t j = (sizeof(T) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(T);
|
size_t j = (sizeof(T) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(T);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
for (i = 0; i < j; ++i) {
|
for (i = 0; i < j; ++i) {
|
||||||
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
((size_t*)(&f))[i] ^= ((size_t*)(&s))[i];
|
||||||
@@ -274,7 +274,7 @@ template<typename T> inline void piSwapBinary(T & f, T & s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
template<> inline void piSwapBinary(const void *& f, const void *& s) {
|
||||||
static size_t j = (sizeof(void *) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(void *);
|
size_t j = (sizeof(void *) / sizeof(size_t)), bs = j * sizeof(size_t), bf = sizeof(void *);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
void * pf = const_cast<void*>(f), * ps = const_cast<void*>(s);
|
void * pf = const_cast<void*>(f), * ps = const_cast<void*>(s);
|
||||||
for (i = 0; i < j; ++i) {
|
for (i = 0; i < j; ++i) {
|
||||||
|
|||||||
@@ -464,8 +464,8 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
|
|||||||
|
|
||||||
|
|
||||||
PIVector<PIObject * > & PIObject::objects() {
|
PIVector<PIObject * > & PIObject::objects() {
|
||||||
static PIVector<PIObject * > ret;
|
static PIVector<PIObject * > * ret = new PIVector<PIObject * >();
|
||||||
return ret;
|
return *ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ PRIVATE_DEFINITION_END(PIMutex)
|
|||||||
|
|
||||||
|
|
||||||
PIMutex::PIMutex(): inited_(false) {
|
PIMutex::PIMutex(): inited_(false) {
|
||||||
|
//printf("new Mutex %p\n", this);
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PRIVATE->mutex = 0;
|
PRIVATE->mutex = 0;
|
||||||
#endif
|
#endif
|
||||||
@@ -60,6 +61,7 @@ PIMutex::PIMutex(): inited_(false) {
|
|||||||
|
|
||||||
|
|
||||||
PIMutex::~PIMutex() {
|
PIMutex::~PIMutex() {
|
||||||
|
//printf("del Mutex %p\n", this);
|
||||||
destroy();
|
destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ PIThread::~PIThread() {
|
|||||||
|
|
||||||
|
|
||||||
void PIThread::stop(bool wait) {
|
void PIThread::stop(bool wait) {
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
|
||||||
terminating = true;
|
terminating = true;
|
||||||
if (wait) waitForFinish();
|
if (wait) waitForFinish();
|
||||||
}
|
}
|
||||||
@@ -307,7 +307,7 @@ bool PIThread::startOnce() {
|
|||||||
|
|
||||||
|
|
||||||
void PIThread::terminate() {
|
void PIThread::terminate() {
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
|
||||||
#ifdef FREERTOS
|
#ifdef FREERTOS
|
||||||
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
|
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
|
||||||
stop(true);
|
stop(true);
|
||||||
@@ -335,7 +335,7 @@ void PIThread::terminate() {
|
|||||||
PRIVATE->thread = 0;
|
PRIVATE->thread = 0;
|
||||||
end();
|
end();
|
||||||
#endif
|
#endif
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_;
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ void PIThread::setPriority(PIThread::Priority prior) {
|
|||||||
|
|
||||||
|
|
||||||
bool PIThread::waitForFinish(int timeout_msecs) {
|
bool PIThread::waitForFinish(int timeout_msecs) {
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "PIThread::waitForFinish" << running_ << terminating << timeout_msecs;
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "PIThread::waitForFinish" << running_ << terminating << timeout_msecs;
|
||||||
if (!running_) return true;
|
if (!running_) return true;
|
||||||
if (timeout_msecs < 0) {
|
if (timeout_msecs < 0) {
|
||||||
while (running_)
|
while (running_)
|
||||||
@@ -445,23 +445,23 @@ void PIThread::__thread_func__() {
|
|||||||
if (lockRun) mutex_.unlock();
|
if (lockRun) mutex_.unlock();
|
||||||
started();
|
started();
|
||||||
while (!terminating) {
|
while (!terminating) {
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
|
||||||
maybeCallQueuedEvents();
|
maybeCallQueuedEvents();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "ok";
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
|
||||||
if (lockRun) mutex_.lock();
|
if (lockRun) mutex_.lock();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
|
||||||
run();
|
run();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
|
||||||
//printf("thread %p tick\n", this);
|
//printf("thread %p tick\n", this);
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "...";
|
||||||
if (ret_func != 0) ret_func(data_);
|
if (ret_func != 0) ret_func(data_);
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "ok";
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
|
||||||
if (lockRun) mutex_.unlock();
|
if (lockRun) mutex_.unlock();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "...";
|
||||||
if (delay_ > 0) {
|
if (delay_ > 0) {
|
||||||
tmr_.reset();
|
tmr_.reset();
|
||||||
double sl(0.);
|
double sl(0.);
|
||||||
@@ -479,19 +479,19 @@ void PIThread::__thread_func__() {
|
|||||||
piMSleep(sl);
|
piMSleep(sl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "ok";
|
||||||
}
|
}
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||||
stopped();
|
stopped();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
if (lockRun) mutex_.lock();
|
if (lockRun) mutex_.lock();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "end" << "...";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "end" << "...";
|
||||||
end();
|
end();
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
if (lockRun) mutex_.unlock();
|
if (lockRun) mutex_.unlock();
|
||||||
terminating = running_ = false;
|
terminating = running_ = false;
|
||||||
tid_ = -1;
|
tid_ = -1;
|
||||||
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
|
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
|
||||||
//cout << "thread " << t << " exiting ... " << endl;
|
//cout << "thread " << t << " exiting ... " << endl;
|
||||||
//PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
|
//PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
|
||||||
UNREGISTER_THREAD(this);
|
UNREGISTER_THREAD(this);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ _PITimerBase::_PITimerBase() {
|
|||||||
void _PITimerBase::setInterval(double i) {
|
void _PITimerBase::setInterval(double i) {
|
||||||
interval_ = i;
|
interval_ = i;
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
piCout << "change interval runtime";
|
//piCout << "change interval runtime";
|
||||||
stop(true);
|
stop(true);
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ bool _PITimerBase::start(double interval_ms) {
|
|||||||
if (isRunning()) stop(true);
|
if (isRunning()) stop(true);
|
||||||
deferred_ = false;
|
deferred_ = false;
|
||||||
setInterval(interval_ms);
|
setInterval(interval_ms);
|
||||||
piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
|
//piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
|
||||||
running_ = startTimer(interval_ms);
|
running_ = startTimer(interval_ms);
|
||||||
return running_;
|
return running_;
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ void _PITimerBase::startDeferred(double interval_ms, double delay_ms) {
|
|||||||
bool _PITimerBase::stop(bool wait) {
|
bool _PITimerBase::stop(bool wait) {
|
||||||
//piCout << GetCurrentThreadId() << "_PITimerBase::stop" << wait << isRunning();
|
//piCout << GetCurrentThreadId() << "_PITimerBase::stop" << wait << isRunning();
|
||||||
if (!isRunning()) return true;
|
if (!isRunning()) return true;
|
||||||
piCout << "_PITimerBase::stopTimer ...";
|
//piCout << "_PITimerBase::stopTimer ...";
|
||||||
running_ = !stopTimer(wait);
|
running_ = !stopTimer(wait);
|
||||||
return !running_;
|
return !running_;
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ _PITimerImp_Thread::_PITimerImp_Thread() {
|
|||||||
wait_dt = 100;
|
wait_dt = 100;
|
||||||
wait_dd = 200;
|
wait_dd = 200;
|
||||||
wait_tick = 10;
|
wait_tick = 10;
|
||||||
piCout << "_PITimerImp_Thread" << this << ", thread& =" << &thread_;
|
//piCout << "_PITimerImp_Thread" << this << ", thread& =" << &thread_;
|
||||||
//piCout << "new _PITimerImp_Thread";
|
//piCout << "new _PITimerImp_Thread";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +211,7 @@ bool _PITimerImp_Thread::startTimer(double interval_ms) {
|
|||||||
|
|
||||||
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
bool _PITimerImp_Thread::stopTimer(bool wait) {
|
||||||
#ifndef FREERTOS
|
#ifndef FREERTOS
|
||||||
thread_.stop(true);
|
thread_.stop(wait);
|
||||||
#else
|
#else
|
||||||
thread_.stop();
|
thread_.stop();
|
||||||
if (wait)
|
if (wait)
|
||||||
@@ -250,9 +250,9 @@ bool _PITimerImp_Thread::threadFunc() {
|
|||||||
st_wait = st_time - PISystemTime::current(true);
|
st_wait = st_time - PISystemTime::current(true);
|
||||||
//piCout << "wait" << this << st_wait;
|
//piCout << "wait" << this << st_wait;
|
||||||
if (st_wait.abs() > st_odt || st_wait.seconds <= -5) {
|
if (st_wait.abs() > st_odt || st_wait.seconds <= -5) {
|
||||||
piCout << &thread_ << "adjust" << "...";
|
//piCout << &thread_ << "adjust" << "...";
|
||||||
adjustTimes();
|
adjustTimes();
|
||||||
piCout << &thread_ << "adjust" << "ok";
|
//piCout << &thread_ << "adjust" << "ok";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (wait_tick > 0) {
|
if (wait_tick > 0) {
|
||||||
@@ -260,7 +260,7 @@ bool _PITimerImp_Thread::threadFunc() {
|
|||||||
piMSleep(wait_tick);
|
piMSleep(wait_tick);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
piCout << &thread_ << "sleep for" << st_wait;
|
//piCout << &thread_ << "sleep for" << st_wait;
|
||||||
st_wait.sleep();
|
st_wait.sleep();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -272,9 +272,9 @@ bool _PITimerImp_Thread::threadFunc() {
|
|||||||
piCout << "Achtung! PITimer \"parent\" is not PIObject!";
|
piCout << "Achtung! PITimer \"parent\" is not PIObject!";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
piCout << &thread_ << "tfunc" << "...";
|
//piCout << &thread_ << "tfunc" << "...";
|
||||||
tfunc(parent);
|
tfunc(parent);
|
||||||
piCout << &thread_ << "tfunc" << "ok";
|
//piCout << &thread_ << "tfunc" << "ok";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -548,7 +548,7 @@ void PITimer::init() const {
|
|||||||
default: piCout << "Fatal: invalid implementation() of" << this << "!"; assert(0);
|
default: piCout << "Fatal: invalid implementation() of" << this << "!"; assert(0);
|
||||||
}
|
}
|
||||||
if (!imp) return;
|
if (!imp) return;
|
||||||
piCout << this << "init" << imp;
|
//piCout << this << "init" << imp;
|
||||||
imp->tfunc = tickImpS;
|
imp->tfunc = tickImpS;
|
||||||
imp->parent = const_cast<PITimer*>(this);
|
imp->parent = const_cast<PITimer*>(this);
|
||||||
}
|
}
|
||||||
@@ -556,7 +556,7 @@ void PITimer::init() const {
|
|||||||
|
|
||||||
void PITimer::destroy() {
|
void PITimer::destroy() {
|
||||||
if (!imp) return;
|
if (!imp) return;
|
||||||
piCout << this << "destroy" << imp;
|
//piCout << this << "destroy" << imp;
|
||||||
imp->stop(false); ///BUG: WTF FreeRTOS segfault on this!
|
imp->stop(false); ///BUG: WTF FreeRTOS segfault on this!
|
||||||
delete imp;
|
delete imp;
|
||||||
imp = 0;
|
imp = 0;
|
||||||
@@ -583,14 +583,14 @@ void PITimer::tickImp() {
|
|||||||
|
|
||||||
|
|
||||||
bool PITimer::start() {
|
bool PITimer::start() {
|
||||||
piCout << this << "start" << imp;
|
//piCout << this << "start" << imp;
|
||||||
return imp->start();
|
return imp->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PITimer::start(double interval_ms_d) {
|
bool PITimer::start(double interval_ms_d) {
|
||||||
init();
|
init();
|
||||||
piCout << this << "start" << imp << interval_ms_d;
|
//piCout << this << "start" << imp << interval_ms_d;
|
||||||
setProperty("interval", interval_ms_d);
|
setProperty("interval", interval_ms_d);
|
||||||
return imp->start(interval_ms_d);
|
return imp->start(interval_ms_d);
|
||||||
}
|
}
|
||||||
@@ -638,7 +638,7 @@ bool PITimer::stop() {
|
|||||||
|
|
||||||
bool PITimer::stop(bool wait) {
|
bool PITimer::stop(bool wait) {
|
||||||
init();
|
init();
|
||||||
piCout << this << "stop" << imp << wait;
|
//piCout << this << "stop" << imp << wait;
|
||||||
return imp->stop(wait);
|
return imp->stop(wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user