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.13 2004/03/01 06:33:19 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 * Initialize a tokref_t. We only need to initialize the token pointer
107 * and the magic number. We do not have to initialize tr_next, tr_gdreqnext,
111 lwkt_tokref_init(lwkt_tokref_t ref, lwkt_token_t tok)
113 ref->tr_magic = LWKT_TOKREF_MAGIC1;
118 * Return whether any threads are runnable, whether they meet mp_lock
119 * requirements or not.
124 return (mycpu->gd_runqmask != 0);