void alarmRemove(Alarm_t *alarm) { Handle_t h; ATOMIC_START(h); SLIST_REMOVE_SAFE(&alarmListHead, alarm, Alarm_s, chain); ATOMIC_END(h); }
void alarmSchedule(Alarm_t *alarm, uint32_t milliseconds) { // we want to avoid inserting local variables in the global alarm list // (but this warning, not an error, because the user function may never return) WARN_ON(isStackAddress(alarm)); // PRINTF("alarmSchedule %p, ms=%lu\n", alarm, milliseconds); alarm->jiffies = (uint32_t)getJiffies() + milliseconds; // locking is required, because both kernel and user threads can be using this function Handle_t h; ATOMIC_START(h); // unschedule the alarm, if it was already scheduled SLIST_REMOVE_SAFE(&alarmListHead, alarm, Alarm_s, chain); // insert it in appropriate position Alarm_t **prev = &SLIST_FIRST(&alarmListHead); Alarm_t *a = *prev; while (a && timeAfter32(alarm->jiffies, a->jiffies)) { prev = &SLIST_NEXT(a, chain); a = *prev; } SLIST_INSERT(prev, alarm, chain); #if USE_THREADS // always reschedule alarm processing in case some alarm was added // that might need to be processed before end of current kernel sleep time processFlags.bits.alarmsProcess = true; // and make sure the kernel thread is awake and ready to deal with it threadWakeup(KERNEL_THREAD_INDEX, THREAD_READY); #endif ATOMIC_END(h); }