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 "piscreen.h"
|
||||
#include "piethernet.h"
|
||||
#include "piintrospection.h"
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
piCout << PIINTROSPECTION;
|
||||
/*PIVector<PIVariant> 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<PIString, __PIVariantInfo__*>::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;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "pithread.h"
|
||||
#include "pisystemtests.h"
|
||||
#include "piintrospection.h"
|
||||
#include <signal.h>
|
||||
#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;
|
||||
|
||||
@@ -101,9 +101,12 @@ 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_;
|
||||
|
||||
Reference in New Issue
Block a user