Give ps access to a process's thread structure.
[dragonfly.git] / sys / sys / thread2.h
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  *
11  * $DragonFly: src/sys/sys/thread2.h,v 1.2 2003/06/27 20:27:19 dillon Exp $
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  */
27 static __inline void
28 crit_enter(void)
29 {
30     curthread->td_pri += TDPRI_CRIT;
31 }
32
33 static __inline void
34 crit_exit_noyield(void)
35 {
36     thread_t td = curthread;
37
38     td->td_pri -= TDPRI_CRIT;
39     KASSERT(td->td_pri >= 0, ("crit_exit nesting error"));
40 }
41
42 static __inline void
43 crit_exit(void)
44 {
45     thread_t td = curthread;
46
47     td->td_pri -= TDPRI_CRIT;
48     KASSERT(td->td_pri >= 0, ("crit_exit nesting error"));
49     if (td->td_pri < mycpu->gd_reqpri)
50         lwkt_yield_quick();
51 }
52
53 static __inline int
54 lwkt_raisepri(int pri)
55 {
56     int opri = curthread->td_pri;
57     if (opri < pri)
58         curthread->td_pri = pri;
59     return(opri);
60 }
61
62 static __inline int
63 lwkt_lowerpri(int pri)
64 {
65     thread_t td = curthread;
66     int opri = td->td_pri;
67     if (opri > pri) {
68         td->td_pri = pri;
69         if (pri < mycpu->gd_reqpri)
70             lwkt_yield_quick();
71     }
72     return(opri);
73 }
74
75 static __inline void
76 lwkt_setpri(int pri)
77 {
78     curthread->td_pri = pri;
79     if (pri < mycpu->gd_reqpri)
80         lwkt_yield_quick();
81 }
82
83 static __inline int
84 lwkt_havetoken(lwkt_token_t tok)
85 {
86     return (tok->t_cpu == mycpu->gd_cpuid);
87 }
88
89 #endif
90