MP Implementation 1/2: Get the APIC code working again, sweetly integrate the
[dragonfly.git] / sys / sys / thread2.h
CommitLineData
f1d1c3fa
MD
1/*
2 * SYS/THREAD2.H
3 *
4 * Implements inline procedure support for the LWKT subsystem.
5 *
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
9 * this cpu.
10 *
8a8d5d85 11 * $DragonFly: src/sys/sys/thread2.h,v 1.5 2003/07/06 21:23:54 dillon Exp $
f1d1c3fa
MD
12 */
13
14#ifndef _SYS_THREAD2_H_
15#define _SYS_THREAD2_H_
16
17/*
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_reqpri to indicate that work needs to be done, which
23 * lwkt_yield_quick() takes care of.
24 *
25 * Synchronous switching and blocking is allowed while in a critical section.
26 */
27static __inline void
28crit_enter(void)
29{
26a0694b
MD
30 struct thread *td = curthread;
31
32 if (td->td_pri < 0)
33 crit_panic();
34 td->td_pri += TDPRI_CRIT;
f1d1c3fa
MD
35}
36
37static __inline void
38crit_exit_noyield(void)
39{
40 thread_t td = curthread;
41
42 td->td_pri -= TDPRI_CRIT;
26a0694b
MD
43 if (td->td_pri < 0)
44 crit_panic();
f1d1c3fa
MD
45}
46
47static __inline void
48crit_exit(void)
49{
50 thread_t td = curthread;
51
52 td->td_pri -= TDPRI_CRIT;
26a0694b
MD
53 if (td->td_pri < 0)
54 crit_panic();
f1d1c3fa
MD
55 if (td->td_pri < mycpu->gd_reqpri)
56 lwkt_yield_quick();
57}
58
8a8d5d85
MD
59static __inline int
60crit_panic_save(void)
61{
62 thread_t td = curthread;
63 int pri = td->td_pri;
64 td->td_pri = td->td_pri & TDPRI_MASK;
65 return(pri);
66}
67
68static __inline void
69crit_panic_restore(int cpri)
70{
71 curthread->td_pri = cpri;
72}
73
4b5f931b
MD
74static __inline int
75lwkt_havetoken(lwkt_token_t tok)
f1d1c3fa 76{
4b5f931b 77 return (tok->t_cpu == mycpu->gd_cpuid);
f1d1c3fa
MD
78}
79
80static __inline int
4b5f931b 81lwkt_runnable(void)
f1d1c3fa 82{
4b5f931b 83 return (mycpu->gd_runqmask != 0);
f1d1c3fa
MD
84}
85
86#endif
87