more literals, use some in PIP, small refactor PIThread::start (clang-format mistakes)
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include "pibinarylog.h"
|
#include "pibinarylog.h"
|
||||||
|
|
||||||
#include "pidir.h"
|
#include "pidir.h"
|
||||||
|
#include "piliterals.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
#define PIBINARYLOG_VERSION_OLD 0x31
|
#define PIBINARYLOG_VERSION_OLD 0x31
|
||||||
@@ -57,7 +58,7 @@ PIBinaryLog::PIBinaryLog() {
|
|||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
setThreadedReadBufferSize(512);
|
setThreadedReadBufferSize(512);
|
||||||
#else
|
#else
|
||||||
setThreadedReadBufferSize(65536);
|
setThreadedReadBufferSize(64_KiB);
|
||||||
#endif
|
#endif
|
||||||
is_started = is_indexed = is_pause = false;
|
is_started = is_indexed = is_pause = false;
|
||||||
create_index_on_fly = false;
|
create_index_on_fly = false;
|
||||||
@@ -67,9 +68,9 @@ PIBinaryLog::PIBinaryLog() {
|
|||||||
setPlaySpeed(1.);
|
setPlaySpeed(1.);
|
||||||
setDefaultID(1);
|
setDefaultID(1);
|
||||||
setPlaySpeed(1.0);
|
setPlaySpeed(1.0);
|
||||||
setPlayDelay(PISystemTime::fromSeconds(1.0));
|
setPlayDelay(1_s);
|
||||||
setPlayRealTime();
|
setPlayRealTime();
|
||||||
setSplitTime(PISystemTime(600, 0));
|
setSplitTime(600_s);
|
||||||
setSplitRecordCount(1000);
|
setSplitRecordCount(1000);
|
||||||
setSplitFileSize(0xFFFFFF);
|
setSplitFileSize(0xFFFFFF);
|
||||||
setSplitMode(SplitNone);
|
setSplitMode(SplitNone);
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "piconstchars.h"
|
#include "piconstchars.h"
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
|
#include "piliterals.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
#include "pisysteminfo.h"
|
#include "pisysteminfo.h"
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@@ -167,11 +168,11 @@ void PIEthernet::construct() {
|
|||||||
setTTL(64);
|
setTTL(64);
|
||||||
setMulticastTTL(1);
|
setMulticastTTL(1);
|
||||||
server_thread_.setData(this);
|
server_thread_.setData(this);
|
||||||
server_thread_.setName("__S__server_thread");
|
server_thread_.setName("__S__server_thread"_a);
|
||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
setThreadedReadBufferSize(512);
|
setThreadedReadBufferSize(512);
|
||||||
#else
|
#else
|
||||||
setThreadedReadBufferSize(65536);
|
setThreadedReadBufferSize(64_KiB);
|
||||||
#endif
|
#endif
|
||||||
// setPriority(piHigh);
|
// setPriority(piHigh);
|
||||||
}
|
}
|
||||||
@@ -305,7 +306,7 @@ bool PIEthernet::closeDevice() {
|
|||||||
server_thread_.stop();
|
server_thread_.stop();
|
||||||
PRIVATE->event.interrupt();
|
PRIVATE->event.interrupt();
|
||||||
if (server_thread_.isRunning()) {
|
if (server_thread_.isRunning()) {
|
||||||
if (!server_thread_.waitForFinish(1000)) server_thread_.terminate();
|
if (!server_thread_.waitForFinish(1_s)) server_thread_.terminate();
|
||||||
}
|
}
|
||||||
PRIVATE->event.destroy();
|
PRIVATE->event.destroy();
|
||||||
if (sock_s == sock) sock_s = -1;
|
if (sock_s == sock) sock_s = -1;
|
||||||
@@ -487,7 +488,7 @@ bool PIEthernet::listen(bool threaded) {
|
|||||||
if (server_thread_.isRunning()) {
|
if (server_thread_.isRunning()) {
|
||||||
if (!server_bounded) return true;
|
if (!server_bounded) return true;
|
||||||
server_thread_.stop();
|
server_thread_.stop();
|
||||||
if (!server_thread_.waitForFinish(100)) server_thread_.terminate();
|
if (!server_thread_.waitForFinish(100_ms)) server_thread_.terminate();
|
||||||
}
|
}
|
||||||
listen_threaded = true;
|
listen_threaded = true;
|
||||||
server_bounded = false;
|
server_bounded = false;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
# include <fcntl.h>
|
# include <fcntl.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include "piliterals.h"
|
||||||
|
|
||||||
|
|
||||||
//! \class PIGPIO pigpio.h
|
//! \class PIGPIO pigpio.h
|
||||||
@@ -71,7 +72,7 @@ PIGPIO::PIGPIO(): PIThread() {}
|
|||||||
|
|
||||||
PIGPIO::~PIGPIO() {
|
PIGPIO::~PIGPIO() {
|
||||||
stop();
|
stop();
|
||||||
waitForFinish(100);
|
waitForFinish(100_ms);
|
||||||
PIMutexLocker ml(mutex);
|
PIMutexLocker ml(mutex);
|
||||||
#ifdef GPIO_SYS_CLASS
|
#ifdef GPIO_SYS_CLASS
|
||||||
PIVector<int> ids = gpio_.keys();
|
PIVector<int> ids = gpio_.keys();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "piconfig.h"
|
#include "piconfig.h"
|
||||||
#include "piconnection.h"
|
#include "piconnection.h"
|
||||||
|
#include "piliterals.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -311,7 +312,7 @@ void PIIODevice::_init() {
|
|||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
threaded_read_buffer_size = 512;
|
threaded_read_buffer_size = 512;
|
||||||
#else
|
#else
|
||||||
threaded_read_buffer_size = 4096;
|
threaded_read_buffer_size = 4_KiB;
|
||||||
#endif
|
#endif
|
||||||
read_thread.setName("__S__.PIIODevice.read_thread");
|
read_thread.setName("__S__.PIIODevice.read_thread");
|
||||||
write_thread.setName("__S__.PIIODevice.write_thread");
|
write_thread.setName("__S__.PIIODevice.write_thread");
|
||||||
@@ -471,7 +472,7 @@ bool PIIODevice::configure(const PIString & config_file, const PIString & sectio
|
|||||||
|
|
||||||
|
|
||||||
PIString PIIODevice::constructFullPath() const {
|
PIString PIIODevice::constructFullPath() const {
|
||||||
return fullPathPrefix().toString() + PIStringAscii("://") + constructFullPathDevice() + fullPathOptions();
|
return fullPathPrefix().toString() + "://"_a + constructFullPathDevice() + fullPathOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -511,18 +512,12 @@ void PIIODevice::splitFullPath(PIString fpwm, PIString * full_path, DeviceMode *
|
|||||||
PIStringList opts(dms.split(","));
|
PIStringList opts(dms.split(","));
|
||||||
piForeachC(PIString & o, opts) {
|
piForeachC(PIString & o, opts) {
|
||||||
// piCout << dms;
|
// piCout << dms;
|
||||||
if (o == PIStringAscii("r") || o == PIStringAscii("ro") || o == PIStringAscii("read") || o == PIStringAscii("readonly"))
|
if (o == "r"_a || o == "ro"_a || o == "read"_a || o == "readonly"_a) dm |= ReadOnly;
|
||||||
dm |= ReadOnly;
|
if (o == "w"_a || o == "wo"_a || o == "write"_a || o == "writeonly"_a) dm |= WriteOnly;
|
||||||
if (o == PIStringAscii("w") || o == PIStringAscii("wo") || o == PIStringAscii("write") || o == PIStringAscii("writeonly"))
|
if (o == "br"_a || o == "blockr"_a || o == "blockread"_a || o == "blockingread"_a) op |= BlockingRead;
|
||||||
dm |= WriteOnly;
|
if (o == "bw"_a || o == "blockw"_a || o == "blockwrite"_a || o == "blockingwrite"_a) op |= BlockingWrite;
|
||||||
if (o == PIStringAscii("br") || o == PIStringAscii("blockr") || o == PIStringAscii("blockread") ||
|
if (o == "brw"_a || o == "bwr"_a || o == "blockrw"_a || o == "blockwr"_a || o == "blockreadrite"_a ||
|
||||||
o == PIStringAscii("blockingread"))
|
o == "blockingreadwrite"_a)
|
||||||
op |= BlockingRead;
|
|
||||||
if (o == PIStringAscii("bw") || o == PIStringAscii("blockw") || o == PIStringAscii("blockwrite") ||
|
|
||||||
o == PIStringAscii("blockingwrite"))
|
|
||||||
op |= BlockingWrite;
|
|
||||||
if (o == PIStringAscii("brw") || o == PIStringAscii("bwr") || o == PIStringAscii("blockrw") || o == PIStringAscii("blockwr") ||
|
|
||||||
o == PIStringAscii("blockreadrite") || o == PIStringAscii("blockingreadwrite"))
|
|
||||||
op |= BlockingRead | BlockingWrite;
|
op |= BlockingRead | BlockingWrite;
|
||||||
}
|
}
|
||||||
fpwm.cutRight(fpwm.length() - fpwm.findLast('(')).trim();
|
fpwm.cutRight(fpwm.length() - fpwm.findLast('(')).trim();
|
||||||
@@ -565,29 +560,29 @@ void PIIODevice::registerDevice(PIConstChars prefix, PIConstChars classname, PII
|
|||||||
|
|
||||||
PIString PIIODevice::fullPathOptions() const {
|
PIString PIIODevice::fullPathOptions() const {
|
||||||
if (mode_ == ReadWrite && options_ == 0) return PIString();
|
if (mode_ == ReadWrite && options_ == 0) return PIString();
|
||||||
PIString ret(" (");
|
PIString ret(" ("_a);
|
||||||
bool f = true;
|
bool f = true;
|
||||||
if (mode_ == ReadOnly) {
|
if (mode_ == ReadOnly) {
|
||||||
if (!f) ret += ",";
|
if (!f) ret += ","_a;
|
||||||
f = false;
|
f = false;
|
||||||
ret += "ro";
|
ret += "ro"_a;
|
||||||
}
|
}
|
||||||
if (mode_ == WriteOnly) {
|
if (mode_ == WriteOnly) {
|
||||||
if (!f) ret += ",";
|
if (!f) ret += ","_a;
|
||||||
f = false;
|
f = false;
|
||||||
ret += "wo";
|
ret += "wo"_a;
|
||||||
}
|
}
|
||||||
if (options_[BlockingRead]) {
|
if (options_[BlockingRead]) {
|
||||||
if (!f) ret += ",";
|
if (!f) ret += ","_a;
|
||||||
f = false;
|
f = false;
|
||||||
ret += "br";
|
ret += "br"_a;
|
||||||
}
|
}
|
||||||
if (options_[BlockingWrite]) {
|
if (options_[BlockingWrite]) {
|
||||||
if (!f) ret += ",";
|
if (!f) ret += ","_a;
|
||||||
f = false;
|
f = false;
|
||||||
ret += "bw";
|
ret += "bw"_a;
|
||||||
}
|
}
|
||||||
return ret + ")";
|
return ret + ")"_a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include "pisharedmemory.h"
|
#include "pisharedmemory.h"
|
||||||
|
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
|
#include "piliterals.h"
|
||||||
#include "pipropertystorage.h"
|
#include "pipropertystorage.h"
|
||||||
#if defined(LINUX) || defined(MAC_OS)
|
#if defined(LINUX) || defined(MAC_OS)
|
||||||
# define SHM_POSIX
|
# define SHM_POSIX
|
||||||
@@ -77,7 +78,7 @@ PRIVATE_DEFINITION_END(PISharedMemory)
|
|||||||
|
|
||||||
PISharedMemory::PISharedMemory(): PIIODevice() {
|
PISharedMemory::PISharedMemory(): PIIODevice() {
|
||||||
initPrivate();
|
initPrivate();
|
||||||
dsize = 65536;
|
dsize = 64_KiB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "pipacketextractor.h"
|
#include "pipacketextractor.h"
|
||||||
|
|
||||||
|
#include "piliterals.h"
|
||||||
|
|
||||||
|
|
||||||
/** \class PIPacketExtractor
|
/** \class PIPacketExtractor
|
||||||
* \brief Packets extractor
|
* \brief Packets extractor
|
||||||
@@ -99,7 +101,7 @@ void PIPacketExtractor::construct() {
|
|||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
setThreadedReadBufferSize(512);
|
setThreadedReadBufferSize(512);
|
||||||
#else
|
#else
|
||||||
setThreadedReadBufferSize(65536);
|
setThreadedReadBufferSize(64_KiB);
|
||||||
#endif
|
#endif
|
||||||
setDevice(nullptr);
|
setDevice(nullptr);
|
||||||
setSplitMode(None);
|
setSplitMode(None);
|
||||||
|
|||||||
40
libs/main/literals/piliterals.h
Normal file
40
libs/main/literals/piliterals.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*! \file piliterals.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \~\brief
|
||||||
|
* \~english C++11 literals
|
||||||
|
* \~russian C++11 суффиксы
|
||||||
|
*
|
||||||
|
* \~\details
|
||||||
|
* \~english
|
||||||
|
* Include all literals_*.h files
|
||||||
|
* \~russian
|
||||||
|
* Включает все файлы literals_*.h
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
C++11 literals
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 PILITERALS_H
|
||||||
|
#define PILITERALS_H
|
||||||
|
|
||||||
|
#include "piliterals_bytearray.h"
|
||||||
|
#include "piliterals_bytes.h"
|
||||||
|
#include "piliterals_string.h"
|
||||||
|
#include "piliterals_time.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
46
libs/main/literals/piliterals_bytearray.h
Normal file
46
libs/main/literals/piliterals_bytearray.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*! \file piliterals_bytearray.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \~\brief
|
||||||
|
* \~english PIByteArray C++11 literals
|
||||||
|
* \~russian C++11 суффиксы PIByteArray
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
PIByteArray C++11 literals
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 PILITERALS_BYTEARRAY_H
|
||||||
|
#define PILITERALS_BYTEARRAY_H
|
||||||
|
|
||||||
|
#include "pibytearray.h"
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIByteArray from hex string (e.g. "1a2e3f")
|
||||||
|
//! \~russian PIByteArray из hex строки (например "1a2e3f")
|
||||||
|
inline PIByteArray operator""_hex(const char * v, size_t sz) {
|
||||||
|
return PIByteArray::fromHex(PIStringAscii(v, sz));
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIByteArray from base64 string (e.g. "aGVsbG8=")
|
||||||
|
//! \~russian PIByteArray из base64 строки (например "aGVsbG8=")
|
||||||
|
inline PIByteArray operator""_base64(const char * v, size_t sz) {
|
||||||
|
return PIByteArray::fromBase64(PIStringAscii(v, sz));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/*! \file piliterals.h
|
/*! \file piliterals_bytes.h
|
||||||
* \ingroup Core
|
* \ingroup Core
|
||||||
* \~\brief
|
* \~\brief
|
||||||
* \~english Bytes C++11 literals
|
* \~english Bytes C++11 literals for bytes
|
||||||
* \~russian C++11 байтовые суффиксы
|
* \~russian C++11 байтовые суффиксы
|
||||||
*
|
*
|
||||||
* \~\details
|
* \~\details
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
PIP - Platform Independent Primitives
|
PIP - Platform Independent Primitives
|
||||||
Bytes C++11 literals
|
Bytes C++11 literals for bytes
|
||||||
Ivan Pelipenko peri4ko@yandex.ru
|
Ivan Pelipenko peri4ko@yandex.ru
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
@@ -33,35 +33,35 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef PILITERALS_H
|
#ifndef PILITERALS_BYTES_H
|
||||||
#define PILITERALS_H
|
#define PILITERALS_BYTES_H
|
||||||
|
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Kilobytes, x1000
|
//! \~english Kilobytes, x1000
|
||||||
//! \~russian Килобайт, x1000
|
//! \~russian Килобайт, x1000
|
||||||
unsigned long long operator""_KB(long double v) {
|
constexpr unsigned long long operator""_KB(long double v) {
|
||||||
return v * 1000.;
|
return v * 1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Kilobytes, x1000
|
//! \~english Kilobytes, x1000
|
||||||
//! \~russian Килобайт, x1000
|
//! \~russian Килобайт, x1000
|
||||||
unsigned long long operator""_KB(unsigned long long v) {
|
constexpr unsigned long long operator""_KB(unsigned long long v) {
|
||||||
return v * 1000;
|
return v * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Kibibytes, x1024 (2^10)
|
//! \~english Kibibytes, x1024 (2^10)
|
||||||
//! \~russian Кибибайт, x1024 (2^10)
|
//! \~russian Кибибайт, x1024 (2^10)
|
||||||
unsigned long long operator""_KiB(long double v) {
|
constexpr unsigned long long operator""_KiB(long double v) {
|
||||||
return v * 1024.;
|
return v * 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Kibibytes, x1024 (2^10)
|
//! \~english Kibibytes, x1024 (2^10)
|
||||||
//! \~russian Кибибайт, x1024 (2^10)
|
//! \~russian Кибибайт, x1024 (2^10)
|
||||||
unsigned long long operator""_KiB(unsigned long long v) {
|
constexpr unsigned long long operator""_KiB(unsigned long long v) {
|
||||||
return v * 1024;
|
return v * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,28 +69,28 @@ unsigned long long operator""_KiB(unsigned long long v) {
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Megabytes, x1000.000
|
//! \~english Megabytes, x1000.000
|
||||||
//! \~russian Мегабайт, x1000.000
|
//! \~russian Мегабайт, x1000.000
|
||||||
unsigned long long operator""_MB(long double v) {
|
constexpr unsigned long long operator""_MB(long double v) {
|
||||||
return v * 1000. * 1000.;
|
return v * 1000. * 1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Megabytes, x1000.000
|
//! \~english Megabytes, x1000.000
|
||||||
//! \~russian Мегабайт, x1000.000
|
//! \~russian Мегабайт, x1000.000
|
||||||
unsigned long long operator""_MB(unsigned long long v) {
|
constexpr unsigned long long operator""_MB(unsigned long long v) {
|
||||||
return v * 1000 * 1000;
|
return v * 1000 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Mebibytes, x1.048.576 (2^20)
|
//! \~english Mebibytes, x1.048.576 (2^20)
|
||||||
//! \~russian Мебибайт, x1.048.576 (2^20)
|
//! \~russian Мебибайт, x1.048.576 (2^20)
|
||||||
unsigned long long operator""_MiB(long double v) {
|
constexpr unsigned long long operator""_MiB(long double v) {
|
||||||
return v * 1024. * 1024.;
|
return v * 1024. * 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Mebibytes, x1.048.576 (2^20)
|
//! \~english Mebibytes, x1.048.576 (2^20)
|
||||||
//! \~russian Мебибайт, x1.048.576 (2^20)
|
//! \~russian Мебибайт, x1.048.576 (2^20)
|
||||||
unsigned long long operator""_MiB(unsigned long long v) {
|
constexpr unsigned long long operator""_MiB(unsigned long long v) {
|
||||||
return v * 1024 * 1024;
|
return v * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,28 +98,28 @@ unsigned long long operator""_MiB(unsigned long long v) {
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Gigabytes, x1000.000.000
|
//! \~english Gigabytes, x1000.000.000
|
||||||
//! \~russian Гигабайт, x1000.000.000
|
//! \~russian Гигабайт, x1000.000.000
|
||||||
unsigned long long operator""_GB(long double v) {
|
constexpr unsigned long long operator""_GB(long double v) {
|
||||||
return v * 1000. * 1000. * 1000.;
|
return v * 1000. * 1000. * 1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Gigabytes, x1000.000.000
|
//! \~english Gigabytes, x1000.000.000
|
||||||
//! \~russian Гигабайт, x1000.000.000
|
//! \~russian Гигабайт, x1000.000.000
|
||||||
unsigned long long operator""_GB(unsigned long long v) {
|
constexpr unsigned long long operator""_GB(unsigned long long v) {
|
||||||
return v * 1000 * 1000 * 1000;
|
return v * 1000 * 1000 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Gibibytes, x1.073.741.824 (2^30)
|
//! \~english Gibibytes, x1.073.741.824 (2^30)
|
||||||
//! \~russian Гибибайт, x1.073.741.824 (2^30)
|
//! \~russian Гибибайт, x1.073.741.824 (2^30)
|
||||||
unsigned long long operator""_GiB(long double v) {
|
constexpr unsigned long long operator""_GiB(long double v) {
|
||||||
return v * 1024. * 1024. * 1024.;
|
return v * 1024. * 1024. * 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Gibibytes, x1.073.741.824 (2^30)
|
//! \~english Gibibytes, x1.073.741.824 (2^30)
|
||||||
//! \~russian Гибибайт, x1.073.741.824 (2^30)
|
//! \~russian Гибибайт, x1.073.741.824 (2^30)
|
||||||
unsigned long long operator""_GiB(unsigned long long v) {
|
constexpr unsigned long long operator""_GiB(unsigned long long v) {
|
||||||
return v * 1024 * 1024 * 1024;
|
return v * 1024 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,28 +127,28 @@ unsigned long long operator""_GiB(unsigned long long v) {
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Terabytes, x1000.000.000.000
|
//! \~english Terabytes, x1000.000.000.000
|
||||||
//! \~russian Терабайт, x1000.000.000.000
|
//! \~russian Терабайт, x1000.000.000.000
|
||||||
unsigned long long operator""_TB(long double v) {
|
constexpr unsigned long long operator""_TB(long double v) {
|
||||||
return v * 1000. * 1000. * 1000. * 1000.;
|
return v * 1000. * 1000. * 1000. * 1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Terabytes, x1000.000.000.000
|
//! \~english Terabytes, x1000.000.000.000
|
||||||
//! \~russian Терабайт, x1000.000.000.000
|
//! \~russian Терабайт, x1000.000.000.000
|
||||||
unsigned long long operator""_TB(unsigned long long v) {
|
constexpr unsigned long long operator""_TB(unsigned long long v) {
|
||||||
return v * 1000 * 1000 * 1000 * 1000;
|
return v * 1000 * 1000 * 1000 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Tebibytes, x1.099.511.627.776 (2^40)
|
//! \~english Tebibytes, x1.099.511.627.776 (2^40)
|
||||||
//! \~russian Тебибайт, x1.099.511.627.776 (2^40)
|
//! \~russian Тебибайт, x1.099.511.627.776 (2^40)
|
||||||
unsigned long long operator""_TiB(long double v) {
|
constexpr unsigned long long operator""_TiB(long double v) {
|
||||||
return v * 1024. * 1024. * 1024. * 1024.;
|
return v * 1024. * 1024. * 1024. * 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Tebibytes, x1.099.511.627.776 (2^40)
|
//! \~english Tebibytes, x1.099.511.627.776 (2^40)
|
||||||
//! \~russian Тебибайт, x1.099.511.627.776 (2^40)
|
//! \~russian Тебибайт, x1.099.511.627.776 (2^40)
|
||||||
unsigned long long operator""_TiB(unsigned long long v) {
|
constexpr unsigned long long operator""_TiB(unsigned long long v) {
|
||||||
return v * 1024 * 1024 * 1024 * 1024;
|
return v * 1024 * 1024 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,28 +156,28 @@ unsigned long long operator""_TiB(unsigned long long v) {
|
|||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Petabytes, x1000.000.000.000.000
|
//! \~english Petabytes, x1000.000.000.000.000
|
||||||
//! \~russian Петабайт, x1000.000.000.000.000
|
//! \~russian Петабайт, x1000.000.000.000.000
|
||||||
unsigned long long operator""_PB(long double v) {
|
constexpr unsigned long long operator""_PB(long double v) {
|
||||||
return v * 1000. * 1000. * 1000. * 1000. * 1000.;
|
return v * 1000. * 1000. * 1000. * 1000. * 1000.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Petabytes, x1000.000.000.000.000
|
//! \~english Petabytes, x1000.000.000.000.000
|
||||||
//! \~russian Петабайт, x1000.000.000.000.000
|
//! \~russian Петабайт, x1000.000.000.000.000
|
||||||
unsigned long long operator""_PB(unsigned long long v) {
|
constexpr unsigned long long operator""_PB(unsigned long long v) {
|
||||||
return v * 1000 * 1000 * 1000 * 1000 * 1000;
|
return v * 1000 * 1000 * 1000 * 1000 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Pebibytes, x1.125.899.906.842.624 (2^50)
|
//! \~english Pebibytes, x1.125.899.906.842.624 (2^50)
|
||||||
//! \~russian Пебибайт, x1.125.899.906.842.624 (2^50)
|
//! \~russian Пебибайт, x1.125.899.906.842.624 (2^50)
|
||||||
unsigned long long operator""_PiB(long double v) {
|
constexpr unsigned long long operator""_PiB(long double v) {
|
||||||
return v * 1024. * 1024. * 1024. * 1024. * 1024.;
|
return v * 1024. * 1024. * 1024. * 1024. * 1024.;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \~\brief
|
//! \~\brief
|
||||||
//! \~english Pebibytes, x1.125.899.906.842.624 (2^50)
|
//! \~english Pebibytes, x1.125.899.906.842.624 (2^50)
|
||||||
//! \~russian Пебибайт, x1.125.899.906.842.624 (2^50)
|
//! \~russian Пебибайт, x1.125.899.906.842.624 (2^50)
|
||||||
unsigned long long operator""_PiB(unsigned long long v) {
|
constexpr unsigned long long operator""_PiB(unsigned long long v) {
|
||||||
return v * 1024 * 1024 * 1024 * 1024 * 1024;
|
return v * 1024 * 1024 * 1024 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
46
libs/main/literals/piliterals_string.h
Normal file
46
libs/main/literals/piliterals_string.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
/*! \file piliterals_string.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \~\brief
|
||||||
|
* \~english PIString C++11 literals
|
||||||
|
* \~russian C++11 суффиксы PIString
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
PIString C++11 literals
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 PILITERALS_STRING_H
|
||||||
|
#define PILITERALS_STRING_H
|
||||||
|
|
||||||
|
#include "pistring.h"
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIString from ASCII
|
||||||
|
//! \~russian PIString из ASCII
|
||||||
|
inline PIString operator""_a(const char * v, size_t sz) {
|
||||||
|
return PIString::fromAscii(v, sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PIString from UTF-8
|
||||||
|
//! \~russian PIString из UTF-8
|
||||||
|
inline PIString operator""_u8(const char * v, size_t sz) {
|
||||||
|
return PIString::fromUTF8(v, sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
85
libs/main/literals/piliterals_time.h
Normal file
85
libs/main/literals/piliterals_time.h
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*! \file piliterals_time.h
|
||||||
|
* \ingroup Core
|
||||||
|
* \~\brief
|
||||||
|
* \~english PISystemTime C++11 literals
|
||||||
|
* \~russian C++11 суффиксы PISystemTime
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
PISystemTime C++11 literals
|
||||||
|
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
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 PILITERALS_TIME_H
|
||||||
|
#define PILITERALS_TIME_H
|
||||||
|
|
||||||
|
#include "pisystemtime.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from seconds
|
||||||
|
//! \~russian PISystemTime из секунд
|
||||||
|
inline PISystemTime operator""_s(long double v) {
|
||||||
|
return PISystemTime::fromSeconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from seconds
|
||||||
|
//! \~russian PISystemTime из секунд
|
||||||
|
inline PISystemTime operator""_s(unsigned long long v) {
|
||||||
|
return PISystemTime::fromSeconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from milliseconds
|
||||||
|
//! \~russian PISystemTime из милисекунд
|
||||||
|
inline PISystemTime operator""_ms(long double v) {
|
||||||
|
return PISystemTime::fromMilliseconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from milliseconds
|
||||||
|
//! \~russian PISystemTime из милисекунд
|
||||||
|
inline PISystemTime operator""_ms(unsigned long long v) {
|
||||||
|
return PISystemTime::fromMilliseconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from microseconds
|
||||||
|
//! \~russian PISystemTime из микросекунд
|
||||||
|
inline PISystemTime operator""_us(long double v) {
|
||||||
|
return PISystemTime::fromMicroseconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from microseconds
|
||||||
|
//! \~russian PISystemTime из микросекунд
|
||||||
|
inline PISystemTime operator""_us(unsigned long long v) {
|
||||||
|
return PISystemTime::fromMicroseconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english PISystemTime from nanoseconds
|
||||||
|
//! \~russian PISystemTime из наносекунд
|
||||||
|
inline PISystemTime operator""_ns(unsigned long long v) {
|
||||||
|
return PISystemTime::fromNanoseconds(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "pisingleapplication.h"
|
#include "pisingleapplication.h"
|
||||||
|
|
||||||
|
#include "piliterals.h"
|
||||||
#include "pisharedmemory.h"
|
#include "pisharedmemory.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
//!
|
//!
|
||||||
|
|
||||||
|
|
||||||
#define SHM_SIZE 1024 * 32
|
#define SHM_SIZE 32_KiB
|
||||||
|
|
||||||
|
|
||||||
PISingleApplication::PISingleApplication(const PIString & app_name): PIThread() {
|
PISingleApplication::PISingleApplication(const PIString & app_name): PIThread() {
|
||||||
@@ -75,7 +76,7 @@ PISingleApplication::PISingleApplication(const PIString & app_name): PIThread()
|
|||||||
|
|
||||||
PISingleApplication::~PISingleApplication() {
|
PISingleApplication::~PISingleApplication() {
|
||||||
stop();
|
stop();
|
||||||
if (!waitForFinish(5000)) terminate();
|
if (!waitForFinish(5_s)) terminate();
|
||||||
delete shm;
|
delete shm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -693,7 +693,34 @@ int PIThread::priority2System(PIThread::Priority p) {
|
|||||||
bool PIThread::_startThread(void * func) {
|
bool PIThread::_startThread(void * func) {
|
||||||
terminating = false;
|
terminating = false;
|
||||||
running_ = true;
|
running_ = true;
|
||||||
#if !defined(WINDOWS) && !defined(FREERTOS)
|
|
||||||
|
#ifdef FREERTOS
|
||||||
|
|
||||||
|
if (xTaskCreate((__THREAD_FUNC_RET__(*)(void *))func,
|
||||||
|
((PIString &)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii(), // A name just for humans
|
||||||
|
128, // This stack size can be checked & adjusted by reading the Stack Highwater
|
||||||
|
this,
|
||||||
|
priority_,
|
||||||
|
&PRIVATE->thread) == pdPASS) {
|
||||||
|
tid_ = (llong)PRIVATE->thread;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined(WINDOWS)
|
||||||
|
|
||||||
|
if (PRIVATE->thread) CloseHandle(PRIVATE->thread);
|
||||||
|
# ifdef CC_GCC
|
||||||
|
PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__(*)(void *))func, this, 0, 0);
|
||||||
|
# else
|
||||||
|
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
|
||||||
|
# endif
|
||||||
|
if (PRIVATE->thread != 0) {
|
||||||
|
setPriority(priority_);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||||
@@ -707,40 +734,20 @@ bool PIThread::_startThread(void * func) {
|
|||||||
# else
|
# else
|
||||||
pthread_setname_np(PRIVATE->thread, ((PIString &)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii());
|
pthread_setname_np(PRIVATE->thread, ((PIString &)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii());
|
||||||
# endif
|
# endif
|
||||||
#endif
|
|
||||||
#ifdef WINDOWS
|
|
||||||
if (PRIVATE->thread) CloseHandle(PRIVATE->thread);
|
|
||||||
# ifdef CC_GCC
|
|
||||||
PRIVATE->thread = (void *)_beginthreadex(0, 0, (__THREAD_FUNC_RET__(*)(void *))func, this, 0, 0);
|
|
||||||
# else
|
|
||||||
PRIVATE->thread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)func, this, 0, 0);
|
|
||||||
# endif
|
|
||||||
if (PRIVATE->thread != 0) {
|
|
||||||
#endif
|
|
||||||
#ifdef FREERTOS
|
|
||||||
if (xTaskCreate((__THREAD_FUNC_RET__(*)(void *))func,
|
|
||||||
((PIString &)name().elided(15, 0.4f).resize(15, PIChar('\0'))).dataAscii(), // A name just for humans
|
|
||||||
128, // This stack size can be checked & adjusted by reading the Stack Highwater
|
|
||||||
this,
|
|
||||||
priority_,
|
|
||||||
&PRIVATE->thread) == pdPASS) {
|
|
||||||
tid_ = (llong)PRIVATE->thread;
|
|
||||||
#endif
|
|
||||||
#ifndef FREERTOS
|
|
||||||
setPriority(priority_);
|
setPriority(priority_);
|
||||||
#endif
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
running_ = false;
|
running_ = false;
|
||||||
PRIVATE->thread = 0;
|
PRIVATE->thread = 0;
|
||||||
piCoutObj << "Error: Can`t start new thread:" << errorString();
|
piCoutObj << "Error: Can`t start new thread:" << errorString();
|
||||||
}
|
|
||||||
running_ = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::setPriority(PIThread::Priority prior) {
|
void PIThread::setPriority(PIThread::Priority prior) {
|
||||||
priority_ = prior;
|
priority_ = prior;
|
||||||
if (!running_ || (PRIVATE->thread == 0)) return;
|
if (!running_ || (PRIVATE->thread == 0)) return;
|
||||||
#ifdef FREERTOS
|
#ifdef FREERTOS
|
||||||
@@ -764,11 +771,21 @@ bool PIThread::_startThread(void * func) {
|
|||||||
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
|
SetThreadPriority(PRIVATE->thread, priority2System(priority_));
|
||||||
# endif
|
# endif
|
||||||
#endif // FREERTOS
|
#endif // FREERTOS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIThread::waitForStart(PISystemTime timeout) {
|
||||||
|
return waitForStart(timeout.toMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIThread::waitForFinish(PISystemTime timeout) {
|
||||||
|
return waitForFinish(timeout.toMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
bool isExists(HANDLE hThread) {
|
bool isExists(HANDLE hThread) {
|
||||||
// errorClear();
|
// errorClear();
|
||||||
// piCout << "isExists" << hThread;
|
// piCout << "isExists" << hThread;
|
||||||
DWORD dw = 0;
|
DWORD dw = 0;
|
||||||
@@ -777,10 +794,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
if (dw == STILL_ACTIVE) return true;
|
if (dw == STILL_ACTIVE) return true;
|
||||||
// piCout << errorString();
|
// piCout << errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool PIThread::waitForFinish(int timeout_msecs) {
|
bool PIThread::waitForFinish(int timeout_msecs) {
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "PIThread::waitForFinish" << running_ << terminating <<
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "PIThread::waitForFinish" << running_ << terminating <<
|
||||||
// timeout_msecs;
|
// timeout_msecs;
|
||||||
if (!running_) return true;
|
if (!running_) return true;
|
||||||
@@ -807,10 +824,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return tmf_.elapsed_m() < timeout_msecs;
|
return tmf_.elapsed_m() < timeout_msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool PIThread::waitForStart(int timeout_msecs) {
|
bool PIThread::waitForStart(int timeout_msecs) {
|
||||||
if (running_) return true;
|
if (running_) return true;
|
||||||
if (timeout_msecs < 0) {
|
if (timeout_msecs < 0) {
|
||||||
while (!running_)
|
while (!running_)
|
||||||
@@ -821,10 +838,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
while (!running_ && tms_.elapsed_m() < timeout_msecs)
|
while (!running_ && tms_.elapsed_m() < timeout_msecs)
|
||||||
piMinSleep();
|
piMinSleep();
|
||||||
return tms_.elapsed_m() < timeout_msecs;
|
return tms_.elapsed_m() < timeout_msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::_beginThread() {
|
void PIThread::_beginThread() {
|
||||||
#ifndef WINDOWS
|
#ifndef WINDOWS
|
||||||
# if !defined(ANDROID) && !defined(FREERTOS)
|
# if !defined(ANDROID) && !defined(FREERTOS)
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
|
||||||
@@ -844,10 +861,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
begin();
|
begin();
|
||||||
if (lockRun) thread_mutex.unlock();
|
if (lockRun) thread_mutex.unlock();
|
||||||
started();
|
started();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::_runThread() {
|
void PIThread::_runThread() {
|
||||||
PIINTROSPECTION_THREAD_RUN(this);
|
PIINTROSPECTION_THREAD_RUN(this);
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "lock" << "...";
|
||||||
if (lockRun) thread_mutex.lock();
|
if (lockRun) thread_mutex.lock();
|
||||||
@@ -868,10 +885,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "...";
|
||||||
if (lockRun) thread_mutex.unlock();
|
if (lockRun) thread_mutex.unlock();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "unlock" << "ok";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::_endThread() {
|
void PIThread::_endThread() {
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "...";
|
||||||
stopped();
|
stopped();
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "stop" << "ok";
|
||||||
@@ -900,10 +917,10 @@ bool PIThread::_startThread(void * func) {
|
|||||||
PRIVATE->thread = 0;
|
PRIVATE->thread = 0;
|
||||||
pthread_exit(0);
|
pthread_exit(0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::__thread_func__() {
|
void PIThread::__thread_func__() {
|
||||||
_beginThread();
|
_beginThread();
|
||||||
while (!terminating) {
|
while (!terminating) {
|
||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "queued" << "...";
|
||||||
@@ -925,47 +942,47 @@ bool PIThread::_startThread(void * func) {
|
|||||||
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "ok";
|
// PICout(PICoutManipulators::DefaultControls) << "thread" << this << "wait" << "ok";
|
||||||
}
|
}
|
||||||
_endThread();
|
_endThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIThread::__thread_func_once__() {
|
void PIThread::__thread_func_once__() {
|
||||||
_beginThread();
|
_beginThread();
|
||||||
_runThread();
|
_runThread();
|
||||||
_endThread();
|
_endThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This method create %PIThread with name "name" and execute
|
//! This method create %PIThread with name "name" and execute
|
||||||
//! event handler "handler" of object "object" in this thread.\n
|
//! event handler "handler" of object "object" in this thread.\n
|
||||||
//! This %PIThread automatically delete on function finish.
|
//! This %PIThread automatically delete on function finish.
|
||||||
//!
|
//!
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод создает %PIThread с именем "name" и выполняет
|
//! Этот метод создает %PIThread с именем "name" и выполняет
|
||||||
//! обработчик "handler" объекта "object" в этом потоке.\n
|
//! обработчик "handler" объекта "object" в этом потоке.\n
|
||||||
//! %PIThread автоматически удаляется после завершения обработчика.
|
//! %PIThread автоматически удаляется после завершения обработчика.
|
||||||
//!
|
//!
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! class MyObj: public PIObject {
|
//! class MyObj: public PIObject {
|
||||||
//! PIOBJECT(MyObj)
|
//! PIOBJECT(MyObj)
|
||||||
//! public:
|
//! public:
|
||||||
//! EVENT_HANDLER(void, threadRun) {
|
//! EVENT_HANDLER(void, threadRun) {
|
||||||
//! piForTimes (5) {
|
//! piForTimes (5) {
|
||||||
//! piCout << "threadRun";
|
//! piCout << "threadRun";
|
||||||
//! piMSleep(100);
|
//! piMSleep(100);
|
||||||
//! }
|
//! }
|
||||||
//! };
|
//! };
|
||||||
//! };
|
//! };
|
||||||
//!
|
//!
|
||||||
//! int main(int argc, char * argv[]) {
|
//! int main(int argc, char * argv[]) {
|
||||||
//! MyObj mo;
|
//! MyObj mo;
|
||||||
//! PIThread::runOnce(&mo, "threadRun");
|
//! PIThread::runOnce(&mo, "threadRun");
|
||||||
//! piMSleep(1000); // wait for thread finish
|
//! piMSleep(1000); // wait for thread finish
|
||||||
//! return 0;
|
//! return 0;
|
||||||
//! }
|
//! }
|
||||||
//! \endcode
|
//! \endcode
|
||||||
void PIThread::runOnce(PIObject * object, const char * handler, const PIString & name) {
|
void PIThread::runOnce(PIObject * object, const char * handler, const PIString & name) {
|
||||||
PIThread * t = new PIThread();
|
PIThread * t = new PIThread();
|
||||||
t->setName(name);
|
t->setName(name);
|
||||||
if (!PIObject::piConnectU(t, PIStringAscii("started"), object, object, PIStringAscii(handler), "PIThread::runOnce").isValid()) {
|
if (!PIObject::piConnectU(t, PIStringAscii("started"), object, object, PIStringAscii(handler), "PIThread::runOnce").isValid()) {
|
||||||
@@ -977,32 +994,32 @@ bool PIThread::_startThread(void * func) {
|
|||||||
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||||
#endif
|
#endif
|
||||||
t->startOnce();
|
t->startOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! \~\details
|
//! \~\details
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This method create %PIThread with name "name" and execute
|
//! This method create %PIThread with name "name" and execute
|
||||||
//! [lambda expression](https://en.cppreference.com/w/cpp/language/lambda) "func" in this thread.\n
|
//! [lambda expression](https://en.cppreference.com/w/cpp/language/lambda) "func" in this thread.\n
|
||||||
//! This %PIThread automatically delete on function finish.\n
|
//! This %PIThread automatically delete on function finish.\n
|
||||||
//! "func" shouldn`t have arguments.
|
//! "func" shouldn`t have arguments.
|
||||||
//!
|
//!
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот метод создает %PIThread с именем "name" и выполняет
|
//! Этот метод создает %PIThread с именем "name" и выполняет
|
||||||
//! [лямбда-выражение](https://ru.cppreference.com/w/cpp/language/lambda) "func" в этом потоке.\n
|
//! [лямбда-выражение](https://ru.cppreference.com/w/cpp/language/lambda) "func" в этом потоке.\n
|
||||||
//! %PIThread автоматически удаляется после завершения функции.\n
|
//! %PIThread автоматически удаляется после завершения функции.\n
|
||||||
//! "func" не должна иметь аргументов.
|
//! "func" не должна иметь аргументов.
|
||||||
//!
|
//!
|
||||||
//! \~\code
|
//! \~\code
|
||||||
//! PIThread::runOnce([](){
|
//! PIThread::runOnce([](){
|
||||||
//! piForTimes(5) {
|
//! piForTimes(5) {
|
||||||
//! piCout << "thread func";
|
//! piCout << "thread func";
|
||||||
//! piMSleep(100);
|
//! piMSleep(100);
|
||||||
//! }
|
//! }
|
||||||
//! });
|
//! });
|
||||||
//! piMSleep(1000);
|
//! piMSleep(1000);
|
||||||
//! \endcode
|
//! \endcode
|
||||||
void PIThread::runOnce(std::function<void()> func, const PIString & name) {
|
void PIThread::runOnce(std::function<void()> func, const PIString & name) {
|
||||||
PIThread * t = new PIThread();
|
PIThread * t = new PIThread();
|
||||||
t->setName(name);
|
t->setName(name);
|
||||||
t->setSlot(func);
|
t->setSlot(func);
|
||||||
@@ -1011,4 +1028,4 @@ bool PIThread::_startThread(void * func) {
|
|||||||
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
CONNECT0(void, t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||||
#endif
|
#endif
|
||||||
t->startOnce();
|
t->startOnce();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,8 +163,10 @@ public:
|
|||||||
|
|
||||||
EVENT_HANDLER0(bool, waitForStart) { return waitForStart(-1); }
|
EVENT_HANDLER0(bool, waitForStart) { return waitForStart(-1); }
|
||||||
EVENT_HANDLER1(bool, waitForStart, int, timeout_msecs);
|
EVENT_HANDLER1(bool, waitForStart, int, timeout_msecs);
|
||||||
|
bool waitForStart(PISystemTime timeout);
|
||||||
EVENT_HANDLER0(bool, waitForFinish) { return waitForFinish(-1); }
|
EVENT_HANDLER0(bool, waitForFinish) { return waitForFinish(-1); }
|
||||||
EVENT_HANDLER1(bool, waitForFinish, int, timeout_msecs);
|
EVENT_HANDLER1(bool, waitForFinish, int, timeout_msecs);
|
||||||
|
bool waitForFinish(PISystemTime timeout);
|
||||||
|
|
||||||
//! \~english Set necessity of lock every \a run() with internal mutex
|
//! \~english Set necessity of lock every \a run() with internal mutex
|
||||||
//! \~russian Устанавливает необходимость блокировки внутреннего мьютекса каждый \a run()
|
//! \~russian Устанавливает необходимость блокировки внутреннего мьютекса каждый \a run()
|
||||||
|
|||||||
6
main.cpp
6
main.cpp
@@ -26,12 +26,10 @@ REGISTER_VARIANT_CAST(PIString, SomeType) {
|
|||||||
return SomeType{sl[0].toInt(), sl[1].toFloat()};
|
return SomeType{sl[0].toInt(), sl[1].toFloat()};
|
||||||
}
|
}
|
||||||
#include "piliterals.h"
|
#include "piliterals.h"
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
piCout << 2_MB;
|
piCout << 0.5_s;
|
||||||
piCout << 2.1_MB;
|
|
||||||
piCout << 2_MiB;
|
|
||||||
piCout << 2.1_MiB;
|
|
||||||
// clang-format on
|
// clang-format on
|
||||||
return 0;
|
return 0;
|
||||||
/*PIValueTree root;
|
/*PIValueTree root;
|
||||||
|
|||||||
Reference in New Issue
Block a user