804 Star 2.4K Fork 1.2K

GVPHuawei LiteOS / LiteOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
development-guidelines-37.md 12.55 KB
一键复制 编辑 原始数据 按行查看 历史

Development Guidelines

Usage Scenarios

A spinlock provides a mutual exclusion mechanism to prevent two tasks from accessing the same shared resource at the same time.

Functions

The spinlock module of Huawei LiteOS provides the following functions. For details about the APIs, see the API reference.

Function Category

API

Description

Spinlock initialization

LOS_SpinInit

Dynamically initializes a spinlock.

SPIN_LOCK_INIT

Statically initializes a spinlock.

Spinlock request and release

LOS_SpinLock

Requests a specified spinlock. If the spinlock cannot be obtained, the system waits in a loop.

LOS_SpinTrylock

Attempts to request a specified spinlock. If the spinlock cannot be obtained, a failure message is returned, and the system does not wait in a loop.

LOS_SpinUnlock

Releases a spinlock.

Spinlock request and release (with disabled interrupt)

LOS_SpinLockSave

Requests a spinlock after the interrupt is disabled.

LOS_SpinUnlockRestore

Releases a spinlock and restores the interrupt.

Spinlock holding status

LOS_SpinHeld

Checks whether a spinlock is held.

Development Process

The typical spinlock development process is as follows:

  1. Spinlocks depend on the SMP. Run the make menuconfig command and choose Kernel > Enable Kernel SMP to configure the spinlock.

    Configuration Item

    Description

    Value Range

    Default Value

    Dependency

    LOSCFG_KERNEL_SMP

    Whether to enable the SMP.

    YES/NO

    YES

    Multi-core hardware is supported.

    LOSCFG_KERNEL_SMP_CORE_NUM

    Number of cores in the multi-core scenario.

    Depends on the architecture.

    2

    None

  2. 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.

  3. 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.

  4. 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.

C
1
https://gitee.com/LiteOS/LiteOS.git
git@gitee.com:LiteOS/LiteOS.git
LiteOS
LiteOS
LiteOS
master

搜索帮助