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

This commit is contained in:
2019-06-23 13:39:55 +00:00
parent 8a2a9e1684
commit 6da4f268d2
6 changed files with 43 additions and 20 deletions

View File

@@ -60,10 +60,10 @@ void PIIntrospectionServer::dataReceived(const PIString & from, const PIByteArra
cs.add(PIIntrospection::itInfo, PIIntrospection::packInfo());
if (ri.types[PIIntrospection::itContainers])
cs.add(PIIntrospection::itContainers, PIIntrospection::packContainers());
if (ri.types[PIIntrospection::itThreads])
cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
if (ri.types[PIIntrospection::itObjects])
cs.add(PIIntrospection::itObjects, PIIntrospection::packObjects());
if (ri.types[PIIntrospection::itThreads])
cs.add(PIIntrospection::itThreads, PIIntrospection::packThreads());
PIByteArray ba;
ba << PIIntrospection::sign;
ba.append(cs.data());

View File

@@ -209,7 +209,12 @@ PIByteArray PIIntrospection::packThreads() {
PIByteArray ret;
PIIntrospectionThreads * p = PIINTROSPECTION_THREADS->p;
p->mutex.lock();
ret << p->threads.values();
PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo> & tm(p->threads);
for (PIMap<PIThread*, PIIntrospectionThreads::ThreadInfo>::iterator i = tm.begin(); i != tm.end(); ++i) {
i.value().classname = PIStringAscii(i.key()->className());
i.value().name = i.key()->name();
}
ret << tm.values();
p->mutex.unlock();
return ret;
}

View File

@@ -21,9 +21,10 @@
PIIntrospectionThreads::ThreadInfo::ThreadInfo() {
id = 0;
id = delay = 0;
state = sStopped;
priority = 0;
run_us = run_count = 0U;
}
@@ -34,59 +35,66 @@ PIIntrospectionThreads::PIIntrospectionThreads() {
void PIIntrospectionThreads::threadNew(PIThread * t) {
mutex.lock();
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.id = t->tid();
ti.priority = t->priority();
ti.name = t->name();
//piCout << "register thread" << id << name;
mutex.unlock();
}
void PIIntrospectionThreads::threadDelete(PIThread * t) {
mutex.lock();
PIMutexLocker _ml(mutex);
threads.remove(t);
mutex.unlock();
}
void PIIntrospectionThreads::threadStart(PIThread * t) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.id = t->tid();
ti.priority = t->priority();
ti.delay = t->delay_;
ti.state = sStarting;
}
void PIIntrospectionThreads::threadRun(PIThread * t) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.state = sRunning;
ti.run_count++;
}
void PIIntrospectionThreads::threadWait(PIThread * t) {
PIMutexLocker _ml(mutex);
threads[t].state = sWaiting;
}
void PIIntrospectionThreads::threadStop(PIThread * t) {
PIMutexLocker _ml(mutex);
threads[t].state = sStopped;
}
void PIIntrospectionThreads::threadRunDone(PIThread * t, ullong us) {
PIMutexLocker _ml(mutex);
ThreadInfo & ti(threads[t]);
ti.run_us = (ti.run_us * 0.8) + (us * 0.2); /// WARNING
}
PIByteArray & operator <<(PIByteArray & b, const PIIntrospectionThreads::ThreadInfo & v) {
b << v.name << v.id << int(v.state) << v.priority;
b << v.classname << v.name << v.id << int(v.state) << v.priority << v.delay << v.run_us << v.run_count;
return b;
}
PIByteArray & operator >>(PIByteArray & b, PIIntrospectionThreads::ThreadInfo & v) {
int st(0);
b >> v.id >> v.priority >> st >> v.name;
b >> v.classname >> v.name >> v.id >> st >> v.priority >> v.delay >> v.run_us >> v.run_count;
v.state = (PIIntrospectionThreads::ThreadState)st;
return b;
}

View File

@@ -34,12 +34,14 @@ public:
sRunning,
sWaiting,
};
struct ThreadInfo {
ThreadInfo();
PIString name;
int id;
PIString classname, name;
int id, delay;
ThreadState state;
short priority;
ullong run_us, run_count;
};
void threadNew (PIThread * t);

View File

@@ -453,7 +453,13 @@ void PIThread::_runThread() {
if (lockRun) mutex_.lock();
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
#ifdef PIP_INTROSPECTION
PITimeMeasurer _tm;
#endif
run();
#ifdef PIP_INTROSPECTION
PIINTROSPECTION_THREAD_RUN_DONE(this, ullong(_tm.elapsed_u()));
#endif
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
//printf("thread %p tick\n", this);
//PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "...";

View File

@@ -30,6 +30,7 @@
#include "piobject.h"
class PIThread;
class PIIntrospectionThreads;
class PIP_EXPORT __PIThreadCollection {
public:
@@ -61,6 +62,7 @@ typedef void (*ThreadFunc)(void * );
class PIP_EXPORT PIThread: public PIObject
{
PIOBJECT_SUBCLASS(PIThread, PIObject)
friend class PIIntrospectionThreads;
public:
//! Contructs thread with custom data "data", external function "func" and main loop delay "loop_delay".