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

This commit is contained in:
2019-02-15 14:45:34 +00:00
parent e1d1853235
commit 0af7eabf56
10 changed files with 140 additions and 63 deletions

View File

@@ -168,6 +168,7 @@ PIThread::PIThread(void * data, ThreadFunc func, bool startNow, int timer_delay)
terminating = running_ = lockRun = false;
priority_ = piNormal;
delay_ = timer_delay;
piCout << "PIThread" << this;
if (startNow) start(timer_delay);
}
@@ -180,6 +181,7 @@ PIThread::PIThread(bool startNow, int timer_delay): PIObject() {
terminating = running_ = lockRun = false;
priority_ = piNormal;
delay_ = timer_delay;
piCout << "PIThread" << this;
if (startNow) start(timer_delay);
}
@@ -202,6 +204,8 @@ PIThread::~PIThread() {
pthread_cancel(PRIVATE->thread);
# endif
# else
piCout << "terminate by ~PIThread" << this;
while(1) msleep(10);
TerminateThread(PRIVATE->thread, 0);
CloseHandle(PRIVATE->thread);
# endif
@@ -321,6 +325,10 @@ void PIThread::terminate() {
//pthread_join(PRIVATE->thread, &ret);
# endif
#else
piCout << "terminate by terminate";
while (1) {
msleep(10);
}
TerminateThread(PRIVATE->thread, 0);
CloseHandle(PRIVATE->thread);
#endif
@@ -438,12 +446,12 @@ void PIThread::__thread_func__(void * t) {
while (!ct.terminating) {
ct.maybeCallQueuedEvents();
if (ct.lockRun) ct.mutex_.lock();
//piCout << "thread" << ct.name() << "...";
// piCout << "thread" << ct.name() << "..." << ct.lockRun;
ct.run();
//piCout << "thread" << ct.name() << "done";
//printf("thread %p tick\n", &ct);
if (ct.ret_func != 0) ct.ret_func(ct.data_);
if (ct.lockRun) ct.mutex_.unlock();
// piCout << "thread" << ct.name() << "done";
if (ct.delay_ > 0) {
ct.tmr_.reset();
double sl(0.);
@@ -472,6 +480,7 @@ void PIThread::__thread_func__(void * t) {
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
UNREGISTER_THREAD(&ct);
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
piCout << "pthread_exit" << &ct;
#ifndef WINDOWS
pthread_detach((ct.__privateinitializer__.p)->thread);
(ct.__privateinitializer__.p)->thread = 0;