version 2.33.0
piMinSleep() method
This commit is contained in:
@@ -285,10 +285,10 @@
|
||||
#define FOREVER for (;;)
|
||||
|
||||
//! Macro used for infinite wait
|
||||
#define FOREVER_WAIT FOREVER msleep(PIP_MIN_MSLEEP);
|
||||
#define FOREVER_WAIT FOREVER piMinSleep;
|
||||
|
||||
//! 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
|
||||
|
||||
@@ -749,7 +749,7 @@ void PIObject::Deleter::deleteObject(PIObject * o) {
|
||||
//piCout << "[Deleter] delete" << (uintptr_t)o << "...";
|
||||
if (o->isPIObject()) {
|
||||
//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";
|
||||
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). */
|
||||
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);
|
||||
if (s == -1) {
|
||||
//piCoutObj << "Can`t accept new connection, " << ethErrorString();
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return -1;
|
||||
}
|
||||
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 << "...";
|
||||
if (::connect(sock, (sockaddr * )&PRIVATE->addr_, sizeof(PRIVATE->addr_)) != 0) {
|
||||
//piCoutObj << "Can`t connect to " << ip_s << ":" << port_s << ", " << ethErrorString();
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return -1;
|
||||
}
|
||||
//piCoutObj << "ok, write SingleTCP" << int(data) << max_size << "bytes ...";
|
||||
|
||||
@@ -254,7 +254,7 @@ void PIIODevice::write_func() {
|
||||
int ret = write(item.first);
|
||||
threadedWriteEvent(item.second, ret);
|
||||
}
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ PIByteArray PIIODevice::readForTime(double timeout_ms) {
|
||||
tm.reset();
|
||||
while (tm.elapsed_m() < timeout_ms) {
|
||||
ret = read(td, threaded_read_buffer_size);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else str.append(td, ret);
|
||||
}
|
||||
delete[] td;
|
||||
|
||||
@@ -434,7 +434,7 @@ bool PISerial::read(void * data, int size, double timeout_ms) {
|
||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||
ret = readDevice(&((uchar * )data)[all], size - all);
|
||||
if (ret > 0) all += ret;
|
||||
else piMSleep(PIP_MIN_MSLEEP);
|
||||
else piMinSleep();
|
||||
}
|
||||
setOption(BlockingRead, br);
|
||||
received(data, all);
|
||||
@@ -473,13 +473,13 @@ PIString PISerial::read(int size, double timeout_ms) {
|
||||
if (size <= 0) {
|
||||
while (tm_.elapsed_m() < timeout_ms) {
|
||||
ret = readDevice(td, 1024);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else str << PIString((char*)td, ret);
|
||||
}
|
||||
} else {
|
||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||
ret = readDevice(td, size - all);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else {
|
||||
str << PIString((char*)td, ret);
|
||||
all += ret;
|
||||
@@ -493,7 +493,7 @@ PIString PISerial::read(int size, double timeout_ms) {
|
||||
str << PIString((char*)td, all);
|
||||
while (all < size) {
|
||||
ret = readDevice(td, size - all);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else {
|
||||
str << PIString((char*)td, ret);
|
||||
all += ret;
|
||||
@@ -525,13 +525,13 @@ PIByteArray PISerial::readData(int size, double timeout_ms) {
|
||||
if (size <= 0) {
|
||||
while (tm_.elapsed_m() < timeout_ms) {
|
||||
ret = readDevice(td, 1024);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else str.append(td, ret);
|
||||
}
|
||||
} else {
|
||||
while (all < size && tm_.elapsed_m() < timeout_ms) {
|
||||
ret = readDevice(td, size - all);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else {
|
||||
str.append(td, ret);
|
||||
all += ret;
|
||||
@@ -545,7 +545,7 @@ PIByteArray PISerial::readData(int size, double timeout_ms) {
|
||||
str.append(td, all);
|
||||
while (all < size) {
|
||||
ret = readDevice(td, size - all);
|
||||
if (ret <= 0) piMSleep(PIP_MIN_MSLEEP);
|
||||
if (ret <= 0) piMinSleep();
|
||||
else {
|
||||
str.append(td, ret);
|
||||
all += ret;
|
||||
|
||||
@@ -346,7 +346,7 @@ bool PIBaseTransfer::send_process() {
|
||||
if (chk == 0) return finish_send(true);
|
||||
if (chk != prev_chk) rtm.reset();
|
||||
else if (rtm.elapsed_m() < 100) {
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
continue;
|
||||
}
|
||||
if (is_pause) {
|
||||
@@ -507,7 +507,7 @@ bool PIBaseTransfer::getStartRequest() {
|
||||
return true;
|
||||
}
|
||||
mutex_session.unlock();
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void PIProcess::exec_() {
|
||||
startOnce();
|
||||
//cout << "exec wait" << endl;
|
||||
while (!is_exec)
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
//cout << "exec end" << endl;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ void PIProcess::startProc(bool detached) {
|
||||
if (execve(str.data(), a, e) < 0)
|
||||
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
|
||||
} else {
|
||||
msleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep;
|
||||
//cout << "wait" << endl;
|
||||
if (!detached) {
|
||||
wait(&exit_code);
|
||||
|
||||
@@ -162,7 +162,7 @@ private:
|
||||
return;
|
||||
}
|
||||
if (ret > 0) {
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return;
|
||||
}
|
||||
diag_.received(1);
|
||||
|
||||
@@ -402,7 +402,7 @@ bool PIThread::waitForFinish(int timeout_msecs) {
|
||||
if (!running_) return true;
|
||||
if (timeout_msecs < 0) {
|
||||
while (running_) {
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
#ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
@@ -414,7 +414,7 @@ bool PIThread::waitForFinish(int timeout_msecs) {
|
||||
}
|
||||
tmf_.reset();
|
||||
while (running_ && tmf_.elapsed_m() < timeout_msecs) {
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
#ifdef WINDOWS
|
||||
if (!isExists(PRIVATE->thread)) {
|
||||
unlock();
|
||||
@@ -430,12 +430,12 @@ bool PIThread::waitForStart(int timeout_msecs) {
|
||||
if (running_) return true;
|
||||
if (timeout_msecs < 0) {
|
||||
while (!running_)
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return true;
|
||||
}
|
||||
tms_.reset();
|
||||
while (!running_ && tms_.elapsed_m() < timeout_msecs)
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return tms_.elapsed_m() < timeout_msecs;
|
||||
}
|
||||
|
||||
|
||||
@@ -648,11 +648,11 @@ bool PITimer::stop(bool wait) {
|
||||
bool PITimer::waitForFinish(int timeout_msecs) {
|
||||
if (timeout_msecs < 0) {
|
||||
while (isRunning())
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return true;
|
||||
}
|
||||
PITimeMeasurer tm;
|
||||
while (isRunning() && tm.elapsed_m() < timeout_msecs)
|
||||
piMSleep(PIP_MIN_MSLEEP);
|
||||
piMinSleep();
|
||||
return tm.elapsed_m() < timeout_msecs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user