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.14 2004/04/10 20:55:24 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_enter_gd(globaldata_t mygd)
61 crit_enter_quick(mygd->gd_curthread);
65 crit_exit_noyield(struct thread *curtd)
67 curtd->td_pri -= TDPRI_CRIT;
69 if (curtd->td_pri < 0)
77 thread_t td = curthread;
79 td->td_pri -= TDPRI_CRIT;
84 if (td->td_pri < TDPRI_CRIT && td->td_gd->gd_reqflags)
89 crit_exit_quick(struct thread *curtd)
91 curtd->td_pri -= TDPRI_CRIT;
92 if (curtd->td_pri < TDPRI_CRIT && curtd->td_gd->gd_reqflags)
97 crit_exit_gd(globaldata_t mygd)
99 crit_exit_quick(mygd->gd_curthread);
103 crit_panic_save(void)
105 thread_t td = curthread;
106 int pri = td->td_pri;
107 td->td_pri = td->td_pri & TDPRI_MASK;
112 crit_panic_restore(int cpri)
114 curthread->td_pri = cpri;
118 * Initialize a tokref_t. We only need to initialize the token pointer
119 * and the magic number. We do not have to initialize tr_next, tr_gdreqnext,
123 lwkt_tokref_init(lwkt_tokref_t ref, lwkt_token_t tok)
125 ref->tr_magic = LWKT_TOKREF_MAGIC1;
130 * Return whether any threads are runnable, whether they meet mp_lock
131 * requirements or not.
136 return (mycpu->gd_runqmask != 0);