Browse Source

simplified sched_switch

sched_switch can check ISR itself.
dev/timer
Oleg Hahm 9 years ago
parent
commit
32f918abe8
  1. 3
      core/include/sched.h
  2. 2
      core/mutex.c
  3. 4
      core/sched.c
  4. 2
      sys/posix/pthread/pthread.c
  5. 2
      sys/semaphore/semaphore.c

3
core/include/sched.h

@ -55,9 +55,8 @@ void sched_set_status(tcb_t *process, unsigned int status);
*
* @param[in] current_prio The priority of the current thread
* @param[in] other_prio The priority of the target thread
* @param[in] in_isr 1 if currently in interrupt context, 0 otherwise
*/
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr);
void sched_switch(uint16_t current_prio, uint16_t other_prio);
/**
* @brief Call context switching at task exit

2
core/mutex.c

@ -108,7 +108,7 @@ void mutex_unlock(struct mutex_t *mutex)
DEBUG("%s: waking up waiter.\n", process->name);
sched_set_status(process, STATUS_PENDING);
sched_switch(active_thread->priority, process->priority, inISR());
sched_switch(active_thread->priority, process->priority);
}
else {
mutex->val = 0;

4
core/sched.c

@ -171,8 +171,10 @@ void sched_set_status(tcb_t *process, unsigned int status)
process->status = status;
}
void sched_switch(uint16_t current_prio, uint16_t other_prio, int in_isr)
void sched_switch(uint16_t current_prio, uint16_t other_prio)
{
int in_isr = inISR();
DEBUG("%s: %i %i %i\n", active_thread->name, (int)current_prio, (int)other_prio, in_isr);
if (current_prio >= other_prio) {

2
sys/posix/pthread/pthread.c

@ -152,7 +152,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*sta
return -1;
}
sched_switch(active_thread->priority, PRIORITY_MAIN, inISR());
sched_switch(active_thread->priority, PRIORITY_MAIN);
return 0;
}

2
sys/semaphore/semaphore.c

@ -145,7 +145,7 @@ int sem_post(sem_t *sem)
tcb_t *next_process = (tcb_t*) next->data;
DEBUG("%s: waking up %s\n", active_thread->name, next_process->name);
sched_set_status(next_process, STATUS_PENDING);
sched_switch(active_thread->priority, next_process->priority, inISR());
sched_switch(active_thread->priority, next_process->priority);
}
restoreIRQ(old_state);

Loading…
Cancel
Save