version 2.33.0
piMinSleep() method
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||||
project(pip)
|
project(pip)
|
||||||
set(pip_MAJOR 2)
|
set(pip_MAJOR 2)
|
||||||
set(pip_MINOR 32)
|
set(pip_MINOR 33)
|
||||||
set(pip_REVISION 0)
|
set(pip_REVISION 0)
|
||||||
set(pip_SUFFIX )
|
set(pip_SUFFIX )
|
||||||
set(pip_COMPANY SHS)
|
set(pip_COMPANY SHS)
|
||||||
|
|||||||
@@ -285,10 +285,10 @@
|
|||||||
#define FOREVER for (;;)
|
#define FOREVER for (;;)
|
||||||
|
|
||||||
//! Macro used for infinite wait
|
//! Macro used for infinite wait
|
||||||
#define FOREVER_WAIT FOREVER msleep(PIP_MIN_MSLEEP);
|
#define FOREVER_WAIT FOREVER piMinSleep;
|
||||||
|
|
||||||
//! Macro used for infinite wait
|
//! Macro used for infinite wait
|
||||||
#define WAIT_FOREVER FOREVER msleep(PIP_MIN_MSLEEP);
|
#define WAIT_FOREVER FOREVER piMinSleep;
|
||||||
|
|
||||||
|
|
||||||
//! global variable enabling output to piCout, default is true
|
//! global variable enabling output to piCout, default is true
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ void PIObject::Deleter::deleteObject(PIObject * o) {
|
|||||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "...";
|
//piCout << "[Deleter] delete" << (uintptr_t)o << "...";
|
||||||
if (o->isPIObject()) {
|
if (o->isPIObject()) {
|
||||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
|
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic ...";
|
||||||
while (o->isInEvent()) piMSleep(PIP_MIN_MSLEEP);
|
while (o->isInEvent()) piMinSleep();
|
||||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
|
//piCout << "[Deleter] delete" << (uintptr_t)o << "wait atomic done";
|
||||||
delete o;
|
delete o;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ inline void piMSleep(double msecs) {piUSleep(int(msecs * 1000.));} // on !Window
|
|||||||
* \details This function exec \a piUSleep (msecs * 1000000). */
|
* \details This function exec \a piUSleep (msecs * 1000000). */
|
||||||
inline void piSleep(double secs) {piUSleep(int(secs * 1000000.));} // on !Windows consider constant "usleep" offset
|
inline void piSleep(double secs) {piUSleep(int(secs * 1000000.));} // on !Windows consider constant "usleep" offset
|
||||||
|
|
||||||
|
//! Shortest available on current system sleep
|
||||||
|
inline void piMinSleep() {piMSleep(PIP_MIN_MSLEEP);}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ int PIEthernet::readDevice(void * read_to, int max_size) {
|
|||||||
s = accept(sock, (sockaddr * )&client_addr, &slen);
|
s = accept(sock, (sockaddr * )&client_addr, &slen);
|
||||||
if (s == -1) {
|
if (s == -1) {
|
||||||
//piCoutObj << "Can`t accept new connection, " << ethErrorString();
|
//piCoutObj << "Can`t accept new connection, " << ethErrorString();
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
rs = ethRecv(s, read_to, max_size);
|
rs = ethRecv(s, read_to, max_size);
|
||||||
@@ -788,7 +788,7 @@ int PIEthernet::writeDevice(const void * data, int max_size) {
|
|||||||
//piCoutObj << "connect SingleTCP" << ip_s << ":" << port_s << "...";
|
//piCoutObj << "connect SingleTCP" << ip_s << ":" << port_s << "...";
|
||||||
if (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) != 0) {
|
if (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) != 0) {
|
||||||
//piCoutObj << "Can`t connect to " << ip_s << ":" << port_s << ", " << ethErrorString();
|
//piCoutObj << "Can`t connect to " << ip_s << ":" << port_s << ", " << ethErrorString();
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
//piCoutObj << "ok, write SingleTCP" << int(data) << max_size << "bytes ...";
|
//piCoutObj << "ok, write SingleTCP" << int(data) << max_size << "bytes ...";
|
||||||
|
|||||||
@@ -254,7 +254,7 @@ void PIIODevice::write_func() {
|
|||||||
int ret = write(item.first);
|
int ret = write(item.first);
|
||||||
threadedWriteEvent(item.second, ret);
|
threadedWriteEvent(item.second, ret);
|
||||||
}
|
}
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ PIByteArray PIIODevice::readForTime(double timeout_ms) {
|
|||||||
tm.reset();
|
tm.reset();
|
||||||
while (tm.elapsed_m() < timeout_ms) {
|
while (tm.elapsed_m() < timeout_ms) {
|
||||||
ret = read(td, threaded_read_buffer_size);
|
ret = read(td, threaded_read_buffer_size);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else str.append(td, ret);
|
else str.append(td, ret);
|
||||||
}
|
}
|
||||||
delete[] td;
|
delete[] td;
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ bool PISerial::read(void * data, int size, double timeout_ms) {
|
|||||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||||
ret = readDevice(&((uchar * )data)[all], size - all);
|
ret = readDevice(&((uchar * )data)[all], size - all);
|
||||||
if (ret > 0) all += ret;
|
if (ret > 0) all += ret;
|
||||||
else piMSleep(PIP_MIN_MSLEEP);
|
else piMinSleep();
|
||||||
}
|
}
|
||||||
setOption(BlockingRead, br);
|
setOption(BlockingRead, br);
|
||||||
received(data, all);
|
received(data, all);
|
||||||
@@ -473,13 +473,13 @@ PIString PISerial::read(int size, double timeout_ms) {
|
|||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
while (tm_.elapsed_m() < timeout_ms) {
|
while (tm_.elapsed_m() < timeout_ms) {
|
||||||
ret = readDevice(td, 1024);
|
ret = readDevice(td, 1024);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else str << PIString((char*)td, ret);
|
else str << PIString((char*)td, ret);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||||
ret = readDevice(td, size - all);
|
ret = readDevice(td, size - all);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else {
|
else {
|
||||||
str << PIString((char*)td, ret);
|
str << PIString((char*)td, ret);
|
||||||
all += ret;
|
all += ret;
|
||||||
@@ -493,7 +493,7 @@ PIString PISerial::read(int size, double timeout_ms) {
|
|||||||
str << PIString((char*)td, all);
|
str << PIString((char*)td, all);
|
||||||
while (all < size) {
|
while (all < size) {
|
||||||
ret = readDevice(td, size - all);
|
ret = readDevice(td, size - all);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else {
|
else {
|
||||||
str << PIString((char*)td, ret);
|
str << PIString((char*)td, ret);
|
||||||
all += ret;
|
all += ret;
|
||||||
@@ -525,13 +525,13 @@ PIByteArray PISerial::readData(int size, double timeout_ms) {
|
|||||||
if (size <= 0) {
|
if (size <= 0) {
|
||||||
while (tm_.elapsed_m() < timeout_ms) {
|
while (tm_.elapsed_m() < timeout_ms) {
|
||||||
ret = readDevice(td, 1024);
|
ret = readDevice(td, 1024);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else str.append(td, ret);
|
else str.append(td, ret);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||||
ret = readDevice(td, size - all);
|
ret = readDevice(td, size - all);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else {
|
else {
|
||||||
str.append(td, ret);
|
str.append(td, ret);
|
||||||
all += ret;
|
all += ret;
|
||||||
@@ -545,7 +545,7 @@ PIByteArray PISerial::readData(int size, double timeout_ms) {
|
|||||||
str.append(td, all);
|
str.append(td, all);
|
||||||
while (all < size) {
|
while (all < size) {
|
||||||
ret = readDevice(td, size - all);
|
ret = readDevice(td, size - all);
|
||||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
if (ret <= 0) piMinSleep();
|
||||||
else {
|
else {
|
||||||
str.append(td, ret);
|
str.append(td, ret);
|
||||||
all += ret;
|
all += ret;
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ bool PIBaseTransfer::send_process() {
|
|||||||
if (chk == 0) return finish_send(true);
|
if (chk == 0) return finish_send(true);
|
||||||
if (chk != prev_chk) rtm.reset();
|
if (chk != prev_chk) rtm.reset();
|
||||||
else if (rtm.elapsed_m() < 100) {
|
else if (rtm.elapsed_m() < 100) {
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_pause) {
|
if (is_pause) {
|
||||||
@@ -507,7 +507,7 @@ bool PIBaseTransfer::getStartRequest() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mutex_session.unlock();
|
mutex_session.unlock();
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ void PIProcess::exec_() {
|
|||||||
startOnce();
|
startOnce();
|
||||||
//cout << "exec wait" << endl;
|
//cout << "exec wait" << endl;
|
||||||
while (!is_exec)
|
while (!is_exec)
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
//cout << "exec end" << endl;
|
//cout << "exec end" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ void PIProcess::startProc(bool detached) {
|
|||||||
if (execve(str.data(), a, e) < 0)
|
if (execve(str.data(), a, e) < 0)
|
||||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||||
} else {
|
} else {
|
||||||
msleep(PIP_MIN_MSLEEP);
|
piMinSleep;
|
||||||
//cout << "wait" << endl;
|
//cout << "wait" << endl;
|
||||||
if (!detached) {
|
if (!detached) {
|
||||||
wait(&exit_code);
|
wait(&exit_code);
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
diag_.received(1);
|
diag_.received(1);
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ bool PIThread::waitForFinish(int timeout_msecs) {
|
|||||||
if (!running_) return true;
|
if (!running_) return true;
|
||||||
if (timeout_msecs < 0) {
|
if (timeout_msecs < 0) {
|
||||||
while (running_) {
|
while (running_) {
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (!isExists(PRIVATE->thread)) {
|
if (!isExists(PRIVATE->thread)) {
|
||||||
unlock();
|
unlock();
|
||||||
@@ -414,7 +414,7 @@ bool PIThread::waitForFinish(int timeout_msecs) {
|
|||||||
}
|
}
|
||||||
tmf_.reset();
|
tmf_.reset();
|
||||||
while (running_ && tmf_.elapsed_m() < timeout_msecs) {
|
while (running_ && tmf_.elapsed_m() < timeout_msecs) {
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (!isExists(PRIVATE->thread)) {
|
if (!isExists(PRIVATE->thread)) {
|
||||||
unlock();
|
unlock();
|
||||||
@@ -430,12 +430,12 @@ 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_)
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
tms_.reset();
|
tms_.reset();
|
||||||
while (!running_ && tms_.elapsed_m() < timeout_msecs)
|
while (!running_ && tms_.elapsed_m() < timeout_msecs)
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return tms_.elapsed_m() < timeout_msecs;
|
return tms_.elapsed_m() < timeout_msecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -648,11 +648,11 @@ bool PITimer::stop(bool wait) {
|
|||||||
bool PITimer::waitForFinish(int timeout_msecs) {
|
bool PITimer::waitForFinish(int timeout_msecs) {
|
||||||
if (timeout_msecs < 0) {
|
if (timeout_msecs < 0) {
|
||||||
while (isRunning())
|
while (isRunning())
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PITimeMeasurer tm;
|
PITimeMeasurer tm;
|
||||||
while (isRunning() && tm.elapsed_m() < timeout_msecs)
|
while (isRunning() && tm.elapsed_m() < timeout_msecs)
|
||||||
piMSleep(PIP_MIN_MSLEEP);
|
piMinSleep();
|
||||||
return tm.elapsed_m() < timeout_msecs;
|
return tm.elapsed_m() < timeout_msecs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user