From 2b7bf4a65efc77027a4da99487279e587c3285a7 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: Mon, 29 Feb 2016 15:45:04 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@184 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- main.cpp | 5 +++-- src/thread/pithread.cpp | 15 +++++++++++++++ src/thread/pithread.h | 7 +++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 3dcce19b..e29b2635 100644 --- a/main.cpp +++ b/main.cpp @@ -4,9 +4,11 @@ #include "piscreentiles.h" #include "piscreen.h" #include "piethernet.h" +#include "piintrospection.h" int main (int argc, char * argv[]) { + piCout << PIINTROSPECTION; /*PIVector vl; vl << PIVariant('2') << PIVariant(-5.5) << PIVariant(10) << PIVariant(complexd(2,3)) << PIVariant("text") << PIVariant(PIByteArray("bytearray", 9)) << PIVariant(PIDateTime::current()); piForeachC (PIVariant v, vl) @@ -18,9 +20,8 @@ int main (int argc, char * argv[]) { piCout << __PIVariantInfoStorage__::get()->map->size(); for (PIMap::iterator i = __PIVariantInfoStorage__::get()->map->begin(); i != __PIVariantInfoStorage__::get()->map->end(); ++i) piCout << i.key() << i.value()->cast.size(); -*/ PIEthernet eth; - piCout << eth.properties(); + piCout << eth.properties();*/ /*PIScreen screen; TileSimple window; window.back_format.color_back = PIScreenTypes::Red; diff --git a/src/thread/pithread.cpp b/src/thread/pithread.cpp index 44a5eaa4..12671c56 100755 --- a/src/thread/pithread.cpp +++ b/src/thread/pithread.cpp @@ -19,6 +19,7 @@ #include "pithread.h" #include "pisystemtests.h" +#include "piintrospection.h" #include #ifdef WINDOWS void __PISetTimerResolution() {if (setTimerResolutionAddr == NULL) return; ULONG ret; setTimerResolutionAddr(1, TRUE, &ret);} @@ -77,6 +78,7 @@ end(); PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay): PIObject() { piMonitor.threads++; + tid_ = -1; thread = 0; data_ = data; ret_func = func; @@ -89,6 +91,7 @@ PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay) PIThread::PIThread(bool startNow, int timer_delay): PIObject() { piMonitor.threads++; + tid_ = -1; thread = 0; ret_func = 0; terminating = running_ = lockRun = false; @@ -130,11 +133,13 @@ bool PIThread::start(int timer_delay) { //piCout << "pthread_create" << thread; pthread_attr_destroy(&attr); if (ret == 0) { + tid_ = thread; #else if (thread != 0) CloseHandle(thread); thread = (void *)_beginthreadex(0, 0, thread_function, this, 0, 0); // thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function, this, 0, 0); if (thread != 0) { + tid_ = GetThreadId(thread); #endif setPriority(priority_); running_ = true; @@ -161,11 +166,13 @@ bool PIThread::startOnce() { //piCout << "pthread_create" << thread; pthread_attr_destroy(&attr); if (ret == 0) { + tid_ = thread; #else if (thread != 0) CloseHandle(thread); thread = (void *)_beginthreadex(0, 0, thread_function_once, this, 0, 0); // thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)thread_function_once, this, 0, 0); if (thread != 0) { + tid_ = GetThreadId(thread); #endif setPriority(priority_); running_ = true; @@ -180,7 +187,9 @@ bool PIThread::startOnce() { void PIThread::terminate() { if (thread == 0) return; + PIINTROSPECTION->unregisterThread(tid()); terminating = running_ = false; + tid_ = -1; //piCout << "terminate" << thread; #ifndef WINDOWS # ifdef ANDROID @@ -210,6 +219,7 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) { __PISetTimerResolution(); #endif PIThread & ct = *((PIThread * )t); + PIINTROSPECTION->registerThread(ct.tid(), ct.priority(), ct.name()); ct.running_ = true; if (ct.lockRun) ct.mutex_.lock(); ct.begin(); @@ -238,8 +248,10 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) { ct.end(); if (ct.lockRun) ct.mutex_.unlock(); ct.terminating = ct.running_ = false; + ct.tid_ = -1; //cout << "thread " << t << " exiting ... " << endl; //piCout << "pthread_exit" << ct.thread; + PIINTROSPECTION->unregisterThread(ct.tid()); #ifndef WINDOWS pthread_detach(ct.thread); ct.thread = 0; @@ -264,6 +276,7 @@ __THREAD_FUNC__ PIThread::thread_function_once(void * t) { __PISetTimerResolution(); #endif PIThread & ct = *((PIThread * )t); + PIINTROSPECTION->registerThread(ct.tid(), ct.priority(), ct.name()); ct.running_ = true; ct.begin(); ct.started(); @@ -274,8 +287,10 @@ __THREAD_FUNC__ PIThread::thread_function_once(void * t) { ct.stopped(); ct.end(); ct.terminating = ct.running_ = false; + ct.tid_ = -1; //cout << "thread " << t << " exiting ... " << endl; //piCout << "pthread_exit" << ct.thread; + PIINTROSPECTION->unregisterThread(ct.tid()); #ifndef WINDOWS pthread_detach(ct.thread); ct.thread = 0; diff --git a/src/thread/pithread.h b/src/thread/pithread.h index ed122d4b..9e4273c4 100755 --- a/src/thread/pithread.h +++ b/src/thread/pithread.h @@ -101,8 +101,11 @@ public: EVENT_HANDLER0(void, lock) {mutex_.lock();} EVENT_HANDLER0(void, unlock) {mutex_.unlock();} - //! \brief Return internal mutex + //! \brief Returns internal mutex PIMutex & mutex() {return mutex_;} + + //! \brief Returns thread ID + int tid() const {return tid_;} EVENT(started) EVENT(stopped) @@ -197,7 +200,7 @@ protected: virtual void end() {;} volatile bool terminating, running_, lockRun; - int delay_, policy_; + int delay_, policy_, tid_; void * data_; PIMutex mutex_; PITimeMeasurer tmf_, tms_, tmr_;