MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_cpus_lock

Function rt_cpus_lock

src/cpu_mp.c:168–196  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

166 * @note This function only has MP version.
167 */
168rt_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}
197RTM_EXPORT(rt_cpus_lock);
198
199/**

Callers 4

demo_core_threadFunction · 0.85
core_threadFunction · 0.85
demo_core_threadFunction · 0.85
demo_core_threadFunction · 0.85

Calls 4

rt_cpu_selfFunction · 0.70
rt_enter_criticalFunction · 0.70
rt_critical_levelFunction · 0.70
rt_hw_spin_lockFunction · 0.50

Tested by 1

core_threadFunction · 0.68