A spinlock provides a mutual exclusion mechanism to prevent two tasks from accessing the same shared resource at the same time.
The spinlock module of Huawei LiteOS provides the following functions. For details about the APIs, see the API reference.
The typical spinlock development process is as follows:
Spinlocks depend on the SMP. Run the make menuconfig command and choose Kernel > Enable Kernel SMP to configure the spinlock.
To create a spinlock, call the LOS_SpinInit API to initialize the spinlock, or call SPIN_LOCK_INIT API to initialize the spinlock of the static memory.
Call the LOS_SpinLock, LOS_SpinTrylock, or LOS_SpinLockSave API to request a spinlock. If the request is successful, the code for lock protection is executed. If the request fails, the system enters a busy loop till a spinlock is obtained.
Call the LOS_SpinUnlock/LOS_SpinUnlockRestore API to release a spinlock. After the lock protection code is executed, the corresponding spinlock is released, so that other cores can request the spinlock.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。