fix bug with null threads
git-svn-id: svn://db.shs.com.ru/pip@163 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -127,7 +127,7 @@ bool PIThread::start(int timer_delay) {
|
|||||||
# endif
|
# endif
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
int ret = pthread_create(&thread, &attr, thread_function, this);
|
int ret = pthread_create(&thread, &attr, thread_function, this);
|
||||||
piCout << "pthread_create" << thread;
|
//piCout << "pthread_create" << thread;
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
#else
|
#else
|
||||||
@@ -158,7 +158,7 @@ bool PIThread::startOnce() {
|
|||||||
# endif
|
# endif
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
int ret = pthread_create(&thread, &attr, thread_function_once, this);
|
int ret = pthread_create(&thread, &attr, thread_function_once, this);
|
||||||
piCout << "pthread_create" << thread;
|
//piCout << "pthread_create" << thread;
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
#else
|
#else
|
||||||
@@ -181,7 +181,7 @@ bool PIThread::startOnce() {
|
|||||||
void PIThread::terminate() {
|
void PIThread::terminate() {
|
||||||
if (thread == 0) return;
|
if (thread == 0) return;
|
||||||
terminating = running_ = false;
|
terminating = running_ = false;
|
||||||
piCout << "terminate" << thread;
|
//piCout << "terminate" << thread;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
# ifdef ANDROID
|
# ifdef ANDROID
|
||||||
pthread_kill(thread, SIGTERM);
|
pthread_kill(thread, SIGTERM);
|
||||||
@@ -239,7 +239,7 @@ __THREAD_FUNC__ PIThread::thread_function(void * t) {
|
|||||||
if (ct.lockRun) ct.mutex_.unlock();
|
if (ct.lockRun) ct.mutex_.unlock();
|
||||||
ct.terminating = ct.running_ = false;
|
ct.terminating = ct.running_ = false;
|
||||||
//cout << "thread " << t << " exiting ... " << endl;
|
//cout << "thread " << t << " exiting ... " << endl;
|
||||||
piCout << "pthread_exit" << ct.thread;
|
//piCout << "pthread_exit" << ct.thread;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
pthread_detach(ct.thread);
|
pthread_detach(ct.thread);
|
||||||
ct.thread = 0;
|
ct.thread = 0;
|
||||||
@@ -275,7 +275,7 @@ __THREAD_FUNC__ PIThread::thread_function_once(void * t) {
|
|||||||
ct.end();
|
ct.end();
|
||||||
ct.terminating = ct.running_ = false;
|
ct.terminating = ct.running_ = false;
|
||||||
//cout << "thread " << t << " exiting ... " << endl;
|
//cout << "thread " << t << " exiting ... " << endl;
|
||||||
piCout << "pthread_exit" << ct.thread;
|
//piCout << "pthread_exit" << ct.thread;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
pthread_detach(ct.thread);
|
pthread_detach(ct.thread);
|
||||||
ct.thread = 0;
|
ct.thread = 0;
|
||||||
@@ -322,8 +322,8 @@ int PIThread::priority2System(PIThread::Priority p) {
|
|||||||
void PIThread::setPriority(PIThread::Priority prior) {
|
void PIThread::setPriority(PIThread::Priority prior) {
|
||||||
priority_ = prior;
|
priority_ = prior;
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
if (!running_ && (thread != 0)) return;
|
if (!running_ || (thread == 0)) return;
|
||||||
piCout << "setPriority" << thread;
|
//piCout << "setPriority" << thread;
|
||||||
policy_ = 0;
|
policy_ = 0;
|
||||||
memset(&sparam, 0, sizeof(sparam));
|
memset(&sparam, 0, sizeof(sparam));
|
||||||
pthread_getschedparam(thread, &policy_, &sparam);
|
pthread_getschedparam(thread, &policy_, &sparam);
|
||||||
@@ -336,7 +336,7 @@ void PIThread::setPriority(PIThread::Priority prior) {
|
|||||||
= priority2System(priority_);
|
= priority2System(priority_);
|
||||||
pthread_setschedparam(thread, policy_, &sparam);
|
pthread_setschedparam(thread, policy_, &sparam);
|
||||||
#else
|
#else
|
||||||
if (!running_ && (thread != 0)) return;
|
if (!running_ || (thread == 0)) return;
|
||||||
SetThreadPriority(thread, priority2System(priority_));
|
SetThreadPriority(thread, priority2System(priority_));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user