BIG deep clean
This commit is contained in:
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Thread
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
Thread
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "piincludes_p.h"
|
||||
@@ -91,11 +91,7 @@ end();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
__PIThreadCollection *__PIThreadCollection::instance() {
|
||||
/*static CDCore * ret = new CDCore();
|
||||
return ret;*/
|
||||
return __PIThreadCollection_Initializer__::__instance__;
|
||||
}
|
||||
|
||||
@@ -250,14 +246,12 @@ void PIThread::stop(bool wait) {
|
||||
|
||||
bool PIThread::start(int timer_delay) {
|
||||
if (running_) return false;
|
||||
//if (terminating) waitForFinish();
|
||||
delay_ = timer_delay;
|
||||
return _startThread((void*)thread_function);
|
||||
}
|
||||
|
||||
|
||||
bool PIThread::startOnce() {
|
||||
if (terminating) waitForFinish();
|
||||
if (running_) return false;
|
||||
return _startThread((void*)thread_function_once);
|
||||
}
|
||||
@@ -326,15 +320,11 @@ int PIThread::priority2System(PIThread::Priority p) {
|
||||
|
||||
|
||||
bool PIThread::_startThread(void * func) {
|
||||
//if (terminating) waitForFinish();
|
||||
terminating = false;
|
||||
running_ = true;
|
||||
#ifndef WINDOWS
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
# ifndef ANDROID
|
||||
//pthread_attr_setschedparam(&attr, &(PRIVATE->sparam));
|
||||
# endif
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
int ret = pthread_create(&PRIVATE->thread, &attr, (void*(*)(void*))func, this);
|
||||
//PICout(PICoutManipulators::DefaultControls) << "pthread_create" << PRIVATE->thread;
|
||||
@@ -374,24 +364,24 @@ bool PIThread::_startThread(void * func) {
|
||||
void PIThread::setPriority(PIThread::Priority prior) {
|
||||
#ifndef FREERTOS // FreeRTOS can't change priority runtime
|
||||
priority_ = prior;
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||
//PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread;
|
||||
policy_ = 0;
|
||||
memset(&(PRIVATE->sparam), 0, sizeof(PRIVATE->sparam));
|
||||
pthread_getschedparam(PRIVATE->thread, &policy_, &(PRIVATE->sparam));
|
||||
PRIVATE->sparam.
|
||||
# ifndef LINUX
|
||||
# ifndef LINUX
|
||||
sched_priority
|
||||
# else
|
||||
# else
|
||||
__sched_priority
|
||||
# endif
|
||||
# endif
|
||||
= priority2System(priority_);
|
||||
pthread_setschedparam(PRIVATE->thread, policy_, &(PRIVATE->sparam));
|
||||
#else
|
||||
# else
|
||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
|
||||
#endif
|
||||
# endif
|
||||
#endif //FREERTOS
|
||||
}
|
||||
|
||||
@@ -458,8 +448,6 @@ void PIThread::_beginThread() {
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
|
||||
# endif
|
||||
#else
|
||||
//__PISetTimerResolution();
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
tid_ = GetCurrentThreadId();
|
||||
@@ -585,6 +573,5 @@ void PIThread::runOnce(std::function<void ()> func, const PIString & name) {
|
||||
__PIThreadCollection::instance()->startedAuto(t);
|
||||
CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||
t->startOnce();
|
||||
//return t;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user