From 84a584c6826a3a70025832e46b9eb967f149fe5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 19 Feb 2019 09:10:12 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@758 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src_main/core/pibase.h | 4 ++-- src_main/core/piobject.cpp | 4 ++-- src_main/thread/pimutex.cpp | 2 ++ src_main/thread/pithread.cpp | 42 ++++++++++++++++++------------------ src_main/thread/pitimer.cpp | 30 +++++++++++++------------- 5 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src_main/core/pibase.h b/src_main/core/pibase.h index f4edd397..9380cd36 100644 --- a/src_main/core/pibase.h +++ b/src_main/core/pibase.h @@ -259,7 +259,7 @@ template 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 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 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(f), * ps = const_cast(s); for (i = 0; i < j; ++i) { diff --git a/src_main/core/piobject.cpp b/src_main/core/piobject.cpp index b54335a4..91a1654c 100755 --- a/src_main/core/piobject.cpp +++ b/src_main/core/piobject.cpp @@ -464,8 +464,8 @@ bool PIObject::findSuitableMethodV(const PIString & method, int args, int & ret_ PIVector & PIObject::objects() { - static PIVector ret; - return ret; + static PIVector * ret = new PIVector(); + return *ret; } diff --git a/src_main/thread/pimutex.cpp b/src_main/thread/pimutex.cpp index 02dc743e..6f84f2ee 100755 --- a/src_main/thread/pimutex.cpp +++ b/src_main/thread/pimutex.cpp @@ -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(); } diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index 1fa0f92d..dfb9e44c 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -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); diff --git a/src_main/thread/pitimer.cpp b/src_main/thread/pitimer.cpp index fe856284..77edb3a2 100755 --- a/src_main/thread/pitimer.cpp +++ b/src_main/thread/pitimer.cpp @@ -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"< 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(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); }