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