diff --git a/main.cpp b/main.cpp index 5c17c2b1..a65c7eb6 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,7 @@ int main() { CONNECTU(&b, eventB1, &a, handlerA1) CONNECTU(&b, eventB2, &a, handlerA2) a.dump(); + WAIT_FOREVER b.dump(); b.eventB1(0.33); b.eventB2("str"); diff --git a/src_main/console/pikbdlistener.h b/src_main/console/pikbdlistener.h index 099c8ce3..b896ea06 100644 --- a/src_main/console/pikbdlistener.h +++ b/src_main/console/pikbdlistener.h @@ -25,7 +25,7 @@ #include "pithread.h" -#define WAIT_FOR_EXIT while (!PIKbdListener::exiting) piMSleep(5); +#define WAIT_FOR_EXIT while (!PIKbdListener::exiting) piMSleep(PIP_MIN_MSLEEP*5); class PIP_EXPORT PIKbdListener: public PIThread diff --git a/src_main/core/pibase.h b/src_main/core/pibase.h index b4e1c8db..f5f2589a 100644 --- a/src_main/core/pibase.h +++ b/src_main/core/pibase.h @@ -217,14 +217,21 @@ #define PRIVATEWB __privateinitializer__.p +#ifdef FREERTOS +# define PIP_MIN_MSLEEP 10. +#else +# define PIP_MIN_MSLEEP 1. +#endif + + //! Macro used for infinite loop #define FOREVER for (;;) //! Macro used for infinite wait -#define FOREVER_WAIT FOREVER msleep(1); +#define FOREVER_WAIT FOREVER msleep(PIP_MIN_MSLEEP); //! Macro used for infinite wait -#define WAIT_FOREVER FOREVER msleep(1); +#define WAIT_FOREVER FOREVER msleep(PIP_MIN_MSLEEP); //! global variable enabling output to piCout, default is true diff --git a/src_main/io_devices/piethernet.cpp b/src_main/io_devices/piethernet.cpp index 588941c8..2b7fef22 100755 --- a/src_main/io_devices/piethernet.cpp +++ b/src_main/io_devices/piethernet.cpp @@ -677,7 +677,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(); - msleep(1); + msleep(PIP_MIN_MSLEEP); return -1; } rs = ethRecv(s, read_to, max_size); @@ -787,7 +787,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(); - msleep(1); + msleep(PIP_MIN_MSLEEP); return -1; } //piCoutObj << "ok, write SingleTCP" << int(data) << max_size << "bytes ..."; diff --git a/src_main/io_devices/piiodevice.cpp b/src_main/io_devices/piiodevice.cpp index 73a2a1ed..822737ca 100755 --- a/src_main/io_devices/piiodevice.cpp +++ b/src_main/io_devices/piiodevice.cpp @@ -199,7 +199,7 @@ void PIIODevice::write_func() { int ret = write(item.first); threadedWriteEvent(item.second, ret); } - msleep(1); + msleep(PIP_MIN_MSLEEP); } } @@ -279,7 +279,7 @@ PIByteArray PIIODevice::readForTime(double timeout_ms) { tm.reset(); while (tm.elapsed_m() < timeout_ms) { ret = read(td, threadedReadBufferSize()); - if (ret <= 0) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else str.append(td, ret); } delete[] td; diff --git a/src_main/io_devices/piiodevice.h b/src_main/io_devices/piiodevice.h index c1babc5d..2ced538c 100755 --- a/src_main/io_devices/piiodevice.h +++ b/src_main/io_devices/piiodevice.h @@ -197,7 +197,7 @@ public: void start() {startThreadedRead(); startThreadedWrite();} //! Stop both threaded read and threaded write and if "wait" block until both threads are stop - void stop(bool wait = false) {stopThreadedRead(); stopThreadedWrite(); if (wait) while (write_thread.isRunning() || isRunning()) msleep(1);} + void stop(bool wait = false) {stopThreadedRead(); stopThreadedWrite(); if (wait) while (write_thread.isRunning() || isRunning()) msleep(PIP_MIN_MSLEEP);} //! Read from device maximum "max_size" bytes to "read_to" diff --git a/src_main/io_devices/piserial.cpp b/src_main/io_devices/piserial.cpp index 1df82321..c298d695 100755 --- a/src_main/io_devices/piserial.cpp +++ b/src_main/io_devices/piserial.cpp @@ -372,7 +372,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 msleep(1); + else msleep(PIP_MIN_MSLEEP); } setOption(BlockingRead, br); received(data, all); @@ -411,13 +411,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) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else str << PIString((char*)td, ret); } } else { while (all < size && tm_.elapsed_m() < timeout_ms) { ret = readDevice(td, size - all); - if (ret <= 0) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else { str << PIString((char*)td, ret); all += ret; @@ -431,7 +431,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) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else { str << PIString((char*)td, ret); all += ret; @@ -463,13 +463,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) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else str.append(td, ret); } } else { while (all < size && tm_.elapsed_m() < timeout_ms) { ret = readDevice(td, size - all); - if (ret <= 0) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else { str.append(td, ret); all += ret; @@ -483,7 +483,7 @@ PIByteArray PISerial::readData(int size, double timeout_ms) { str.append(td, all); while (all < size) { ret = readDevice(td, size - all); - if (ret <= 0) msleep(1); + if (ret <= 0) msleep(PIP_MIN_MSLEEP); else { str.append(td, ret); all += ret; diff --git a/src_main/io_utils/pibasetransfer.cpp b/src_main/io_utils/pibasetransfer.cpp index 8371171b..8d4291e3 100644 --- a/src_main/io_utils/pibasetransfer.cpp +++ b/src_main/io_utils/pibasetransfer.cpp @@ -281,7 +281,7 @@ bool PIBaseTransfer::send_process() { mutex_send.unlock(); if (sq >= packets_count || is_pause) { --i; - //piMSleep(1); + //piMSleep(PIP_MIN_MSLEEP); if (is_pause) { piMSleep(40); //piCout << "send pause"; @@ -331,7 +331,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(1); + piMSleep(PIP_MIN_MSLEEP); continue; } if (is_pause) { @@ -366,7 +366,7 @@ bool PIBaseTransfer::send_process() { } // if (chk == -1) return finish_send(false); if (break_) return finish_send(false); - //piMSleep(1); + //piMSleep(PIP_MIN_MSLEEP); } return finish_send(false); } @@ -496,7 +496,7 @@ bool PIBaseTransfer::getStartRequest() { return true; } mutex_session.unlock(); - piMSleep(1); + piMSleep(PIP_MIN_MSLEEP); } return false; } diff --git a/src_main/system/piprocess.cpp b/src_main/system/piprocess.cpp index 2231dff5..ba15b06f 100755 --- a/src_main/system/piprocess.cpp +++ b/src_main/system/piprocess.cpp @@ -66,7 +66,7 @@ void PIProcess::exec_() { startOnce(); //cout << "exec wait" << endl; while (!is_exec) - msleep(1); + msleep(PIP_MIN_MSLEEP); //cout << "exec end" << endl; } @@ -186,7 +186,7 @@ void PIProcess::startProc(bool detached) { if (execve(str.data(), a, e) < 0) piCoutObj << "\"execve" << str << args << "\" error :" << errorString(); } else { - msleep(1); + msleep(PIP_MIN_MSLEEP); //cout << "wait" << endl; if (!detached) { wait(&exit_code); diff --git a/src_main/thread/pigrabberbase.h b/src_main/thread/pigrabberbase.h index 506f4dd2..ac407340 100644 --- a/src_main/thread/pigrabberbase.h +++ b/src_main/thread/pigrabberbase.h @@ -162,7 +162,7 @@ private: return; } if (ret > 0) { - piMSleep(1); + piMSleep(PIP_MIN_MSLEEP); return; } diag_.received(1); diff --git a/src_main/thread/pithread.cpp b/src_main/thread/pithread.cpp index 679b4916..9eaac31d 100755 --- a/src_main/thread/pithread.cpp +++ b/src_main/thread/pithread.cpp @@ -364,12 +364,12 @@ bool PIThread::waitForFinish(int timeout_msecs) { if (!running_) return true; if (timeout_msecs < 0) { while (running_) - msleep(1); + msleep(PIP_MIN_MSLEEP); return true; } tmf_.reset(); while (running_ && tmf_.elapsed_m() < timeout_msecs) - msleep(1); + msleep(PIP_MIN_MSLEEP); return tmf_.elapsed_m() < timeout_msecs; } @@ -378,12 +378,12 @@ bool PIThread::waitForStart(int timeout_msecs) { if (running_) return true; if (timeout_msecs < 0) { while (!running_) - msleep(1); + msleep(PIP_MIN_MSLEEP); return true; } tms_.reset(); while (!running_ && tms_.elapsed_m() < timeout_msecs) - msleep(1); + msleep(PIP_MIN_MSLEEP); return tms_.elapsed_m() < timeout_msecs; } @@ -424,10 +424,10 @@ void PIThread::__thread_func__(void * t) { ct.tmr_.reset(); double sl(0.); while (1) { - sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), PTHREAD_MIN_MSLEEP); + sl = piMind(ct.delay_ - ct.tmr_.elapsed_m(), PIP_MIN_MSLEEP); #ifdef WINDOWS /*if (sl <= 1. && sl >= 0.) { - piMSleep(1.); + piMSleep(PIP_MIN_MSLEEP); continue; }*/ #endif diff --git a/src_main/thread/pithread.h b/src_main/thread/pithread.h index a6b9ac8e..46ce2e08 100755 --- a/src_main/thread/pithread.h +++ b/src_main/thread/pithread.h @@ -29,12 +29,6 @@ #include "pimutex.h" #include "piobject.h" -#ifdef FREERTOS -# define PTHREAD_MIN_MSLEEP 10. -#else -# define PTHREAD_MIN_MSLEEP 1. -#endif - class PIThread; class PIP_EXPORT __PIThreadCollection { diff --git a/src_main/thread/pitimer.cpp b/src_main/thread/pitimer.cpp index c87eca36..34a019a1 100755 --- a/src_main/thread/pitimer.cpp +++ b/src_main/thread/pitimer.cpp @@ -371,7 +371,7 @@ _PITimerImp_Pool::Pool::Pool(): PIThread() { #ifndef FREERTOS timers.reserve(64); #endif - start(PTHREAD_MIN_MSLEEP); + start(PIP_MIN_MSLEEP); } @@ -538,11 +538,11 @@ void PITimer::tickImp() { bool PITimer::waitForFinish(int timeout_msecs) { if (timeout_msecs < 0) { while (isRunning()) - msleep(1); + msleep(PIP_MIN_MSLEEP); return true; } PITimeMeasurer tm; while (isRunning() && tm.elapsed_m() < timeout_msecs) - msleep(1); + msleep(PIP_MIN_MSLEEP); return tm.elapsed_m() < timeout_msecs; } diff --git a/utils/system_daemon/daemon.cpp b/utils/system_daemon/daemon.cpp index 1e1df9a5..8b71a06b 100644 --- a/utils/system_daemon/daemon.cpp +++ b/utils/system_daemon/daemon.cpp @@ -618,7 +618,7 @@ PIString Daemon::connectedDaemon() const { void Daemon::peerConnected(const PIString & p_name) { - while (!inited__) piMSleep(5); + while (!inited__) piMSleep(PIP_MIN_MSLEEP*5); // PIMutexLocker ml(peers_mutex); /*piCout << "connected" << name; mode = 2; @@ -638,7 +638,7 @@ void Daemon::peerConnected(const PIString & p_name) { void Daemon::peerDisconnected(const PIString & p_name) { - while (!inited__) piMSleep(5); + while (!inited__) piMSleep(PIP_MIN_MSLEEP*5); piCoutObj << "peer disconnect" << p_name; if (p_name == conn_name) { disconnect();