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:
@@ -117,7 +117,9 @@
|
||||
//!
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
PIMutex PIIODevice::nfp_mutex;
|
||||
#endif
|
||||
PIMap<PIString, PIString> PIIODevice::nfp_cache;
|
||||
|
||||
|
||||
@@ -138,6 +140,7 @@ PIIODevice::PIIODevice(const PIString & path, PIIODevice::DeviceMode mode): PIOb
|
||||
PIIODevice::~PIIODevice() {
|
||||
destroying = true;
|
||||
stopAndWait();
|
||||
(void)destroying;
|
||||
}
|
||||
|
||||
|
||||
@@ -195,6 +198,7 @@ void PIIODevice::setThreadedReadBufferSize(int new_size) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
bool PIIODevice::isThreadedRead() const {
|
||||
return read_thread.isRunning();
|
||||
}
|
||||
@@ -216,16 +220,12 @@ void PIIODevice::startThreadedRead(ReadRetFunc func) {
|
||||
|
||||
void PIIODevice::stopThreadedRead() {
|
||||
if (!isThreadedRead()) return;
|
||||
#ifdef MICRO_PIP
|
||||
read_thread.stop();
|
||||
#else
|
||||
read_thread.stop();
|
||||
if (!destroying) {
|
||||
interrupt();
|
||||
} else {
|
||||
piCoutObj << "Error: Device is running after destructor!"_tr("PIIODevice");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -248,56 +248,80 @@ bool PIIODevice::waitThreadedReadFinished(PISystemTime timeout) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool PIIODevice::isThreadedWrite() const {
|
||||
#ifndef PIP_NO_THREADS
|
||||
return write_thread.isRunning();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::startThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
if (!write_thread.isRunning()) write_thread.startOnce();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
if (!write_thread.isRunning()) return;
|
||||
write_thread.stop();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::terminateThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
write_thread.terminate();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::waitThreadedWriteFinished(PISystemTime timeout) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
return write_thread.waitForFinish(timeout);
|
||||
#else
|
||||
(void)timeout;
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::clearThreadedWriteQueue() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
write_thread.lock();
|
||||
write_queue.clear();
|
||||
write_thread.unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::start() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
startThreadedRead();
|
||||
#endif
|
||||
startThreadedWrite();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stop() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
stopThreadedRead();
|
||||
#endif
|
||||
stopThreadedWrite();
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopAndWait(PISystemTime timeout) {
|
||||
stop();
|
||||
#ifndef PIP_NO_THREADS
|
||||
waitThreadedReadFinished(timeout);
|
||||
#endif
|
||||
waitThreadedWriteFinished(timeout);
|
||||
}
|
||||
|
||||
@@ -333,11 +357,10 @@ void PIIODevice::_init() {
|
||||
setOptions(0);
|
||||
setReopenEnabled(true);
|
||||
setReopenTimeout(1_s);
|
||||
#ifdef MICRO_PIP
|
||||
#ifdef PIP_NO_THREADS
|
||||
threaded_read_buffer_size = 512;
|
||||
#else
|
||||
threaded_read_buffer_size = 4_KiB;
|
||||
#endif
|
||||
read_thread.setName("_S.PIIODev.read");
|
||||
write_thread.setName("_S.PIIODev.write");
|
||||
CONNECT(void, &write_thread, started, this, write_func);
|
||||
@@ -345,9 +368,11 @@ void PIIODevice::_init() {
|
||||
if (!isOpened()) open();
|
||||
});
|
||||
read_thread.setSlot([this](void *) { read_func(); });
|
||||
#endif // PIP_NO_THREADS
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
void PIIODevice::write_func() {
|
||||
while (!write_thread.isStopping()) {
|
||||
while (!write_queue.isEmpty()) {
|
||||
@@ -362,15 +387,6 @@ void PIIODevice::write_func() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
||||
if (!prefix) return nullptr;
|
||||
auto fi = fabrics().value(prefix);
|
||||
if (fi.fabricator) return fi.fabricator();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::read_func() {
|
||||
if (!isReadable()) {
|
||||
read_thread.stop();
|
||||
@@ -391,13 +407,20 @@ void PIIODevice::read_func() {
|
||||
if (read_thread.isStopping()) return;
|
||||
if (readed_ <= 0) {
|
||||
piMSleep(threaded_read_timeout_ms);
|
||||
// cout << readed_ << ", " << errno << ", " << errorString() << endl;
|
||||
return;
|
||||
}
|
||||
// piCoutObj << "readed" << readed_;// << ", " << errno << ", " << errorString();
|
||||
threadedRead(buffer_tr.data(), readed_);
|
||||
threadedReadEvent(buffer_tr.data(), readed_);
|
||||
}
|
||||
#endif // PIP_NO_THREADS
|
||||
|
||||
|
||||
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
||||
if (!prefix) return nullptr;
|
||||
auto fi = fabrics().value(prefix);
|
||||
if (fi.fabricator) return fi.fabricator();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
PIByteArray PIIODevice::readForTime(PISystemTime timeout) {
|
||||
@@ -420,6 +443,7 @@ PIByteArray PIIODevice::readForTime(PISystemTime timeout) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
ullong PIIODevice::writeThreaded(const PIByteArray & data) {
|
||||
write_thread.lock();
|
||||
write_queue.enqueue(PIPair<PIByteArray, ullong>(data, tri));
|
||||
@@ -427,6 +451,7 @@ ullong PIIODevice::writeThreaded(const PIByteArray & data) {
|
||||
write_thread.unlock();
|
||||
return tri - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool PIIODevice::open() {
|
||||
@@ -543,7 +568,7 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
|
||||
if (o == "br"_a || o == "blockr"_a || o == "blockread"_a || o == "blockingread"_a) op |= BlockingRead;
|
||||
if (o == "bw"_a || o == "blockw"_a || o == "blockwrite"_a || o == "blockingwrite"_a) op |= BlockingWrite;
|
||||
if (o == "brw"_a || o == "bwr"_a || o == "blockrw"_a || o == "blockwr"_a || o == "blockreadrite"_a ||
|
||||
o == "blockingreadwrite"_a)
|
||||
o == "blockingreadwrite"_a)
|
||||
op |= BlockingRead | BlockingWrite;
|
||||
}
|
||||
fpwm.cutRight(fpwm.length() - fpwm.findLast('(')).trim();
|
||||
@@ -638,15 +663,20 @@ PIIODevice * PIIODevice::createFromVariant(const PIVariantTypes::IODevice & d) {
|
||||
|
||||
|
||||
PIString PIIODevice::normalizeFullPath(const PIString & full_path) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
nfp_mutex.lock();
|
||||
#endif
|
||||
PIString ret = nfp_cache.value(full_path);
|
||||
if (!ret.isEmpty()) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
nfp_mutex.unlock();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
#ifndef PIP_NO_THREADS
|
||||
nfp_mutex.unlock();
|
||||
#endif
|
||||
PIIODevice * d = createFromFullPath(full_path);
|
||||
// piCout << "normalizeFullPath" << d;
|
||||
if (d == 0) return PIString();
|
||||
ret = d->constructFullPath();
|
||||
delete d;
|
||||
@@ -655,7 +685,9 @@ PIString PIIODevice::normalizeFullPath(const PIString & full_path) {
|
||||
|
||||
|
||||
void PIIODevice::cacheFullPath(const PIString & full_path, const PIIODevice * d) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
PIMutexLocker nfp_ml(nfp_mutex);
|
||||
#endif
|
||||
nfp_cache[full_path] = d->constructFullPath();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user