|
0
|
1 #ifndef CYGONCE_KERNEL_SCHED_INL |
|
|
2 #define CYGONCE_KERNEL_SCHED_INL |
|
|
3 |
|
|
4 //========================================================================== |
|
|
5 // |
|
2
|
6 // sched.inl |
|
0
|
7 // |
|
2
|
8 // Scheduler class inlines |
|
0
|
9 // |
|
|
10 //========================================================================== |
|
|
11 //####COPYRIGHTBEGIN#### |
|
|
12 // |
|
|
13 // ------------------------------------------- |
|
|
14 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
|
16 // compliance with the License. You may obtain a copy of the License at |
|
|
17 // http://sourceware.cygnus.com/ecos |
|
|
18 // |
|
|
19 // Software distributed under the License is distributed on an "AS IS" |
|
|
20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
21 // License for the specific language governing rights and limitations under |
|
|
22 // the License. |
|
|
23 // |
|
|
24 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
25 // September 30, 1998. |
|
|
26 // |
|
|
27 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
28 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
29 // ------------------------------------------- |
|
|
30 // |
|
|
31 //####COPYRIGHTEND#### |
|
|
32 //========================================================================== |
|
|
33 //#####DESCRIPTIONBEGIN#### |
|
|
34 // |
|
2
|
35 // Author(s): nickg |
|
|
36 // Contributors: nickg |
|
|
37 // Date: 1997-09-09 |
|
|
38 // Purpose: Define inlines for scheduler classes |
|
|
39 // Description: Inline functions for the scheduler classes. These are |
|
0
|
40 // not defined in the header so that we have the option |
|
|
41 // of making them non-inline. |
|
|
42 // Usage: |
|
|
43 // #include <cyg/kernel/sched.hxx> |
|
|
44 // ... |
|
2
|
45 // #include <cyg/kernel/sched.inl> |
|
|
46 // ... |
|
0
|
47 // |
|
|
48 //####DESCRIPTIONEND#### |
|
|
49 // |
|
|
50 //========================================================================== |
|
|
51 |
|
|
52 #include <cyg/kernel/instrmnt.h> |
|
|
53 |
|
|
54 #include <cyg/kernel/thread.inl> // we use some thread inlines here |
|
|
55 |
|
|
56 // ------------------------------------------------------------------------- |
|
|
57 // Inlines for Cyg_Scheduler class |
|
|
58 |
|
|
59 inline void Cyg_Scheduler::lock() |
|
|
60 { |
|
|
61 // We do not need to do a read-modify-write sequence here because |
|
|
62 // the scheduler lock is strictly nesting. Even if we are interrupted |
|
|
63 // partway through the increment, the lock will be returned to the same |
|
|
64 // value before we are resumed/rescheduled. |
|
|
65 |
|
2
|
66 HAL_REORDER_BARRIER(); |
|
|
67 |
|
0
|
68 sched_lock++; |
|
|
69 |
|
|
70 HAL_REORDER_BARRIER(); |
|
|
71 |
|
|
72 CYG_INSTRUMENT_SCHED(LOCK,sched_lock,0); |
|
|
73 }; |
|
|
74 |
|
|
75 inline void Cyg_Scheduler::unlock() |
|
|
76 { |
|
|
77 // This is an inline wrapper for the real scheduler unlock function in |
|
|
78 // Cyg_Scheduler::unlock_inner(). |
|
|
79 |
|
|
80 // Only do anything if the lock is about to go zero, otherwise we simply |
|
|
81 // decrement and return. As with lock() we do not need any special code |
|
|
82 // to decrement the lock counter. |
|
|
83 |
|
|
84 CYG_INSTRUMENT_SCHED(UNLOCK,sched_lock,0); |
|
|
85 |
|
|
86 HAL_REORDER_BARRIER(); |
|
|
87 |
|
2
|
88 cyg_ucount32 __lock = sched_lock - 1; |
|
0
|
89 |
|
2
|
90 if( __lock == 0 ) unlock_inner(); |
|
|
91 else sched_lock = __lock; |
|
|
92 |
|
|
93 HAL_REORDER_BARRIER(); |
|
|
94 } |
|
|
95 |
|
|
96 inline void Cyg_Scheduler::unlock_simple() |
|
|
97 { |
|
|
98 // This function decrements the lock, but does not call unlock_inner(). |
|
|
99 // Therefore does not immediately allow another thread to run: |
|
|
100 // merely makes it possible for some other thread to run at some |
|
|
101 // indeterminate future time. This is mainly for use by |
|
|
102 // debuggers, it should not normally be used anywhere else. |
|
|
103 |
|
|
104 CYG_INSTRUMENT_SCHED(UNLOCK,sched_lock,0); |
|
|
105 |
|
|
106 HAL_REORDER_BARRIER(); |
|
|
107 |
|
|
108 if (sched_lock > 0) |
|
|
109 sched_lock = sched_lock - 1; |
|
|
110 |
|
|
111 HAL_REORDER_BARRIER(); |
|
0
|
112 } |
|
|
113 |
|
|
114 |
|
|
115 // ------------------------------------------------------------------------- |
|
|
116 // Inlines for Cyg_SchedThread class |
|
|
117 |
|
|
118 inline void Cyg_SchedThread::remove() |
|
|
119 { |
|
|
120 if( queue != NULL ) |
|
|
121 { |
|
|
122 queue->remove((Cyg_Thread *)this); |
|
|
123 queue = NULL; |
|
|
124 } |
|
|
125 } |
|
|
126 |
|
|
127 // ------------------------------------------------------------------------- |
|
|
128 |
|
|
129 #endif // ifndef CYGONCE_KERNEL_SCHED_INL |
|
|
130 // EOF sched.inl |