#include "signal.h"
-#include <cfg/cfg_timer.h>
+#include "cfg/cfg_timer.h"
#include <cfg/debug.h>
+#include <cfg/depend.h>
+
#include <cpu/irq.h>
#include <kern/proc.h>
#include <kern/proc_p.h>
#if CONFIG_KERN_SIGNALS
+// Check config dependencies
+CONFIG_DEPEND(CONFIG_KERN_SIGNALS, CONFIG_KERN);
+
/**
* Check if any of the signals in \a sigs has occurred and clear them.
*
sigmask_t sig_check(sigmask_t sigs)
{
sigmask_t result;
- cpuflags_t flags;
+ cpu_flags_t flags;
IRQ_SAVE_DISABLE(flags);
- result = CurrentProcess->sig_recv & sigs;
- CurrentProcess->sig_recv &= ~sigs;
+ result = current_process->sig_recv & sigs;
+ current_process->sig_recv &= ~sigs;
IRQ_RESTORE(flags);
return result;
sigmask_t sig_wait(sigmask_t sigs)
{
sigmask_t result;
- cpuflags_t flags;
/* Sleeping with IRQs disabled or preemption forbidden is illegal */
IRQ_ASSERT_ENABLED();
-
- #if CONFIG_KERN_PREEMPT
- ASSERT(preempt_forbid_cnt == 0);
- #endif
+ ASSERT(proc_preemptAllowed());
/*
* This is subtle: there's a race condition where a concurrent
* In this case, we'd deadlock with the signal bit already set
* and the process never being reinserted into the ready list.
*/
- // FIXME: just use IRQ_DISABLE() here
- IRQ_SAVE_DISABLE(flags);
+ IRQ_DISABLE;
/* Loop until we get at least one of the signals */
- while (!(result = CurrentProcess->sig_recv & sigs))
+ while (!(result = current_process->sig_recv & sigs))
{
/*
* Tell "them" that we want to be awaken when any of these
* signals arrives.
*/
- CurrentProcess->sig_wait = sigs;
+ current_process->sig_wait = sigs;
/*
* Go to sleep and proc_switch() to another process.
* We re-enable IRQs because proc_switch() does not
* guarantee to save and restore the interrupt mask.
*/
- IRQ_RESTORE(flags);
+ IRQ_ENABLE;
proc_switch();
- IRQ_SAVE_DISABLE(flags);
+ IRQ_DISABLE;
/*
* When we come back here, the wait mask must have been
* one of the signals we were expecting must have been
* delivered to us.
*/
- ASSERT(!CurrentProcess->sig_wait);
- ASSERT(CurrentProcess->sig_recv & sigs);
+ ASSERT(!current_process->sig_wait);
+ ASSERT(current_process->sig_recv & sigs);
}
/* Signals found: clear them and return */
- CurrentProcess->sig_recv &= ~sigs;
+ current_process->sig_recv &= ~sigs;
- IRQ_RESTORE(flags);
+ IRQ_ENABLE;
return result;
}
{
Timer t;
sigmask_t res;
- cpuflags_t flags;
+ cpu_flags_t flags;
ASSERT(!sig_check(SIG_TIMEOUT));
ASSERT(!(sigs & SIG_TIMEOUT));
*/
void sig_signal(Process *proc, sigmask_t sigs)
{
- cpuflags_t flags;
+ cpu_flags_t flags;
/* See comment in sig_wait() for why this protection is necessary */
IRQ_SAVE_DISABLE(flags);
/* Check if process needs to be awoken */
if (proc->sig_recv & proc->sig_wait)
{
- /* Wake up process and enqueue in ready list */
+ /*
+ * Wake up process and enqueue in ready list.
+ *
+ * Move this process to the head of the ready list, so that it
+ * will be chosen at the next scheduling point.
+ */
proc->sig_wait = 0;
- SCHED_ENQUEUE(proc);
+ SCHED_ENQUEUE_HEAD(proc);
}
IRQ_RESTORE(flags);