Files
rt-thread/components/lwp/lwp_futex_table.c
Guorui Li 1aef0dba71
Some checks failed
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
[components/lwp]add doxygen comment for lwp futex. (#10763)
2025-10-04 10:02:21 +08:00

89 lines
2.1 KiB
C

/*
* Copyright (c) 2006-2025 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-11-01 Shell Init ver.
*/
#include "lwp_futex_internal.h"
static struct shared_futex_entry *_futex_hash_head;
/**
* @brief Add a futex to the global hash table
*
* @param[in] key Pointer to the shared futex key structure
* @param[in] futex The futex to be added to the table
*
* @return rt_err_t Returns RT_EOK on success, error code on failure
*/
rt_err_t futex_global_table_add(struct shared_futex_key *key, rt_futex_t futex)
{
rt_err_t rc = 0;
struct shared_futex_entry *entry = &futex->entry;
futex->entry.key.mobj = key->mobj;
futex->entry.key.offset = key->offset;
RT_UTHASH_ADD(_futex_hash_head, key, sizeof(struct shared_futex_key), entry);
return rc;
}
/**
* @brief Find a futex in the global hash table
*
* @param[in] key Pointer to the shared futex key structure
* @param[out] futex Pointer to store the found futex
*
* @return rt_err_t Returns RT_EOK if found, -RT_ENOENT if not found
*/
rt_err_t futex_global_table_find(struct shared_futex_key *key, rt_futex_t *futex)
{
rt_err_t rc;
rt_futex_t found_futex;
struct shared_futex_entry *entry;
RT_UTHASH_FIND(_futex_hash_head, key, sizeof(struct shared_futex_key), entry);
if (entry)
{
rc = RT_EOK;
found_futex = rt_container_of(entry, struct rt_futex, entry);
}
else
{
rc = -RT_ENOENT;
found_futex = RT_NULL;
}
*futex = found_futex;
return rc;
}
/**
* @brief Delete a futex from the global hash table
*
* @param[in] key Pointer to the shared futex key structure
*
* @return rt_err_t Returns RT_EOK if deleted successfully, -RT_ENOENT if not found
*/
rt_err_t futex_global_table_delete(struct shared_futex_key *key)
{
rt_err_t rc;
struct shared_futex_entry *entry;
RT_UTHASH_FIND(_futex_hash_head, key, sizeof(struct shared_futex_key), entry);
if (entry)
{
RT_UTHASH_DELETE(_futex_hash_head, entry);
rc = RT_EOK;
}
else
{
rc = -RT_ENOENT;
}
return rc;
}