git-svn-id: svn://db.shs.com.ru/pip@758 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-02-19 09:10:12 +00:00
parent dd1079bcef
commit 84a584c682
5 changed files with 42 additions and 40 deletions

View File

@@ -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 "="
* \details Example:\n \snippet piincludes.cpp swapBinary */
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;
for (i = 0; i < j; ++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) {
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;
void * pf = const_cast<void*>(f), * ps = const_cast<void*>(s);
for (i = 0; i < j; ++i) {

View File

@@ -464,8 +464,8 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_
PIVector<PIObject * > & PIObject::objects() {
static PIVector<PIObject * > ret;
return ret;
static PIVector<PIObject * > * ret = new PIVector<PIObject * >();
return *ret;
}

View File

@@ -52,6 +52,7 @@ PRIVATE_DEFINITION_END(PIMutex)
PIMutex::PIMutex(): inited_(false) {
//printf("new Mutex %p\n", this);
#ifdef WINDOWS
PRIVATE->mutex = 0;
#endif
@@ -60,6 +61,7 @@ PIMutex::PIMutex(): inited_(false) {
PIMutex::~PIMutex() {
//printf("del Mutex %p\n", this);
destroy();
}

View File

@@ -211,7 +211,7 @@ PIThread::~PIThread() {
void PIThread::stop(bool wait) {
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop ..." << running_ << wait;
terminating = true;
if (wait) waitForFinish();
}
@@ -307,7 +307,7 @@ bool PIThread::startOnce() {
void PIThread::terminate() {
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
#ifdef FREERTOS
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
stop(true);
@@ -335,7 +335,7 @@ void PIThread::terminate() {
PRIVATE->thread = 0;
end();
#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) {
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 (timeout_msecs < 0) {
while (running_)
@@ -445,23 +445,23 @@ void PIThread::__thread_func__() {
if (lockRun) mutex_.unlock();
started();
while (!terminating) {
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
maybeCallQueuedEvents();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "ok";
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
if (lockRun) mutex_.lock();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
run();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
//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_);
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "ok";
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
if (lockRun) mutex_.unlock();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "...";
if (delay_ > 0) {
tmr_.reset();
double sl(0.);
@@ -479,19 +479,19 @@ void PIThread::__thread_func__() {
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();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
if (lockRun) mutex_.lock();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "end" << "...";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "end" << "...";
end();
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
if (lockRun) mutex_.unlock();
terminating = running_ = false;
tid_ = -1;
PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "exit";
//cout << "thread " << t << " exiting ... " << endl;
//PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
UNREGISTER_THREAD(this);

View File

@@ -62,7 +62,7 @@ _PITimerBase::_PITimerBase() {
void _PITimerBase::setInterval(double i) {
interval_ = i;
if (isRunning()) {
piCout << "change interval runtime";
//piCout << "change interval runtime";
stop(true);
start();
}
@@ -73,7 +73,7 @@ bool _PITimerBase::start(double interval_ms) {
if (isRunning()) stop(true);
deferred_ = false;
setInterval(interval_ms);
piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
//piCout << "_PITimerBase::startTimer"<<interval_ms<<"...";
running_ = startTimer(interval_ms);
return running_;
}
@@ -102,7 +102,7 @@ void _PITimerBase::startDeferred(double interval_ms, double delay_ms) {
bool _PITimerBase::stop(bool wait) {
//piCout << GetCurrentThreadId() << "_PITimerBase::stop" << wait << isRunning();
if (!isRunning()) return true;
piCout << "_PITimerBase::stopTimer ...";
//piCout << "_PITimerBase::stopTimer ...";
running_ = !stopTimer(wait);
return !running_;
}
@@ -174,7 +174,7 @@ _PITimerImp_Thread::_PITimerImp_Thread() {
wait_dt = 100;
wait_dd = 200;
wait_tick = 10;
piCout << "_PITimerImp_Thread" << this << ", thread& =" << &thread_;
//piCout << "_PITimerImp_Thread" << this << ", thread& =" << &thread_;
//piCout << "new _PITimerImp_Thread";
}
@@ -211,7 +211,7 @@ bool _PITimerImp_Thread::startTimer(double interval_ms) {
bool _PITimerImp_Thread::stopTimer(bool wait) {
#ifndef FREERTOS
thread_.stop(true);
thread_.stop(wait);
#else
thread_.stop();
if (wait)
@@ -250,9 +250,9 @@ bool _PITimerImp_Thread::threadFunc() {
st_wait = st_time - PISystemTime::current(true);
//piCout << "wait" << this << st_wait;
if (st_wait.abs() > st_odt || st_wait.seconds <= -5) {
piCout << &thread_ << "adjust" << "...";
//piCout << &thread_ << "adjust" << "...";
adjustTimes();
piCout << &thread_ << "adjust" << "ok";
//piCout << &thread_ << "adjust" << "ok";
return true;
}
if (wait_tick > 0) {
@@ -260,7 +260,7 @@ bool _PITimerImp_Thread::threadFunc() {
piMSleep(wait_tick);
return false;
} else {
piCout << &thread_ << "sleep for" << st_wait;
//piCout << &thread_ << "sleep for" << st_wait;
st_wait.sleep();
}
} else {
@@ -272,9 +272,9 @@ bool _PITimerImp_Thread::threadFunc() {
piCout << "Achtung! PITimer \"parent\" is not PIObject!";
return false;
}
piCout << &thread_ << "tfunc" << "...";
//piCout << &thread_ << "tfunc" << "...";
tfunc(parent);
piCout << &thread_ << "tfunc" << "ok";
//piCout << &thread_ << "tfunc" << "ok";
return true;
}
@@ -548,7 +548,7 @@ void PITimer::init() const {
default: piCout << "Fatal: invalid implementation() of" << this << "!"; assert(0);
}
if (!imp) return;
piCout << this << "init" << imp;
//piCout << this << "init" << imp;
imp->tfunc = tickImpS;
imp->parent = const_cast<PITimer*>(this);
}
@@ -556,7 +556,7 @@ void PITimer::init() const {
void PITimer::destroy() {
if (!imp) return;
piCout << this << "destroy" << imp;
//piCout << this << "destroy" << imp;
imp->stop(false); ///BUG: WTF FreeRTOS segfault on this!
delete imp;
imp = 0;
@@ -583,14 +583,14 @@ void PITimer::tickImp() {
bool PITimer::start() {
piCout << this << "start" << imp;
//piCout << this << "start" << imp;
return imp->start();
}
bool PITimer::start(double interval_ms_d) {
init();
piCout << this << "start" << imp << interval_ms_d;
//piCout << this << "start" << imp << interval_ms_d;
setProperty("interval", interval_ms_d);
return imp->start(interval_ms_d);
}
@@ -638,7 +638,7 @@ bool PITimer::stop() {
bool PITimer::stop(bool wait) {
init();
piCout << this << "stop" << imp << wait;
//piCout << this << "stop" << imp << wait;
return imp->stop(wait);
}