Skip to content

Commit 95156ce

Browse files
author
Cruz Monrreal
authored
Merge pull request #6698 from kjbracey-arm/poll-ticks
Make poll() use RTOS tick count
2 parents 4875769 + 39fa676 commit 95156ce

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

platform/mbed_poll.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
*/
1616
#include "mbed_poll.h"
1717
#include "FileHandle.h"
18+
#if MBED_CONF_RTOS_PRESENT
19+
#include "rtos/Kernel.h"
20+
#include "rtos/Thread.h"
21+
using namespace rtos;
22+
#else
1823
#include "Timer.h"
1924
#include "LowPowerTimer.h"
20-
#ifdef MBED_CONF_RTOS_PRESENT
21-
#include "rtos/Thread.h"
2225
#endif
2326

2427
namespace mbed {
@@ -35,6 +38,13 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
3538
* interested in. In future, his spinning behaviour will be replaced with
3639
* condition variables.
3740
*/
41+
#if MBED_CONF_RTOS_PRESENT
42+
uint64_t start_time = 0;
43+
if (timeout > 0) {
44+
start_time = Kernel::get_ms_count();
45+
}
46+
#define TIME_ELAPSED() int64_t(Kernel::get_ms_count() - start_time)
47+
#else
3848
#if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER
3949
LowPowerTimer timer;
4050
#else
@@ -43,6 +53,8 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
4353
if (timeout > 0) {
4454
timer.start();
4555
}
56+
#define TIME_ELAPSED() timer.read_ms()
57+
#endif // MBED_CONF_RTOS_PRESENT
4658

4759
int count = 0;
4860
for (;;) {
@@ -65,7 +77,7 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
6577
}
6678

6779
/* Nothing selected - this is where timeout handling would be needed */
68-
if (timeout == 0 || (timeout > 0 && timer.read_ms() > timeout)) {
80+
if (timeout == 0 || (timeout > 0 && TIME_ELAPSED() > timeout)) {
6981
break;
7082
}
7183
#ifdef MBED_CONF_RTOS_PRESENT

0 commit comments

Comments
 (0)