Changeset 21536 in vbox for trunk/src/VBox/Runtime/r0drv/linux
- Timestamp:
- Jul 13, 2009 2:49:39 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 50009
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/linux/thread-r0drv-linux.c
r21337 r21536 37 37 38 38 #include <iprt/thread.h> 39 #include <iprt/asm.h> 40 #include <iprt/assert.h> 39 41 #include <iprt/err.h> 40 #include <iprt/assert.h> 42 43 44 /******************************************************************************* 45 * Global Variables * 46 *******************************************************************************/ 47 #ifndef CONFIG_PREEMPT 48 /** Per-cpu preemption counters. */ 49 static int32_t volatile g_acPreemptDisabled[NR_CPUS]; 50 #endif 41 51 42 52 … … 76 86 RTDECL(bool) RTThreadPreemptIsEnabled(RTTHREAD hThread) 77 87 { 88 #ifdef CONFIG_PREEMPT 78 89 Assert(hThread == NIL_RTTHREAD); 79 #ifdef CONFIG_PREEMPT80 90 # ifdef preemptible 81 91 return preemptible(); … … 84 94 # endif 85 95 #else 86 return false; 96 int32_t c; 97 98 Assert(hThread == NIL_RTTHREAD); 99 c = g_acPreemptDisabled[smp_processor_id()]; 100 AssertMsg(c >= 0 && c < 32, ("%d\n", c)); 101 return c == 0 && !in_atomic() && !irqs_disabled(); 87 102 #endif 88 103 } … … 117 132 118 133 134 RTDECL(bool) RTThreadPreemptIsPossible(void) 135 { 136 #ifdef CONFIG_PREEMPT 137 return true; /* yes, kernel preemption is possible. */ 138 #else 139 return false; /* no kernel preemption */ 140 #endif 141 } 142 RT_EXPORT_SYMBOL(RTThreadPreemptIsPossible); 143 144 119 145 RTDECL(void) RTThreadPreemptDisable(PRTTHREADPREEMPTSTATE pState) 120 146 { 147 #ifdef CONFIG_PREEMPT 121 148 AssertPtr(pState); 122 149 Assert(pState->uchDummy != 42); 123 150 pState->uchDummy = 42; 151 preempt_disable(); 124 152 125 /* 126 * Note: This call is a NOP if CONFIG_PREEMPT is not enabled in the Linux kernel 127 * configuration. In that case, schedule() is only called need_resched() is set 128 * which is tested just before we return to R3 (not when returning from R0 to R0). 129 */ 130 preempt_disable(); 153 #else /* !CONFIG_PREEMPT */ 154 int32_t c; 155 AssertPtr(pState); 156 157 /* Do our own accounting. */ 158 c = ASMAtomicIncS32(&g_acPreemptDisabled[smp_processor_id()]); 159 AssertMsg(c > 0 && c < 32, ("%d\n", c)); 160 pState->uchDummy = (unsigned char )c; 161 #endif 131 162 } 132 163 RT_EXPORT_SYMBOL(RTThreadPreemptDisable); … … 135 166 RTDECL(void) RTThreadPreemptRestore(PRTTHREADPREEMPTSTATE pState) 136 167 { 168 #ifdef CONFIG_PREEMPT 137 169 AssertPtr(pState); 138 170 Assert(pState->uchDummy == 42); 139 171 pState->uchDummy = 0; 172 preempt_enable(); 140 173 141 preempt_enable(); 174 #else 175 int32_t volatile *pc; 176 AssertPtr(pState); 177 AssertMsg(pState->uchDummy > 0 && pState->uchDummy < 32, ("%d\n", pState->uchDummy)); 178 179 /* Do our own accounting. */ 180 pc = &g_acPreemptDisabled[smp_processor_id()]; 181 AssertMsg(pState->uchDummy == (uint32_t)*pc, ("uchDummy=%d *pc=%d \n", pState->uchDummy, *pc)); 182 ASMAtomicUoWriteS32(pc, pState->uchDummy - 1); 183 #endif 142 184 } 143 185 RT_EXPORT_SYMBOL(RTThreadPreemptRestore); 144 186 187 188 RTDECL(bool) RTThreadIsInInterrupt(RTTHREAD hThread) 189 { 190 Assert(hThread == NIL_RTTHREAD); NOREF(hThread); 191 192 return in_interrupt() != 0; 193 } 194 RT_EXPORT_SYMBOL(RTThreadIsInInterrupt); 195
Note:
See TracChangeset
for help on using the changeset viewer.