Skip to content

Commit fa4a97e

Browse files
committed
Core: Let interrupted timing properly exit early
1 parent c7114d8 commit fa4a97e

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/core/timing.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ void mTimingSchedule(struct mTiming* timing, struct mTimingEvent* event, int32_t
3939
if (nextEvent < *timing->nextEvent) {
4040
*timing->nextEvent = nextEvent;
4141
}
42+
struct mTimingEvent** previous;
43+
struct mTimingEvent* next;
4244
if (timing->reroot) {
43-
timing->root = timing->reroot;
44-
timing->reroot = NULL;
45+
previous = &timing->reroot;
46+
next = timing->reroot;
47+
} else {
48+
previous = &timing->root;
49+
next = timing->root;
4550
}
46-
struct mTimingEvent** previous = &timing->root;
47-
struct mTimingEvent* next = timing->root;
51+
4852
unsigned priority = event->priority;
4953
while (next) {
5054
int32_t nextWhen = next->when - timing->masterCycles;
@@ -63,12 +67,16 @@ void mTimingScheduleAbsolute(struct mTiming* timing, struct mTimingEvent* event,
6367
}
6468

6569
void mTimingDeschedule(struct mTiming* timing, struct mTimingEvent* event) {
70+
struct mTimingEvent** previous;
71+
struct mTimingEvent* next;
6672
if (timing->reroot) {
67-
timing->root = timing->reroot;
68-
timing->reroot = NULL;
73+
previous = &timing->reroot;
74+
next = timing->reroot;
75+
} else {
76+
previous = &timing->root;
77+
next = timing->root;
6978
}
70-
struct mTimingEvent** previous = &timing->root;
71-
struct mTimingEvent* next = timing->root;
79+
7280
while (next) {
7381
if (next == event) {
7482
*previous = next->next;
@@ -105,13 +113,10 @@ int32_t mTimingTick(struct mTiming* timing, int32_t cycles) {
105113
timing->root = next->next;
106114
next->callback(timing, next->context, -nextWhen);
107115
}
108-
if (timing->reroot) {
116+
if (UNLIKELY(timing->reroot)) {
109117
timing->root = timing->reroot;
110118
timing->reroot = NULL;
111119
*timing->nextEvent = mTimingNextEvent(timing);
112-
if (*timing->nextEvent <= 0) {
113-
return mTimingTick(timing, 0);
114-
}
115120
}
116121
return *timing->nextEvent;
117122
}

0 commit comments

Comments
 (0)