You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
4.1 KiB
92 lines
4.1 KiB
/* ----------------------------------------------------------------------------
|
|
* Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved.
|
|
* Description: Semaphore Private HeadFile
|
|
* Author: Huawei LiteOS Team
|
|
* Create: 2013-01-01
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
* conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
|
|
* to endorse or promote products derived from this software without specific prior written
|
|
* permission.
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
* --------------------------------------------------------------------------- */
|
|
//这个头文件定义了一些关于信号量的数据结构和函数声明,用于信号量的控制和管理。
|
|
#ifndef _LOS_SEM_PRI_H
|
|
#define _LOS_SEM_PRI_H
|
|
|
|
#include "los_sem.h"
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
|
|
/* Semaphore control structure. */
|
|
//信号量控制块的数据结构
|
|
typedef struct {
|
|
UINT8 semStat;//信号量的状态 /* Semaphore state, enum LosSemState */
|
|
UINT8 semType;//信号量的类型 /* Semaphore Type, enum LosSemType */
|
|
UINT16 semCount;//信号量可用数量 /* number of available semaphores */
|
|
UINT32 semId;//信号量ID /* Semaphore control structure ID, COUNT(UINT16)|INDEX(UINT16) */
|
|
LOS_DL_LIST semList; /* List of tasks that are waiting on a semaphore */
|
|
} LosSemCB;
|
|
|
|
/* Semaphore type */
|
|
//信号量类型的枚举值:包括计数信号量和二进制信号量
|
|
enum {
|
|
OS_SEM_COUNTING, /* The semaphore is a counting semaphore which max count is LOS_SEM_COUNT_MAX */
|
|
OS_SEM_BINARY, /* The semaphore is a binary semaphore which max count is OS_SEM_BINARY_COUNT_MAX */
|
|
};
|
|
|
|
/* Max count of binary semaphores */
|
|
//二进制信号量的最大计数值
|
|
#define OS_SEM_BINARY_COUNT_MAX 1
|
|
|
|
/* Semaphore information control block */
|
|
//信号量信息控制块的全局指针
|
|
extern LosSemCB *g_allSem;
|
|
|
|
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
|
|
|
|
#ifndef LOSCFG_RESOURCE_ID_NOT_USE_HIGH_BITS
|
|
|
|
/* COUNT | INDEX split bit */
|
|
#define SEM_SPLIT_BIT 16
|
|
#define SET_SEM_ID(count, semId) (((count) << SEM_SPLIT_BIT) | (semId))
|
|
#define GET_SEM_INDEX(semId) ((semId) & ((1U << SEM_SPLIT_BIT) - 1))
|
|
#define GET_SEM_COUNT(semId) ((semId) >> SEM_SPLIT_BIT)
|
|
#else
|
|
#define GET_SEM_INDEX(semId) (semId)
|
|
#endif
|
|
|
|
#define GET_SEM(semId) (((LosSemCB *)g_allSem) + GET_SEM_INDEX(semId))
|
|
|
|
/* This API is used to create a semaphore control structure according to the initial number of available semaphores
|
|
* specified by count and return the ID of this semaphore control structure. */
|
|
用于根据初始可用信号量的数量创建信号量控制结构的函数
|
|
extern UINT32 OsSemInit(VOID);
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
#endif /* __cplusplus */
|
|
|
|
#endif /* _LOS_SEM_PRI_H */
|