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

This commit is contained in:
2019-02-07 18:32:14 +00:00
parent a8bb4c21f3
commit 42a4223667

View File

@@ -212,7 +212,9 @@ PIThread::~PIThread() {
bool PIThread::start(int timer_delay) { bool PIThread::start(int timer_delay) {
if (running_) return false; if (running_) return false;
terminating = running_ = false; //if (terminating) waitForFinish();
terminating = false;
running_ = true;
delay_ = timer_delay; delay_ = timer_delay;
#ifndef WINDOWS #ifndef WINDOWS
pthread_attr_t attr; pthread_attr_t attr;
@@ -242,19 +244,22 @@ bool PIThread::start(int timer_delay) {
if (PRIVATE->thread != 0) { if (PRIVATE->thread != 0) {
#endif #endif
setPriority(priority_); setPriority(priority_);
running_ = true;
return true; return true;
} else { } else {
running_ = false;
PRIVATE->thread = 0; PRIVATE->thread = 0;
piCoutObj << "Error: Can`t start new thread:" << errorString(); piCoutObj << "Error: Can`t start new thread:" << errorString();
} }
running_ = false;
return false; return false;
} }
bool PIThread::startOnce() { bool PIThread::startOnce() {
if (terminating) waitForFinish();
if (running_) return false; if (running_) return false;
terminating = running_ = false; terminating = false;
running_ = true;
#ifndef WINDOWS #ifndef WINDOWS
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
@@ -263,7 +268,7 @@ bool PIThread::startOnce() {
# endif # endif
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int ret = pthread_create(&(PRIVATE->thread), &attr, thread_function_once, this); int ret = pthread_create(&(PRIVATE->thread), &attr, thread_function_once, this);
//piCout << "pthread_create" << PRIVATE->thread; piCout << "pthread_create" << PRIVATE->thread;
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
if (ret == 0) { if (ret == 0) {
# ifdef MAC_OS # ifdef MAC_OS
@@ -283,12 +288,13 @@ bool PIThread::startOnce() {
if (PRIVATE->thread != 0) { if (PRIVATE->thread != 0) {
#endif #endif
setPriority(priority_); setPriority(priority_);
running_ = true;
return true; return true;
} else { } else {
running_ = false;
PRIVATE->thread = 0; PRIVATE->thread = 0;
piCoutObj << "Error: Can`t start new thread:" << errorString(); piCoutObj << "Error: Can`t start new thread:" << errorString();
} }
running_ = false;
return false; return false;
} }
@@ -463,7 +469,7 @@ void PIThread::__thread_func__(void * t) {
ct.terminating = ct.running_ = false; ct.terminating = ct.running_ = false;
ct.tid_ = -1; ct.tid_ = -1;
//cout << "thread " << t << " exiting ... " << endl; //cout << "thread " << t << " exiting ... " << endl;
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
UNREGISTER_THREAD(&ct); UNREGISTER_THREAD(&ct);
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid()); PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
#ifndef WINDOWS #ifndef WINDOWS
@@ -512,7 +518,7 @@ void PIThread::__thread_func_once__(void * t) {
ct.terminating = ct.running_ = false; ct.terminating = ct.running_ = false;
ct.tid_ = -1; ct.tid_ = -1;
//cout << "thread " << t << " exiting ... " << endl; //cout << "thread " << t << " exiting ... " << endl;
//piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread; piCout << "pthread_exit" << (ct.__privateinitializer__.p)->thread;
UNREGISTER_THREAD(&ct); UNREGISTER_THREAD(&ct);
PIINTROSPECTION_UNREGISTER_THREAD(ct.tid()); PIINTROSPECTION_UNREGISTER_THREAD(ct.tid());
#ifndef WINDOWS #ifndef WINDOWS