Make poll() use RTOS tick count

RTOS maintains a tick count - use it, avoiding issues with sleep and low
power timers.
pull/6698/head
Kevin Bracey 2018-04-20 17:50:52 +03:00
parent 42d77ecd13
commit 39fa676993
1 changed files with 15 additions and 3 deletions

View File

@ -15,10 +15,13 @@
*/ */
#include "mbed_poll.h" #include "mbed_poll.h"
#include "FileHandle.h" #include "FileHandle.h"
#if MBED_CONF_RTOS_PRESENT
#include "rtos/Kernel.h"
#include "rtos/Thread.h"
using namespace rtos;
#else
#include "Timer.h" #include "Timer.h"
#include "LowPowerTimer.h" #include "LowPowerTimer.h"
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/Thread.h"
#endif #endif
namespace mbed { namespace mbed {
@ -35,6 +38,13 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
* interested in. In future, his spinning behaviour will be replaced with * interested in. In future, his spinning behaviour will be replaced with
* condition variables. * condition variables.
*/ */
#if MBED_CONF_RTOS_PRESENT
uint64_t start_time = 0;
if (timeout > 0) {
start_time = Kernel::get_ms_count();
}
#define TIME_ELAPSED() int64_t(Kernel::get_ms_count() - start_time)
#else
#if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER #if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER
LowPowerTimer timer; LowPowerTimer timer;
#else #else
@ -43,6 +53,8 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
if (timeout > 0) { if (timeout > 0) {
timer.start(); timer.start();
} }
#define TIME_ELAPSED() timer.read_ms()
#endif // MBED_CONF_RTOS_PRESENT
int count = 0; int count = 0;
for (;;) { for (;;) {
@ -65,7 +77,7 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
} }
/* Nothing selected - this is where timeout handling would be needed */ /* Nothing selected - this is where timeout handling would be needed */
if (timeout == 0 || (timeout > 0 && timer.read_ms() > timeout)) { if (timeout == 0 || (timeout > 0 && TIME_ELAPSED() > timeout)) {
break; break;
} }
#ifdef MBED_CONF_RTOS_PRESENT #ifdef MBED_CONF_RTOS_PRESENT