Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block, unsigned sta
sched_set_status(target, STATUS_PENDING);

irq_restore(state);
thread_yield_higher();

}

return 1;
Expand Down Expand Up @@ -207,8 +207,11 @@ int msg_send_int(msg_t *m, kernel_pid_t target_pid)
msg_t *target_message = (msg_t*) target->wait_data;
*target_message = *m;
sched_set_status(target, STATUS_PENDING);

#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
sched_context_switch_request = 1;
#else
thread_yield_higher();
#endif
return 1;
}
else {
Expand Down Expand Up @@ -272,7 +275,11 @@ int msg_reply_int(msg_t *m, msg_t *reply)
msg_t *target_message = (msg_t*) target->wait_data;
*target_message = *reply;
sched_set_status(target, STATUS_PENDING);
sched_context_switch_request = 1;
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
sched_context_switch_request = 1;
#else
thread_yield_higher();
#endif
return 1;
}

Expand Down
7 changes: 7 additions & 0 deletions core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ schedstat sched_pidlist[KERNEL_PID_LAST + 1];

int __attribute__((used)) sched_run(void)
{
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
sched_context_switch_request = 0;
#endif

thread_t *active_thread = (thread_t *)sched_active_thread;

Expand Down Expand Up @@ -194,6 +196,7 @@ void sched_switch(uint16_t other_prio)
active_thread->pid, current_prio, on_runqueue, other_prio);

if (!on_runqueue || (current_prio > other_prio)) {
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
if (irq_is_in()) {
DEBUG("sched_switch: setting sched_context_switch_request.\n");
sched_context_switch_request = 1;
Expand All @@ -202,6 +205,10 @@ void sched_switch(uint16_t other_prio)
DEBUG("sched_switch: yielding immediately.\n");
thread_yield_higher();
}
#else
DEBUG("sched_switch: yielding immediately.\n");
thread_yield_higher();
#endif
}
else {
DEBUG("sched_switch: continuing without yield.\n");
Expand Down
4 changes: 4 additions & 0 deletions core/thread_flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ inline int __attribute__((always_inline)) thread_flags_wake(thread_t *thread)
if (wakeup) {
DEBUG("_thread_flags_wake(): waking up pid %"PRIkernel_pid"\n", thread->pid);
sched_set_status(thread, STATUS_PENDING);
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
sched_context_switch_request = 1;
#else
thread_yield_higher();
#endif
}

return wakeup;
Expand Down
3 changes: 2 additions & 1 deletion cpu/atmega_common/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,12 @@ static inline void _isr(tim_t tim, int chan)
*ctx[tim].mask &= ~(1 << (chan + OCIE1A));
ctx[tim].cb(ctx[tim].arg, chan);

#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
if (sched_context_switch_request) {
thread_yield();
thread_yield_isr();
}

#endif
__exit_isr();
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions cpu/atmega_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ static inline void isr_handler(int num)
{
isr_ctx[num].rx_cb(isr_ctx[num].arg, dev[num]->DR);

#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
if (sched_context_switch_request) {
thread_yield();
thread_yield_isr();
}
#endif
}

#ifdef UART_0_ISR
Expand Down
14 changes: 13 additions & 1 deletion cpu/atmega_common/thread_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,24 @@ void NORETURN __enter_thread_mode(void)
}

void thread_yield_higher(void) {

if (irq_is_in() == 0) {
__context_save();
sched_run();
__context_restore();

__asm__ volatile("ret");
} else {
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
sched_context_switch_request = 1;
#else
__context_save();
sched_run();
__context_restore();

__exit_isr();
__asm__ volatile("reti");
#endif
}
}

Expand All @@ -237,7 +248,8 @@ void thread_yield_isr(void) {
__context_restore();

__exit_isr();

PORTF |= (1 << 5);
PORTF &= ~(1 << 5);
__asm__ volatile("reti");
}

Expand Down
3 changes: 3 additions & 0 deletions sys/evtimer/evtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,12 @@ void evtimer_add(evtimer_t *evtimer, evtimer_event_t *event)
_set_timer(&evtimer->timer, event->offset);
}
irq_restore(state);
#if !defined(ISR_CONTEXT_SWITCH_ALLOWED)
if (sched_context_switch_request) {
thread_yield_higher();
}
#endif

}

void evtimer_del(evtimer_t *evtimer, evtimer_event_t *event)
Expand Down