* @brief This function will lock all cpus's scheduler and disable local irq. * * @return Return current cpu interrupt status. * * @note This function only has MP version. */
| 166 | * @note This function only has MP version. |
| 167 | */ |
| 168 | rt_base_t rt_cpus_lock(void) |
| 169 | { |
| 170 | rt_base_t level; |
| 171 | struct rt_cpu* pcpu; |
| 172 | |
| 173 | level = rt_hw_local_irq_disable(); |
| 174 | pcpu = rt_cpu_self(); |
| 175 | if (pcpu->current_thread != RT_NULL) |
| 176 | { |
| 177 | rt_ubase_t lock_nest = rt_atomic_load(&(pcpu->current_thread->cpus_lock_nest)); |
| 178 | |
| 179 | rt_atomic_add(&(pcpu->current_thread->cpus_lock_nest), 1); |
| 180 | if (lock_nest == 0) |
| 181 | { |
| 182 | rt_enter_critical(); |
| 183 | rt_hw_spin_lock(&_cpus_lock); |
| 184 | #ifdef RT_USING_DEBUG |
| 185 | _cpus_critical_level = rt_critical_level(); |
| 186 | #endif /* RT_USING_DEBUG */ |
| 187 | |
| 188 | #ifdef RT_DEBUGING_SPINLOCK |
| 189 | _cpus_lock_owner = pcpu->current_thread; |
| 190 | _cpus_lock_pc = __GET_RETURN_ADDRESS; |
| 191 | #endif /* RT_DEBUGING_SPINLOCK */ |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return level; |
| 196 | } |
| 197 | RTM_EXPORT(rt_cpus_lock); |
| 198 | |
| 199 | /** |