refactor: rename PIP_NO_\* to PIP_HAS_\* with inverted logic
All feature flags now use positive naming (enabled by default): - PIP_HAS_FILESYSTEM, PIP_HAS_THREADS, PIP_HAS_SOCKET - PIP_HAS_PROCESS, PIP_HAS_DYNLIB, PIP_HAS_FFT, PIP_HAS_SERIAL Preprocessor guards inverted: - #ifndef PIP_NO_X → #ifdef PIP_HAS_X - #ifdef PIP_NO_X → #ifndef PIP_HAS_X CMake options default ON instead of OFF. Platform blocks set flags OFF to disable features. 85 files transformed via Python script + 2 manual fixes.
This commit is contained in:
@@ -117,7 +117,7 @@
|
||||
//!
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
PIMutex PIIODevice::nfp_mutex;
|
||||
#endif
|
||||
PIMap<PIString, PIString> PIIODevice::nfp_cache;
|
||||
@@ -198,7 +198,7 @@ void PIIODevice::setThreadedReadBufferSize(int new_size) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
bool PIIODevice::isThreadedRead() const {
|
||||
return read_thread.isRunning();
|
||||
}
|
||||
@@ -252,7 +252,7 @@ bool PIIODevice::waitThreadedReadFinished(PISystemTime timeout) {
|
||||
|
||||
|
||||
bool PIIODevice::isThreadedWrite() const {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
return write_thread.isRunning();
|
||||
#else
|
||||
return false;
|
||||
@@ -261,14 +261,14 @@ bool PIIODevice::isThreadedWrite() const {
|
||||
|
||||
|
||||
void PIIODevice::startThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
if (!write_thread.isRunning()) write_thread.startOnce();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PIIODevice::stopThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
if (!write_thread.isRunning()) return;
|
||||
write_thread.stop();
|
||||
#endif
|
||||
@@ -276,14 +276,14 @@ void PIIODevice::stopThreadedWrite() {
|
||||
|
||||
|
||||
void PIIODevice::terminateThreadedWrite() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
write_thread.terminate();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool PIIODevice::waitThreadedWriteFinished(PISystemTime timeout) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
return write_thread.waitForFinish(timeout);
|
||||
#else
|
||||
(void)timeout;
|
||||
@@ -293,7 +293,7 @@ bool PIIODevice::waitThreadedWriteFinished(PISystemTime timeout) {
|
||||
|
||||
|
||||
void PIIODevice::clearThreadedWriteQueue() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
write_thread.lock();
|
||||
write_queue.clear();
|
||||
write_thread.unlock();
|
||||
@@ -302,7 +302,7 @@ void PIIODevice::clearThreadedWriteQueue() {
|
||||
|
||||
|
||||
void PIIODevice::start() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
startThreadedRead();
|
||||
#endif
|
||||
startThreadedWrite();
|
||||
@@ -310,7 +310,7 @@ void PIIODevice::start() {
|
||||
|
||||
|
||||
void PIIODevice::stop() {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
stopThreadedRead();
|
||||
#endif
|
||||
stopThreadedWrite();
|
||||
@@ -319,7 +319,7 @@ void PIIODevice::stop() {
|
||||
|
||||
void PIIODevice::stopAndWait(PISystemTime timeout) {
|
||||
stop();
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
waitThreadedReadFinished(timeout);
|
||||
#endif
|
||||
waitThreadedWriteFinished(timeout);
|
||||
@@ -357,7 +357,7 @@ void PIIODevice::_init() {
|
||||
setOptions(0);
|
||||
setReopenEnabled(true);
|
||||
setReopenTimeout(1_s);
|
||||
#ifdef PIP_NO_THREADS
|
||||
#ifndef PIP_HAS_THREADS
|
||||
threaded_read_buffer_size = 512;
|
||||
#else
|
||||
threaded_read_buffer_size = 4_KiB;
|
||||
@@ -368,11 +368,11 @@ void PIIODevice::_init() {
|
||||
if (!isOpened()) open();
|
||||
});
|
||||
read_thread.setSlot([this](void *) { read_func(); });
|
||||
#endif // PIP_NO_THREADS
|
||||
#endif // PIP_HAS_THREADS
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
void PIIODevice::write_func() {
|
||||
while (!write_thread.isStopping()) {
|
||||
while (!write_queue.isEmpty()) {
|
||||
@@ -412,7 +412,7 @@ void PIIODevice::read_func() {
|
||||
threadedRead(buffer_tr.data(), readed_);
|
||||
threadedReadEvent(buffer_tr.data(), readed_);
|
||||
}
|
||||
#endif // PIP_NO_THREADS
|
||||
#endif // PIP_HAS_THREADS
|
||||
|
||||
|
||||
PIIODevice * PIIODevice::newDeviceByPrefix(const char * prefix) {
|
||||
@@ -443,7 +443,7 @@ PIByteArray PIIODevice::readForTime(PISystemTime timeout) {
|
||||
}
|
||||
|
||||
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
ullong PIIODevice::writeThreaded(const PIByteArray & data) {
|
||||
write_thread.lock();
|
||||
write_queue.enqueue(PIPair<PIByteArray, ullong>(data, tri));
|
||||
@@ -663,17 +663,17 @@ PIIODevice * PIIODevice::createFromVariant(const PIVariantTypes::IODevice & d) {
|
||||
|
||||
|
||||
PIString PIIODevice::normalizeFullPath(const PIString & full_path) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
nfp_mutex.lock();
|
||||
#endif
|
||||
PIString ret = nfp_cache.value(full_path);
|
||||
if (!ret.isEmpty()) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
nfp_mutex.unlock();
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
nfp_mutex.unlock();
|
||||
#endif
|
||||
PIIODevice * d = createFromFullPath(full_path);
|
||||
@@ -685,7 +685,7 @@ PIString PIIODevice::normalizeFullPath(const PIString & full_path) {
|
||||
|
||||
|
||||
void PIIODevice::cacheFullPath(const PIString & full_path, const PIIODevice * d) {
|
||||
#ifndef PIP_NO_THREADS
|
||||
#ifdef PIP_HAS_THREADS
|
||||
PIMutexLocker nfp_ml(nfp_mutex);
|
||||
#endif
|
||||
nfp_cache[full_path] = d->constructFullPath();
|
||||
|
||||
Reference in New Issue
Block a user