4 * Implements inline procedure support for the LWKT subsystem.
6 * Generally speaking these routines only operate on threads associated
7 * with the current cpu. For example, a higher priority thread pending
8 * on a different cpu will not be immediately scheduled by a yield() on
11 * $DragonFly: src/sys/sys/thread2.h,v 1.9 2003/07/25 05:51:19 dillon Exp $
14 #ifndef _SYS_THREAD2_H_
15 #define _SYS_THREAD2_H_
18 * Critical sections prevent preemption by raising a thread's priority
19 * above the highest possible interrupting priority. Additionally, the
20 * current cpu will not be able to schedule a new thread but will instead
21 * place it on a pending list (with interrupts physically disabled) and
22 * set mycpu->gd_reqflags to indicate that work needs to be done, which
23 * lwkt_yield_quick() takes care of.
25 * Some of these routines take a struct thread pointer as an argument. This
26 * pointer MUST be curthread and is only passed as an optimization.
28 * Synchronous switching and blocking is allowed while in a critical section.
34 struct thread *td = curthread;
40 td->td_pri += TDPRI_CRIT;
44 crit_enter_quick(struct thread *curtd)
46 curtd->td_pri += TDPRI_CRIT;
50 crit_exit_noyield(struct thread *curtd)
52 curtd->td_pri -= TDPRI_CRIT;
54 if (curtd->td_pri < 0)
62 thread_t td = curthread;
64 td->td_pri -= TDPRI_CRIT;
69 if (td->td_pri < TDPRI_CRIT && td->td_gd->gd_reqflags)
74 crit_exit_quick(struct thread *curtd)
76 curtd->td_pri -= TDPRI_CRIT;
77 if (curtd->td_pri < TDPRI_CRIT && curtd->td_gd->gd_reqflags)
84 thread_t td = curthread;
86 td->td_pri = td->td_pri & TDPRI_MASK;
91 crit_panic_restore(int cpri)
93 curthread->td_pri = cpri;
97 lwkt_havetoken(lwkt_token_t tok)
99 return (tok->t_cpu == mycpu->gd_cpuid);
103 * Return whether any threads are runnable, whether they meet mp_lock
104 * requirements or not.
109 return (mycpu->gd_runqmask != 0);