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.12 2004/02/10 07:34:43 dillon Exp $
14 #ifndef _SYS_THREAD2_H_
15 #define _SYS_THREAD2_H_
18 * Userland will have its own globaldata which it includes prior to this.
20 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
21 #ifndef _SYS_GLOBALDATA_H_
22 #include <sys/globaldata.h>
27 * Critical sections prevent preemption by raising a thread's priority
28 * above the highest possible interrupting priority. Additionally, the
29 * current cpu will not be able to schedule a new thread but will instead
30 * place it on a pending list (with interrupts physically disabled) and
31 * set mycpu->gd_reqflags to indicate that work needs to be done, which
32 * lwkt_yield_quick() takes care of.
34 * Some of these routines take a struct thread pointer as an argument. This
35 * pointer MUST be curthread and is only passed as an optimization.
37 * Synchronous switching and blocking is allowed while in a critical section.
43 struct thread *td = curthread;
45 td->td_pri += TDPRI_CRIT;
53 crit_enter_quick(struct thread *curtd)
55 curtd->td_pri += TDPRI_CRIT;
59 crit_exit_noyield(struct thread *curtd)
61 curtd->td_pri -= TDPRI_CRIT;
63 if (curtd->td_pri < 0)
71 thread_t td = curthread;
73 td->td_pri -= TDPRI_CRIT;
78 if (td->td_pri < TDPRI_CRIT && td->td_gd->gd_reqflags)
83 crit_exit_quick(struct thread *curtd)
85 curtd->td_pri -= TDPRI_CRIT;
86 if (curtd->td_pri < TDPRI_CRIT && curtd->td_gd->gd_reqflags)
93 thread_t td = curthread;
95 td->td_pri = td->td_pri & TDPRI_MASK;
100 crit_panic_restore(int cpri)
102 curthread->td_pri = cpri;
106 lwkt_havetoken(lwkt_token_t tok)
108 return (tok->t_cpu == mycpu);
112 * Return whether any threads are runnable, whether they meet mp_lock
113 * requirements or not.
118 return (mycpu->gd_runqmask != 0);