Skip to content

Commit 978b282

Browse files
fix: remove unecessary if, return if cancelled in cancel_timeout
1 parent 0d627b4 commit 978b282

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

Inc/HALAL/Services/Time/Scheduler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ struct Scheduler {
5151
if(microseconds == 0) [[unlikely]] microseconds = 1;
5252
return register_task(microseconds, func, false);
5353
}
54-
static inline void cancel_timeout(uint8_t id) {
54+
static inline bool cancel_timeout(uint8_t id) {
5555
/* NOTE: This does not fix this case:
5656
1. id = set_timeout(x, func)
5757
2. timeout ends, func gets called and removed internally
5858
3. id_2 = set_timeout(y, func_2) // id will be equal to id_2
5959
4. clear_timeout(id) -> will remove the second timeout
6060
*/
61-
if(tasks_[id].repeating) return;
62-
unregister_task(id);
61+
if(tasks_[id].repeating) return false;
62+
return unregister_task(id);
6363
}
6464

6565
// static void global_timer_callback();

Src/HALAL/Services/Time/Scheduler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ inline uint8_t Scheduler::allocate_slot() {
173173
}
174174

175175
inline void Scheduler::release_slot(uint8_t id) {
176-
// NOTE: This condition shouldn't be here since it's an internal function but it could be an assert
177-
if(id >= kMaxTasks) [[unlikely]] return;
178176
ready_bitmap_ &= ~(1u << id);
179177
free_bitmap_ |= (1u << id);
180178
}

0 commit comments

Comments
 (0)