15
15
*/
16
16
#include " mbed_poll.h"
17
17
#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
18
23
#include " Timer.h"
19
24
#include " LowPowerTimer.h"
20
- #ifdef MBED_CONF_RTOS_PRESENT
21
- #include " rtos/Thread.h"
22
25
#endif
23
26
24
27
namespace mbed {
@@ -35,6 +38,13 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
35
38
* interested in. In future, his spinning behaviour will be replaced with
36
39
* condition variables.
37
40
*/
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
38
48
#if MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER
39
49
LowPowerTimer timer;
40
50
#else
@@ -43,6 +53,8 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
43
53
if (timeout > 0 ) {
44
54
timer.start ();
45
55
}
56
+ #define TIME_ELAPSED () timer.read_ms()
57
+ #endif // MBED_CONF_RTOS_PRESENT
46
58
47
59
int count = 0 ;
48
60
for (;;) {
@@ -65,7 +77,7 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
65
77
}
66
78
67
79
/* 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)) {
69
81
break ;
70
82
}
71
83
#ifdef MBED_CONF_RTOS_PRESENT
0 commit comments