Skip to content

Commit bc2e3b4

Browse files
committed
Allow OnLoop() to return the maximum blocking time
1 parent bd70f29 commit bc2e3b4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libxbot-service/include/xbot-service/Service.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ class Service : public ServiceIo {
139139
void heartbeat();
140140

141141
void runProcessing();
142-
virtual void OnLoop(uint32_t now_micros, uint32_t last_tick_micros) {
142+
virtual uint32_t OnLoop(uint32_t now_micros, uint32_t last_tick_micros) {
143143
(void)now_micros;
144144
(void)last_tick_micros;
145+
return UINT32_MAX;
145146
};
146147

147148
void HandleClaimMessage(datatypes::XbotHeader *header, const void *payload, size_t payload_len);

libxbot-service/src/Service.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ void xbot::service::Service::runProcessing() {
217217

218218
// Run schedules.
219219
uint32_t now_micros = system::getTimeMicros();
220-
OnLoop(now_micros, last_tick_micros);
221-
uint32_t block_time = scheduler_.Tick(now_micros - last_tick_micros);
220+
uint32_t on_loop_block_time = OnLoop(now_micros, last_tick_micros);
221+
uint32_t scheduler_block_time = scheduler_.Tick(now_micros - last_tick_micros);
222+
uint32_t block_time = on_loop_block_time < scheduler_block_time ? on_loop_block_time : scheduler_block_time;
222223
if (block_time > 1'000'000) {
223224
block_time = 1'000'000;
224225
}

0 commit comments

Comments
 (0)