注解读写锁

    百图画鸿蒙 + 百文说内核 + 百万注源码  => 挖透鸿蒙内核源码
    鸿蒙研究站 | http://weharmonyos.com (国内)
              | https://weharmony.github.io (国外)
    oschina | https://my.oschina.net/weharmony
    博客园 | https://www.cnblogs.com/weharmony/
    知乎 | https://www.zhihu.com/people/weharmonyos
    csdn | https://blog.csdn.net/kuangyufei
    51cto | https://harmonyos.51cto.com/column/34
    掘金 | https://juejin.cn/user/756888642000808
    公众号 | 鸿蒙研究站 (weharmonyos)
上级 cba3780e
此差异已折叠。
......@@ -41,14 +41,14 @@ extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
#define OS_RWLOCK_MAGIC 0xBEFDCAU
#define OS_RWLOCK_MAGIC 0xBEFDCAU ///< 读写锁魔法数字
enum RwlockMode {
RWLOCK_NONE_MODE,
RWLOCK_READ_MODE,
RWLOCK_WRITE_MODE,
RWLOCK_READFIRST_MODE,
RWLOCK_WRITEFIRST_MODE
RWLOCK_NONE_MODE, ///< 自由模式: 读写链表都没有内容
RWLOCK_READ_MODE, ///< 读模式: 读链表有数据,写链表没有数据
RWLOCK_WRITE_MODE, ///< 写模式: 写链表有数据,读链表没有数据
RWLOCK_READFIRST_MODE, ///< 读优先模式: 读链表中的任务最高优先级高于写链表中任务最高优先级
RWLOCK_WRITEFIRST_MODE ///< 写优先模式: 写链表中的任务最高优先级高于读链表中任务最高优先级
};
extern UINT32 OsRwlockRdUnsafe(LosRwlock *rwlock, UINT32 timeout);
......
......@@ -326,7 +326,7 @@ EXIT:
return;
}
///< 这块代码谁写的? 这种命名 ...
/// 这块代码谁写的? 这种命名 ...
STATIC FutexNode *OsFutexDeleteAlreadyWakeTaskAndGetNext(const FutexNode *node, FutexNode **headNode, BOOL isDeleteHead)
{
FutexNode *tempNode = (FutexNode *)node;
......
......@@ -66,7 +66,7 @@
#ifdef LOSCFG_BASE_IPC_RWLOCK
#define RWLOCK_COUNT_MASK 0x00FFFFFFU
/// 判断读写锁有效性
BOOL LOS_RwlockIsValid(const LosRwlock *rwlock)
{
if ((rwlock != NULL) && ((rwlock->magic & RWLOCK_COUNT_MASK) == OS_RWLOCK_MAGIC)) {
......@@ -75,7 +75,7 @@ BOOL LOS_RwlockIsValid(const LosRwlock *rwlock)
return FALSE;
}
/// 创建读写锁
/// 创建读写锁,初始化锁信息
UINT32 LOS_RwlockInit(LosRwlock *rwlock)
{
UINT32 intSave;
......@@ -98,7 +98,7 @@ UINT32 LOS_RwlockInit(LosRwlock *rwlock)
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
/// 删除指定的读写锁
UINT32 LOS_RwlockDestroy(LosRwlock *rwlock)
{
UINT32 intSave;
......@@ -122,18 +122,18 @@ UINT32 LOS_RwlockDestroy(LosRwlock *rwlock)
SCHEDULER_UNLOCK(intSave);
return LOS_OK;
}
/// 读写锁检查
STATIC UINT32 OsRwlockCheck(LosRwlock *rwlock)
{
if (rwlock == NULL) {
return LOS_EINVAL;
}
if (OS_INT_ACTIVE) {
if (OS_INT_ACTIVE) { // 读写锁不能在中断服务程序中使用。请想想为什么 ?
return LOS_EINTR;
}
/* DO NOT Call blocking API in system tasks */
/* DO NOT Call blocking API in system tasks | 系统任务不能使用读写锁 */
LosTaskCB *runTask = (LosTaskCB *)OsCurrTaskGet();
if (runTask->taskStatus & OS_TASK_FLAG_SYSTEM_TASK) {
return LOS_EPERM;
......@@ -141,19 +141,23 @@ STATIC UINT32 OsRwlockCheck(LosRwlock *rwlock)
return LOS_OK;
}
/// 指定任务优先级优先级是否低于 写锁任务最高优先级
STATIC BOOL OsRwlockPriCompare(LosTaskCB *runTask, LOS_DL_LIST *rwList)
{
if (!LOS_ListEmpty(rwList)) {
LosTaskCB *highestTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(rwList));
if (runTask->priority < highestTask->priority) {
LosTaskCB *highestTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(rwList));//首个写锁任务优先级是最高的
if (runTask->priority < highestTask->priority) {//如果当前任务优先级低于等待写锁任务
return TRUE;
}
return FALSE;
}
return TRUE;
}
/* 申请读模式下的锁,分三种情况:
1. 若无人持有锁,读任务可获得锁。
2. 若有人持有锁,读任务可获得锁,读取顺序按照任务优先级。
3. 若有人(非自己)持有写模式下的锁,则当前任务无法获得锁,直到写模式下的锁释放。
*/
STATIC UINT32 OsRwlockRdPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 timeout)
{
UINT32 ret;
......@@ -162,12 +166,12 @@ STATIC UINT32 OsRwlockRdPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
* When the rwlock mode is read mode or free mode and the priority of the current read task
* is higher than the first pended write task. current read task can obtain this rwlock.
*/
if (rwlock->rwCount >= 0) {
if (OsRwlockPriCompare(runTask, &(rwlock->writeList))) {
if (rwlock->rwCount == INT8_MAX) {
if (rwlock->rwCount >= 0) {//第一和第二种情况
if (OsRwlockPriCompare(runTask, &(rwlock->writeList))) {//读优先级低于写优先级,意思就是必须先写再读
if (rwlock->rwCount == INT8_MAX) {//读锁任务达到上限
return LOS_EINVAL;
}
rwlock->rwCount++;
rwlock->rwCount++;//读锁
return LOS_OK;
}
}
......@@ -176,45 +180,51 @@ STATIC UINT32 OsRwlockRdPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
return LOS_EINVAL;
}
if (!OsPreemptableInSched()) {
if (!OsPreemptableInSched()) {//不可抢占时
return LOS_EDEADLK;
}
/* The current task is not allowed to obtain the write lock when it obtains the read lock. */
if ((LosTaskCB *)(rwlock->writeOwner) == runTask) {
/* The current task is not allowed to obtain the write lock when it obtains the read lock.
| 当前任务在获得读锁时不允许获得写锁 */
if ((LosTaskCB *)(rwlock->writeOwner) == runTask) { //拥有写锁任务是否为当前任务
return LOS_EINVAL;
}
/*
* When the rwlock mode is write mode or the priority of the current read task
* is lower than the first pended write task, current read task will be pended.
| 当 rwlock 模式为写模式或当前读任务的优先级低于第一个挂起的写任务时,当前读任务将被挂起。
反正就是写锁任务优先
*/
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->readList));
ret = OsSchedTaskWait(node, timeout, TRUE);
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->readList));//找到要挂入的位置
//例如现有链表内任务优先级为 0 3 8 9 23 当前为 10 时, 返回的是 9 这个节点
ret = OsSchedTaskWait(node, timeout, TRUE);//从尾部插入读锁链表 由此变成了 0 3 8 9 10 23
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
return LOS_ETIMEDOUT;
}
return ret;
}
/// 申请写模式下的锁
STATIC UINT32 OsRwlockWrPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 timeout)
{
UINT32 ret;
/* When the rwlock is free mode, current write task can obtain this rwlock. */
/* When the rwlock is free mode, current write task can obtain this rwlock.
| 若该锁当前没有任务持有,或者持有该读模式下的锁的任务和申请该锁的任务为同一个任务,则申请成功,可立即获得写模式下的锁。*/
if (rwlock->rwCount == 0) {
rwlock->rwCount = -1;
rwlock->writeOwner = (VOID *)runTask;
rwlock->writeOwner = (VOID *)runTask;//直接给当前进程锁
return LOS_OK;
}
/* Current write task can use one rwlock once again if the rwlock owner is it. */
/* Current write task can use one rwlock once again if the rwlock owner is it.
| 如果 rwlock 拥有者是当前写入任务,则它可以再次使用该锁。*/
if ((rwlock->rwCount < 0) && ((LosTaskCB *)(rwlock->writeOwner) == runTask)) {
if (rwlock->rwCount == INT8_MIN) {
return LOS_EINVAL;
}
rwlock->rwCount--;
rwlock->rwCount--;//注意再次拥有算是两把锁了.
return LOS_OK;
}
......@@ -228,10 +238,10 @@ STATIC UINT32 OsRwlockWrPendOp(LosTaskCB *runTask, LosRwlock *rwlock, UINT32 tim
/*
* When the rwlock is read mode or other write task obtains this rwlock, current
* write task will be pended.
* write task will be pended. | 当 rwlock 为读模式或其他写任务获得该 rwlock 时,当前的写任务将被挂起。直到读模式下的锁释放
*/
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->writeList));
ret = OsSchedTaskWait(node, timeout, TRUE);
LOS_DL_LIST *node = OsSchedLockPendFindPos(runTask, &(rwlock->writeList));//找到要挂入的位置
ret = OsSchedTaskWait(node, timeout, TRUE);//从尾部插入写锁链表
if (ret == LOS_ERRNO_TSK_TIMEOUT) {
ret = LOS_ETIMEDOUT;
}
......@@ -305,7 +315,7 @@ UINT32 OsRwlockTryWrUnsafe(LosRwlock *rwlock, UINT32 timeout)
return OsRwlockWrPendOp(runTask, rwlock, timeout);
}
/// 申请指定的读模式下的锁
UINT32 LOS_RwlockRdLock(LosRwlock *rwlock, UINT32 timeout)
{
UINT32 intSave;
......@@ -320,7 +330,7 @@ UINT32 LOS_RwlockRdLock(LosRwlock *rwlock, UINT32 timeout)
SCHEDULER_UNLOCK(intSave);
return ret;
}
/// 尝试申请指定的读模式下的锁
UINT32 LOS_RwlockTryRdLock(LosRwlock *rwlock)
{
UINT32 intSave;
......@@ -335,7 +345,7 @@ UINT32 LOS_RwlockTryRdLock(LosRwlock *rwlock)
SCHEDULER_UNLOCK(intSave);
return ret;
}
/// 申请指定的写模式下的锁
UINT32 LOS_RwlockWrLock(LosRwlock *rwlock, UINT32 timeout)
{
UINT32 intSave;
......@@ -350,7 +360,7 @@ UINT32 LOS_RwlockWrLock(LosRwlock *rwlock, UINT32 timeout)
SCHEDULER_UNLOCK(intSave);
return ret;
}
/// 尝试申请指定的写模式下的锁
UINT32 LOS_RwlockTryWrLock(LosRwlock *rwlock)
{
UINT32 intSave;
......@@ -365,26 +375,26 @@ UINT32 LOS_RwlockTryWrLock(LosRwlock *rwlock)
SCHEDULER_UNLOCK(intSave);
return ret;
}
/// 获取读写锁模式
STATIC UINT32 OsRwlockGetMode(LOS_DL_LIST *readList, LOS_DL_LIST *writeList)
{
BOOL isReadEmpty = LOS_ListEmpty(readList);
BOOL isWriteEmpty = LOS_ListEmpty(writeList);
if (isReadEmpty && isWriteEmpty) {
return RWLOCK_NONE_MODE;
if (isReadEmpty && isWriteEmpty) { //读写链表都没有内容
return RWLOCK_NONE_MODE; //自由模式
}
if (!isReadEmpty && isWriteEmpty) {
if (!isReadEmpty && isWriteEmpty) { //读链表有数据,写链表没有数据
return RWLOCK_READ_MODE;
}
if (isReadEmpty && !isWriteEmpty) {
if (isReadEmpty && !isWriteEmpty) { //写链表有数据,读链表没有数据
return RWLOCK_WRITE_MODE;
}
LosTaskCB *pendedReadTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(readList));
LosTaskCB *pendedWriteTask = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(writeList));
if (pendedWriteTask->priority <= pendedReadTask->priority) {
return RWLOCK_WRITEFIRST_MODE;
if (pendedWriteTask->priority <= pendedReadTask->priority) { //都有数据比优先级
return RWLOCK_WRITEFIRST_MODE; //写的优先级高时,为写优先模式
}
return RWLOCK_READFIRST_MODE;
return RWLOCK_READFIRST_MODE; //读的优先级高时,为读优先模式
}
STATIC UINT32 OsRwlockPostOp(LosRwlock *rwlock, BOOL *needSched)
......@@ -465,7 +475,7 @@ UINT32 OsRwlockUnlockUnsafe(LosRwlock *rwlock, BOOL *needSched)
return OsRwlockPostOp(rwlock, needSched);
}
/// 释放指定读写锁
UINT32 LOS_RwlockUnLock(LosRwlock *rwlock)
{
UINT32 intSave;
......
......@@ -1194,19 +1194,19 @@ VOID LOS_Schedule(VOID)
SCHEDULER_UNLOCK(intSave);
}
/// 找到合适的位置 将当前任务插入到 读/写锁链表中
STATIC INLINE LOS_DL_LIST *OsSchedLockPendFindPosSub(const LosTaskCB *runTask, const LOS_DL_LIST *lockList)
{
LosTaskCB *pendedTask = NULL;
LOS_DL_LIST *node = NULL;
LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, lockList, LosTaskCB, pendList) {
if (pendedTask->priority < runTask->priority) {
LOS_DL_LIST_FOR_EACH_ENTRY(pendedTask, lockList, LosTaskCB, pendList) {//遍历阻塞链表
if (pendedTask->priority < runTask->priority) {//当前优先级更小,位置不宜,继续
continue;
} else if (pendedTask->priority > runTask->priority) {
} else if (pendedTask->priority > runTask->priority) {//找到合适位置
node = &pendedTask->pendList;
break;
} else {
} else {//找到合适位置
node = pendedTask->pendList.pstNext;
break;
}
......@@ -1214,7 +1214,7 @@ STATIC INLINE LOS_DL_LIST *OsSchedLockPendFindPosSub(const LosTaskCB *runTask, c
return node;
}
/// 找到合适的位置 将当前任务插入到 读/写锁链表中
LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockList)
{
LOS_DL_LIST *node = NULL;
......@@ -1222,14 +1222,14 @@ LOS_DL_LIST *OsSchedLockPendFindPos(const LosTaskCB *runTask, LOS_DL_LIST *lockL
if (LOS_ListEmpty(lockList)) {
node = lockList;
} else {
LosTaskCB *pendedTask1 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(lockList));
LosTaskCB *pendedTask2 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_LAST(lockList));
if (pendedTask1->priority > runTask->priority) {
node = lockList->pstNext;
} else if (pendedTask2->priority <= runTask->priority) {
LosTaskCB *pendedTask1 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_FIRST(lockList));//找到首任务
LosTaskCB *pendedTask2 = OS_TCB_FROM_PENDLIST(LOS_DL_LIST_LAST(lockList)); //找到尾任务
if (pendedTask1->priority > runTask->priority) { //首任务比当前任务优先级低 ,所以runTask可以排第一
node = lockList->pstNext;//下一个,注意priority越大 优先级越低
} else if (pendedTask2->priority <= runTask->priority) {//尾任务比当前任务优先级高 ,所以runTask排最后
node = lockList;
} else {
node = OsSchedLockPendFindPosSub(runTask, lockList);
} else {//两头比较没结果,陷入中间比较
node = OsSchedLockPendFindPosSub(runTask, lockList);//进入子级循环找
}
}
......
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* 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_HASH_H
#define _LOS_HASH_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/*
http://www.isthe.com/chongo/tech/comp/fnv/
/*
* Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
*
* 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_HASH_H
#define _LOS_HASH_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/*
http://www.isthe.com/chongo/tech/comp/fnv/
FNV算法简介
FNV算法属于非密码学哈希函数,它最初由Glenn Fowler和Kiem-Phong Vo于1991年在IEEE POSIX P1003.2上首先提出,
最后由Landon Curt Noll 完善,故该算法以三人姓的首字母命名。
最后由Landon Curt Noll 完善,故该算法以三人姓的首字母命名。
FNV算法目前有三种,分别是FNV-1,FNV-1a和FNV-0,但是FNV-0算法已经被丢弃了。FNV算法的哈希结果有32、64、128、256、512和1024位等长度。
如果需要哈希结果长度不属于以上任意一种,也可以采用根据Changing the FNV hash size - xor-folding上面的指导进行变换得到。
FNV-1算法过程如下:
如果需要哈希结果长度不属于以上任意一种,也可以采用根据Changing the FNV hash size - xor-folding上面的指导进行变换得到。
FNV-1算法过程如下:
hash = offset_basis
for each octet_of_data to be hashed
hash = hash * FNV_prime
hash = hash xor octet_of_data
return hash
FNV-1a算法过程如下:
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
FNV-0算法过程如下:
hash = 0
for each octet_of_data to be hashed
hash = hash * FNV_prime
hash = hash XOR octet_of_data
return hash
*/
#define FNV1_32A_INIT ((UINT32)0x811c9dc5)
/*
* 32 bit magic FNV-1 prime
*/
#define FNV_32_PRIME ((UINT32)0x01000193)
LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aBuf(const VOID *buf, size_t len, UINT32 hval)
{
const UINT8 *hashbuf = (const UINT8 *)buf;
/*
* FNV-1a hash each octet in the buffer
*/
while (len-- != 0) {
/* xor the bottom with the current octet */
hval ^= (UINT32)*hashbuf++;
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hval *= FNV_32_PRIME;
}
/* return our new hash value */
return hval;
}
LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aStr(CHAR *str, UINT32 hval)
{
UINT8 *s = (UINT8 *)str;
/*
* FNV-1a hash each octet in the buffer
*/
while (*s) {
/* xor the bottom with the current octet */
hval ^= (UINT32)*s++;
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hval *= FNV_32_PRIME;
}
/* return our new hash value */
return hval;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HASH_H */
FNV-1a算法过程如下:
hash = offset_basis
for each octet_of_data to be hashed
hash = hash xor octet_of_data
hash = hash * FNV_prime
return hash
FNV-0算法过程如下:
hash = 0
for each octet_of_data to be hashed
hash = hash * FNV_prime
hash = hash XOR octet_of_data
return hash
*/
#define FNV1_32A_INIT ((UINT32)0x811c9dc5)
/*
* 32 bit magic FNV-1 prime
*/
#define FNV_32_PRIME ((UINT32)0x01000193)
LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aBuf(const VOID *buf, size_t len, UINT32 hval)
{
const UINT8 *hashbuf = (const UINT8 *)buf;
/*
* FNV-1a hash each octet in the buffer
*/
while (len-- != 0) {
/* xor the bottom with the current octet */
hval ^= (UINT32)*hashbuf++;
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hval *= FNV_32_PRIME;
}
/* return our new hash value */
return hval;
}
LITE_OS_SEC_ALW_INLINE STATIC INLINE UINT32 LOS_HashFNV32aStr(CHAR *str, UINT32 hval)
{
UINT8 *s = (UINT8 *)str;
/*
* FNV-1a hash each octet in the buffer
*/
while (*s) {
/* xor the bottom with the current octet */
hval ^= (UINT32)*s++;
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hval *= FNV_32_PRIME;
}
/* return our new hash value */
return hval;
}
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_HASH_H */
......@@ -56,7 +56,7 @@ typedef struct OsRwlock {//读写锁
大于0时为读模式 , 小于0时为写模式 等于0为自由模式*/
VOID *writeOwner; /**< The current write thread that is locking the rwlock | 拥有写权限的任务*/
LOS_DL_LIST readList; /**< Read waiting list | 等待读锁的任务链表*/
LOS_DL_LIST writeList; /**< Write waiting list | 等待写*/
LOS_DL_LIST writeList; /**< Write waiting list | 等待写锁的任务链表*/
} LosRwlock;
extern BOOL LOS_RwlockIsValid(const LosRwlock *rwlock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册