refactor: migrate MICRO_PIP to fine-grained feature flags
Replace monolithic MICRO_PIP/PIP_MICRO with granular flags: Feature flags (CMake options + platform auto-detection): - PIP_NO_FILESYSTEM, PIP_NO_THREADS, PIP_NO_SOCKET - PIP_NO_PROCESS, PIP_NO_DYNLIB, PIP_NO_FFT, PIP_NO_SERIAL Embedded optimization flag: - PIP_EMBEDDED (auto-set for Pico SDK and FreeRTOS) Controls buffer sizes, time stubs, terminal fallback, init stubs Platform blocks in CMakeLists.txt: - Pico SDK: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables THREADS (no FreeRTOS) and SOCKET (no LWIP) - FreeRTOS: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL; conditionally disables SOCKET (no LWIP) - Android: auto-disables PROCESS, DYNLIB, FFT Updated 96 files across libs/, utils/, tests/, and CMakeLists.txt. Builds verified for Linux (547 tests pass) and Pico SDK (100%). Removed all MICRO_PIP and PIP_MICRO references (0 remaining).
This commit is contained in:
@@ -4,22 +4,22 @@
|
||||
//! \~english Condition variable for waiting and notification between threads
|
||||
//! \~russian Переменная условия для ожидания и уведомления между потоками
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Condition variable for waiting and notification between threads
|
||||
Stephan Fomenko
|
||||
PIP - Platform Independent Primitives
|
||||
Condition variable for waiting and notification between threads
|
||||
Stephan Fomenko
|
||||
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PICONDITIONVAR_H
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
//! \param condition вызываемый объект или функция, не принимающая аргументов и возвращающая значение, которое может быть оценено как
|
||||
//! bool. Вызывается повторно, пока не примет значение true
|
||||
//!
|
||||
virtual void wait(PIMutex & lk, std::function<bool ()> condition);
|
||||
virtual void wait(PIMutex & lk, std::function<bool()> condition);
|
||||
|
||||
|
||||
//! \~english Waits for at most \a timeout and returns \c true if awakened before it expires.
|
||||
@@ -176,4 +176,19 @@ private:
|
||||
};
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#ifdef PIP_NO_THREADS
|
||||
class PIConditionVariable {
|
||||
public:
|
||||
void wait(PIMutex &) {}
|
||||
void wait(PIMutex &, std::function<bool()>) {}
|
||||
bool waitFor(PIMutex &, PISystemTime) { return false; }
|
||||
bool waitFor(PIMutex &, PISystemTime, std::function<bool()>) { return false; }
|
||||
bool wait(PIMutex &, PISystemTime) { return true; }
|
||||
bool wait(PIMutex &, ullong) { return true; }
|
||||
void notifyOne() {}
|
||||
void notifyAll() {}
|
||||
};
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#endif // PICONDITIONVAR_H
|
||||
|
||||
@@ -95,4 +95,28 @@ private:
|
||||
};
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#ifdef PIP_NO_THREADS
|
||||
//! \~\ingroup Thread
|
||||
//! \~\brief
|
||||
//! \~english Dummy mutex for builds without threading support.
|
||||
//! \~russian Заглушка мьютекса для сборки без поддержки потоков.
|
||||
class PIMutex {
|
||||
public:
|
||||
void lock() {}
|
||||
void unlock() {}
|
||||
bool tryLock() { return true; }
|
||||
void * handle() { return nullptr; }
|
||||
};
|
||||
|
||||
//! \~\ingroup Thread
|
||||
//! \~\brief
|
||||
//! \~english Dummy mutex locker for builds without threading support.
|
||||
//! \~russian Заглушка блокировщика для сборки без поддержки потоков.
|
||||
class PIMutexLocker {
|
||||
public:
|
||||
PIMutexLocker(PIMutex &, bool = true) {}
|
||||
};
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#endif // PIMUTEX_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
PIReadWriteLock, PIReadLocker, PIWriteLocker
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIReadWriteLock, PIReadLocker, PIWriteLocker
|
||||
Ivan Pelipenko peri4ko@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
|
||||
@@ -151,6 +151,8 @@
|
||||
|
||||
#include "pireadwritelock.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
|
||||
PIReadWriteLock::PIReadWriteLock() {}
|
||||
|
||||
@@ -232,3 +234,5 @@ void PIReadWriteLock::unlockRead() {
|
||||
--reading;
|
||||
var.notifyAll();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -98,6 +98,8 @@
|
||||
|
||||
#include "pisemaphore.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
|
||||
PISemaphore::PISemaphore(int initial) {
|
||||
count = initial;
|
||||
@@ -150,3 +152,5 @@ int PISemaphore::available() const {
|
||||
PIMutexLocker _ml(mutex);
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
+104
-111
@@ -18,39 +18,37 @@
|
||||
*/
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#include "pithread.h"
|
||||
# include "pithread.h"
|
||||
|
||||
#include "piincludes_p.h"
|
||||
#include "piintrospection_threads.h"
|
||||
#include "piliterals_time.h"
|
||||
#include "pitime.h"
|
||||
#include "pitranslator.h"
|
||||
#ifndef MICRO_PIP
|
||||
# include "piincludes_p.h"
|
||||
# include "piintrospection_threads.h"
|
||||
# include "piliterals_time.h"
|
||||
# include "pisystemtests.h"
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# include <ioapiset.h>
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#if defined(WINDOWS)
|
||||
# define __THREAD_FUNC_RET__ uint __stdcall
|
||||
#elif defined(FREERTOS)
|
||||
# define __THREAD_FUNC_RET__ void
|
||||
#else
|
||||
# define __THREAD_FUNC_RET__ void *
|
||||
#endif
|
||||
#ifndef FREERTOS
|
||||
# define __THREAD_FUNC_END__ 0
|
||||
#else
|
||||
# define __THREAD_FUNC_END__
|
||||
#endif
|
||||
#if defined(LINUX)
|
||||
# include <sys/syscall.h>
|
||||
# define gettid() syscall(SYS_gettid)
|
||||
#endif
|
||||
#if defined(MAC_OS) || defined(BLACKBERRY)
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
# include "pitime.h"
|
||||
# include "pitranslator.h"
|
||||
# ifdef WINDOWS
|
||||
# include <ioapiset.h>
|
||||
# endif
|
||||
# include <signal.h>
|
||||
# if defined(WINDOWS)
|
||||
# define __THREAD_FUNC_RET__ uint __stdcall
|
||||
# elif defined(FREERTOS)
|
||||
# define __THREAD_FUNC_RET__ void
|
||||
# else
|
||||
# define __THREAD_FUNC_RET__ void *
|
||||
# endif
|
||||
# ifndef FREERTOS
|
||||
# define __THREAD_FUNC_END__ 0
|
||||
# else
|
||||
# define __THREAD_FUNC_END__
|
||||
# endif
|
||||
# if defined(LINUX)
|
||||
# include <sys/syscall.h>
|
||||
# define gettid() syscall(SYS_gettid)
|
||||
# endif
|
||||
# if defined(MAC_OS) || defined(BLACKBERRY)
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
__THREAD_FUNC_RET__ thread_function(void * t) {
|
||||
((PIThread *)t)->__thread_func__();
|
||||
return __THREAD_FUNC_END__;
|
||||
@@ -60,13 +58,8 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {
|
||||
return __THREAD_FUNC_END__;
|
||||
}
|
||||
|
||||
#ifndef MICRO_PIP
|
||||
# define REGISTER_THREAD(t) __PIThreadCollection::instance()->registerThread(t)
|
||||
# define UNREGISTER_THREAD(t) __PIThreadCollection::instance()->unregisterThread(t)
|
||||
#else
|
||||
# define REGISTER_THREAD(t)
|
||||
# define UNREGISTER_THREAD(t)
|
||||
#endif
|
||||
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
@@ -457,7 +450,7 @@ __THREAD_FUNC_RET__ thread_function_once(void * t) {
|
||||
//! \return \c false если таймаут истёк
|
||||
|
||||
|
||||
#ifndef MICRO_PIP
|
||||
# ifndef PIP_NO_THREADS
|
||||
|
||||
__PIThreadCollection * __PIThreadCollection::instance() {
|
||||
return __PIThreadCollection_Initializer__::__instance__;
|
||||
@@ -523,18 +516,18 @@ __PIThreadCollection_Initializer__::~__PIThreadCollection_Initializer__() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICRO_PIP
|
||||
# endif // PIP_NO_THREADS
|
||||
|
||||
|
||||
PRIVATE_DEFINITION_START(PIThread)
|
||||
#if defined(WINDOWS)
|
||||
# if defined(WINDOWS)
|
||||
void * thread = nullptr;
|
||||
#elif defined(FREERTOS)
|
||||
# elif defined(FREERTOS)
|
||||
TaskHandle_t thread;
|
||||
#else
|
||||
# else
|
||||
pthread_t thread = 0;
|
||||
sched_param sparam;
|
||||
#endif
|
||||
# endif
|
||||
PRIVATE_DEFINITION_END(PIThread)
|
||||
|
||||
|
||||
@@ -572,25 +565,25 @@ PIThread::~PIThread() {
|
||||
PIINTROSPECTION_THREAD_DELETE(this);
|
||||
if (!running_ || PRIVATE->thread == 0) return;
|
||||
piCout << "[PIThread \"%1\"] Warning, terminate on destructor!"_tr("PIThread").arg(name());
|
||||
#ifdef FREERTOS
|
||||
# ifdef FREERTOS
|
||||
// void * ret(0);
|
||||
// PICout(PICoutManipulators::DefaultControls) << "~PIThread" << PRIVATE->thread;
|
||||
// PICout(PICoutManipulators::DefaultControls) << pthread_join(PRIVATE->thread, 0);
|
||||
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
|
||||
stopAndWait();
|
||||
// PICout(PICoutManipulators::DefaultControls) << "stopped!";
|
||||
#else
|
||||
# ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
# else
|
||||
pthread_cancel(PRIVATE->thread);
|
||||
# endif
|
||||
# else
|
||||
# ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
# else
|
||||
pthread_cancel(PRIVATE->thread);
|
||||
# endif
|
||||
# else
|
||||
TerminateThread(PRIVATE->thread, 0);
|
||||
CloseHandle(PRIVATE->thread);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
UNREGISTER_THREAD(this);
|
||||
PIINTROSPECTION_THREAD_STOP(this);
|
||||
terminating = running_ = false;
|
||||
@@ -668,32 +661,32 @@ void PIThread::stop() {
|
||||
void PIThread::terminate() {
|
||||
piCoutObj << "Warning, terminate!"_tr("PIThread");
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ..." << running_;
|
||||
#ifdef FREERTOS
|
||||
# ifdef FREERTOS
|
||||
PICout(PICoutManipulators::DefaultControls) << "FreeRTOS can't terminate pthreads! waiting for stop";
|
||||
stop(true);
|
||||
// PICout(PICoutManipulators::DefaultControls) << "stopped!";
|
||||
#else
|
||||
# else
|
||||
if (PRIVATE->thread == 0) return;
|
||||
UNREGISTER_THREAD(this);
|
||||
terminating = running_ = false;
|
||||
tid_ = -1;
|
||||
// PICout(PICoutManipulators::DefaultControls) << "terminate" << PRIVATE->thread;
|
||||
# ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
# ifndef WINDOWS
|
||||
# ifdef ANDROID
|
||||
pthread_kill(PRIVATE->thread, SIGTERM);
|
||||
# else
|
||||
# else
|
||||
// pthread_kill(PRIVATE->thread, SIGKILL);
|
||||
// void * ret(0);
|
||||
pthread_cancel(PRIVATE->thread);
|
||||
// pthread_join(PRIVATE->thread, &ret);
|
||||
# endif
|
||||
# else
|
||||
# endif
|
||||
# else
|
||||
TerminateThread(PRIVATE->thread, 0);
|
||||
CloseHandle(PRIVATE->thread);
|
||||
# endif
|
||||
# endif
|
||||
PRIVATE->thread = 0;
|
||||
end();
|
||||
#endif // FREERTOS
|
||||
# endif // FREERTOS
|
||||
PIINTROSPECTION_THREAD_STOP(this);
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "terminate ok" << running_;
|
||||
}
|
||||
@@ -701,31 +694,31 @@ void PIThread::terminate() {
|
||||
|
||||
int PIThread::priority2System(PIThread::Priority p) {
|
||||
switch (p) {
|
||||
#if defined(QNX)
|
||||
# if defined(QNX)
|
||||
case piLowerst: return 8;
|
||||
case piLow: return 9;
|
||||
case piNormal: return 10;
|
||||
case piHigh: return 11;
|
||||
case piHighest: return 12;
|
||||
#elif defined(WINDOWS)
|
||||
# elif defined(WINDOWS)
|
||||
case piLowerst: return -2;
|
||||
case piLow: return -1;
|
||||
case piNormal: return 0;
|
||||
case piHigh: return 1;
|
||||
case piHighest: return 2;
|
||||
#elif defined(FREERTOS)
|
||||
# elif defined(FREERTOS)
|
||||
case piLowerst: return 2;
|
||||
case piLow: return 3;
|
||||
case piNormal: return 4;
|
||||
case piHigh: return 5;
|
||||
case piHighest: return 6;
|
||||
#else
|
||||
# else
|
||||
case piLowerst: return 2;
|
||||
case piLow: return 1;
|
||||
case piNormal: return 0;
|
||||
case piHigh: return -1;
|
||||
case piHighest: return -2;
|
||||
#endif
|
||||
# endif
|
||||
default: return 0;
|
||||
}
|
||||
return 0;
|
||||
@@ -736,7 +729,7 @@ bool PIThread::_startThread(void * func) {
|
||||
terminating = false;
|
||||
running_ = true;
|
||||
|
||||
#ifdef FREERTOS
|
||||
# ifdef FREERTOS
|
||||
|
||||
auto name_ba = createThreadName();
|
||||
if (xTaskCreate((__THREAD_FUNC_RET__(*)(void *))func,
|
||||
@@ -749,20 +742,20 @@ bool PIThread::_startThread(void * func) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#elif defined(WINDOWS)
|
||||
# elif defined(WINDOWS)
|
||||
|
||||
if (PRIVATE->thread) CloseHandle(PRIVATE->thread);
|
||||
# ifdef CC_GCC
|
||||
# ifdef CC_GCC
|
||||
PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__(*)(void *))func, this, CREATE_SUSPENDED, 0);
|
||||
# else
|
||||
# else
|
||||
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, CREATE_SUSPENDED, 0);
|
||||
# endif
|
||||
# endif
|
||||
if (PRIVATE->thread != 0) {
|
||||
ResumeThread(PRIVATE->thread);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
# else
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
@@ -775,7 +768,7 @@ bool PIThread::_startThread(void * func) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
# endif
|
||||
|
||||
running_ = false;
|
||||
PRIVATE->thread = 0;
|
||||
@@ -787,30 +780,30 @@ bool PIThread::_startThread(void * func) {
|
||||
void PIThread::setPriority(PIThread::Priority prior) {
|
||||
priority_ = prior;
|
||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||
#ifdef FREERTOS
|
||||
# ifdef FREERTOS
|
||||
vTaskPrioritySet(PRIVATE->thread, priority2System(priority_));
|
||||
#else
|
||||
# ifndef WINDOWS
|
||||
# else
|
||||
# ifndef WINDOWS
|
||||
// PICout(PICoutManipulators::DefaultControls) << "setPriority" << PRIVATE->thread;
|
||||
int policy_ = 0;
|
||||
piZeroMemory(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
|
||||
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
|
||||
# endif
|
||||
#endif // FREERTOS
|
||||
# endif
|
||||
# endif // FREERTOS
|
||||
}
|
||||
|
||||
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
bool isExists(HANDLE hThread) {
|
||||
// errorClear();
|
||||
// piCout << "isExists" << hThread;
|
||||
@@ -821,7 +814,7 @@ bool isExists(HANDLE hThread) {
|
||||
// piCout << errorString();
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
|
||||
bool PIThread::waitForFinish(PISystemTime timeout) {
|
||||
@@ -857,18 +850,18 @@ bool PIThread::waitForStart(PISystemTime timeout) {
|
||||
|
||||
|
||||
void PIThread::_beginThread() {
|
||||
#ifndef WINDOWS
|
||||
# if !defined(ANDROID) && !defined(FREERTOS)
|
||||
# ifndef WINDOWS
|
||||
# if !defined(ANDROID) && !defined(FREERTOS)
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, 0);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
tid_ = GetCurrentThreadId();
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
# endif
|
||||
# ifdef LINUX
|
||||
tid_ = gettid();
|
||||
#endif
|
||||
# endif
|
||||
setPriority(priority_);
|
||||
setThreadName();
|
||||
PIINTROSPECTION_THREAD_START(this);
|
||||
@@ -887,13 +880,13 @@ void PIThread::_runThread() {
|
||||
if (lockRun) thread_mutex.lock();
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "ok";
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "...";
|
||||
#ifdef PIP_INTROSPECTION
|
||||
# ifdef PIP_INTROSPECTION
|
||||
PITimeMeasurer _tm;
|
||||
#endif
|
||||
# endif
|
||||
run();
|
||||
#ifdef PIP_INTROSPECTION
|
||||
# ifdef PIP_INTROSPECTION
|
||||
PIINTROSPECTION_THREAD_RUN_DONE(this, ullong(_tm.elapsed_u()));
|
||||
#endif
|
||||
# endif
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "run" << "ok";
|
||||
// printf("thread %p tick\n", this);
|
||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "ret_func" << "...";
|
||||
@@ -924,20 +917,20 @@ void PIThread::_endThread() {
|
||||
// PICout(PICoutManipulators::DefaultControls) << "pthread_exit" << (__privateinitializer__.p)->thread;
|
||||
UNREGISTER_THREAD(this);
|
||||
PIINTROSPECTION_THREAD_STOP(this);
|
||||
#if defined(WINDOWS)
|
||||
# if defined(WINDOWS)
|
||||
ec.callAndCancel();
|
||||
# ifdef CC_GCC
|
||||
# ifdef CC_GCC
|
||||
_endthreadex(0);
|
||||
# else
|
||||
# else
|
||||
ExitThread(0);
|
||||
# endif
|
||||
#elif defined(FREERTOS)
|
||||
# endif
|
||||
# elif defined(FREERTOS)
|
||||
PRIVATE->thread = 0;
|
||||
#else
|
||||
# else
|
||||
PRIVATE->thread = 0;
|
||||
ec.callAndCancel();
|
||||
pthread_exit(0);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1010,10 +1003,10 @@ void PIThread::runOnce(PIObject * object, const char * handler, const PIString &
|
||||
delete t;
|
||||
return;
|
||||
}
|
||||
#ifndef MICRO_PIP
|
||||
# ifndef PIP_NO_THREADS
|
||||
__PIThreadCollection::instance()->startedAuto(t);
|
||||
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||
#endif
|
||||
# endif
|
||||
t->startOnce();
|
||||
}
|
||||
|
||||
@@ -1044,10 +1037,10 @@ void PIThread::runOnce(std::function<void()> func, const PIString & name) {
|
||||
PIThread * t = new PIThread();
|
||||
t->setName(name);
|
||||
t->setSlot(std::move(func));
|
||||
#ifndef MICRO_PIP
|
||||
# ifndef PIP_NO_THREADS
|
||||
__PIThreadCollection::instance()->startedAuto(t);
|
||||
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||
#endif
|
||||
# endif
|
||||
t->startOnce();
|
||||
}
|
||||
|
||||
@@ -1063,15 +1056,15 @@ PIByteArray PIThread::createThreadName(int size) const {
|
||||
|
||||
|
||||
void PIThread::setThreadName() {
|
||||
#ifndef WINDOWS
|
||||
# ifndef WINDOWS
|
||||
auto name_ba = createThreadName();
|
||||
# ifdef MAC_OS
|
||||
# ifdef MAC_OS
|
||||
pthread_setname_np((const char *)name_ba.data());
|
||||
pthread_threadid_np(PRIVATE->thread, (__uint64_t *)&tid_);
|
||||
# else
|
||||
# else
|
||||
pthread_setname_np(PRIVATE->thread, (const char *)name_ba.data());
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1079,12 +1072,12 @@ bool PIThread::_waitForFinish(PISystemTime max_tm) {
|
||||
if (!running_) return true;
|
||||
state_notifier.waitFor(max_tm);
|
||||
if (!running_) return true;
|
||||
#ifdef WINDOWS
|
||||
# ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
return false;
|
||||
}
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
class PIThread;
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifndef MICRO_PIP
|
||||
# ifndef PIP_NO_THREADS
|
||||
class PIIntrospectionThreads;
|
||||
|
||||
class PIP_EXPORT __PIThreadCollection: public PIObject {
|
||||
@@ -75,7 +75,7 @@ public:
|
||||
};
|
||||
|
||||
static __PIThreadCollection_Initializer__ __PIThreadCollection_initializer__;
|
||||
#endif // MICRO_PIP
|
||||
# endif // PIP_NO_THREADS
|
||||
|
||||
//! \~english Callback executed by %PIThread with the current \a data() pointer.
|
||||
//! \~russian Обратный вызов, который %PIThread выполняет с текущим указателем \a data().
|
||||
@@ -99,9 +99,9 @@ typedef std::function<void(void *)> ThreadFunc;
|
||||
//! проход без повторяющегося цикла обработки очереди.
|
||||
class PIP_EXPORT PIThread: public PIObject {
|
||||
PIOBJECT_SUBCLASS(PIThread, PIObject);
|
||||
#ifndef MICRO_PIP
|
||||
# ifndef PIP_NO_THREADS
|
||||
friend class PIIntrospectionThreads;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
public:
|
||||
NO_COPY_CLASS(PIThread);
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include "pithreadnotifier.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
//! \class PIThreadNotifier pithreadnotifier.h
|
||||
@@ -142,3 +144,5 @@ void PIThreadNotifier::notify() {
|
||||
v.notifyAll();
|
||||
m.unlock();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Class for simply notify and wait in different threads
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
Ivan Pelipenko peri4ko@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
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "piconditionvar.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
//! \~\ingroup Thread
|
||||
//! \~\brief
|
||||
@@ -63,5 +64,6 @@ private:
|
||||
PIMutex m;
|
||||
PIConditionVariable v;
|
||||
};
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
#endif // PITHREADNOTIFIER_H
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include "pisysteminfo.h"
|
||||
#include "pithread.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
@@ -166,3 +168,5 @@ void PIThreadPoolLoop::exec(int index_start, int index_count, std::function<void
|
||||
setFunction(std::move(f));
|
||||
exec(index_start, index_count);
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
|
||||
Ivan Pelipenko, Stephan Fomenko
|
||||
Ivan Pelipenko, Stephan Fomenko
|
||||
|
||||
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
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
#include "pisysteminfo.h"
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
|
||||
//! \addtogroup Thread
|
||||
//! \{
|
||||
//! \class PIThreadPoolWorker pithreadpoolworker.h
|
||||
@@ -177,7 +179,7 @@ int64_t PIThreadPoolWorker::enqueueTask(std::function<void(int64_t)> func, PIObj
|
||||
contexts.remove(context);
|
||||
auto qref = tasks_queue.getRef();
|
||||
// auto prev_size = qref->size();
|
||||
// piCout << "deleted" << (void *)context << qref->map<void *>([](const Task & t) { return t.context; });
|
||||
// piCout << "deleted" << (void *)context << qref->map<void *>([](const Task & t) { return t.context; });
|
||||
qref->removeWhere([context](const Task & t) { return t.context == context; });
|
||||
// piCout << prev_size << qref->size() << qref->map<void *>([](const Task & t) { return t.context; });
|
||||
}));
|
||||
@@ -236,3 +238,5 @@ void PIThreadPoolWorker::threadFunc(Worker * w) {
|
||||
taskFinished(task.id);
|
||||
w->notifier.notify();
|
||||
}
|
||||
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
|
||||
Ivan Pelipenko, Stephan Fomenko
|
||||
Ivan Pelipenko, Stephan Fomenko
|
||||
|
||||
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
|
||||
@@ -33,6 +33,7 @@
|
||||
//! \~\brief
|
||||
//! \~english Fixed-size pool of worker threads for generic-purpose tasks.
|
||||
//! \~russian Фиксированный пул рабочих потоков для задач общего назначения.
|
||||
#ifndef PIP_NO_THREADS
|
||||
class PIP_EXPORT PIThreadPoolWorker: public PIObject {
|
||||
PIOBJECT(PIThreadPoolWorker)
|
||||
|
||||
@@ -109,7 +110,7 @@ public:
|
||||
template<typename O>
|
||||
int64_t enqueueTask(O * obj, void (O::*member_func)(int64_t)) {
|
||||
return enqueueTask([obj, member_func](int64_t id) { (obj->*member_func)(id); },
|
||||
PIObject::isPIObject(obj) ? dynamic_cast<PIObject *>(obj) : nullptr);
|
||||
PIObject::isPIObject(obj) ? dynamic_cast<PIObject *>(obj) : nullptr);
|
||||
}
|
||||
|
||||
//! \~english Queue class member method to execution. Returns task ID.
|
||||
@@ -117,7 +118,7 @@ public:
|
||||
template<typename O>
|
||||
int64_t enqueueTask(O * obj, void (O::*member_func)()) {
|
||||
return enqueueTask([obj, member_func](int64_t) { (obj->*member_func)(); },
|
||||
PIObject::isPIObject(obj) ? dynamic_cast<PIObject *>(obj) : nullptr);
|
||||
PIObject::isPIObject(obj) ? dynamic_cast<PIObject *>(obj) : nullptr);
|
||||
}
|
||||
|
||||
//! \~english Remove task with id \a id from queue. Returns if task delete.
|
||||
@@ -172,6 +173,7 @@ private:
|
||||
PISet<PIObject *> contexts;
|
||||
std::atomic_int64_t next_task_id = {0};
|
||||
};
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
|
||||
#endif // PITHREADPOOLWORKER_H
|
||||
|
||||
Reference in New Issue
Block a user