diff --git a/client/src/comms.c b/client/src/comms.c index c96ecf369..b2392903a 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -100,7 +100,8 @@ bool WaitForTxIdle(uint32_t ms_timeout) { if (msclock() - start >= ms_timeout) { return false; } - msleep(1); + + xyield(); // just to avoid CPU busy loop } } @@ -1149,8 +1150,8 @@ bool WaitForResponseTimeoutW(uint32_t cmd, PacketResponseNG *response, size_t ms PrintAndLogEx(INFO, "You can cancel this operation by pressing the pm3 button"); show_warning = false; } - // just to avoid CPU busy loop: - msleep(1); + + xyield(); // just to avoid CPU busy loop } return false; } diff --git a/common/util_posix.h b/common/util_posix.h index 8f7ffb091..7d039a0e3 100644 --- a/common/util_posix.h +++ b/common/util_posix.h @@ -24,11 +24,13 @@ #ifdef _WIN32 # include # define sleep(n) Sleep(1000 *(n)) -# define msleep(n) Sleep((n)) +# define msleep(n) Sleep((n)) // Sleep(1) may wait 15ms, which is a feature of Windows. +# define xyield() Sleep(0) // avoid cpu busy, yield to other threads #else -void msleep(uint32_t n); // sleep n milliseconds +void msleep(uint32_t n); // sleep n milliseconds +# define xyield() msleep(1) #endif // _WIN32 -uint64_t msclock(void); // a milliseconds clock -uint64_t usclock(void); // a microseconds clock +uint64_t msclock(void); // a milliseconds clock +uint64_t usclock(void); // a microseconds clock #endif