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:
+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
|
||||
|
||||
Reference in New Issue
Block a user