This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
tango-maat/src/inc_internal/rcu_hash.h

82 lines
1.9 KiB
C
Raw Normal View History

2022-11-17 05:05:35 +08:00
/*
**********************************************************************************************
2022-11-29 14:12:40 +08:00
* File: rcu_hash.h
* Description: rcu hashtable
2022-11-17 05:05:35 +08:00
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-10-31
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#ifndef _RCU_HASH_H_
#define _RCU_HASH_H_
#ifdef __cplusplus
2022-11-17 05:05:35 +08:00
extern "C"
{
#endif
#include "uthash/uthash.h"
2022-11-25 16:32:29 +08:00
typedef void rcu_hash_data_free_fn(void *user_ctx, void *data);
2022-11-17 05:05:35 +08:00
/* rcu hash table */
struct rcu_hash_table;
2022-11-25 16:32:29 +08:00
struct rcu_hash_table *rcu_hash_new(rcu_hash_data_free_fn *free_fn);
2022-11-17 05:05:35 +08:00
void rcu_hash_free(struct rcu_hash_table *htable);
2022-11-25 16:32:29 +08:00
void rcu_hash_set_user_ctx(struct rcu_hash_table *htable, void *user_ctx);
2022-12-09 17:12:18 +08:00
void *rcu_hash_get_user_ctx(struct rcu_hash_table *htable);
2022-11-17 05:05:35 +08:00
/**
* @brief Adding the updating nodes which will become effective nodes after call rcu_hash_commit
*
* @retval 0(success) -1(failed)
2022-11-17 05:05:35 +08:00
*/
int rcu_hash_add(struct rcu_hash_table *htable, const char *key, size_t key_len, void *data);
2022-11-17 05:05:35 +08:00
/**
* @brief Deleting
*/
int rcu_hash_del(struct rcu_hash_table *htable, const char *key, size_t key_len);
2022-11-17 05:05:35 +08:00
/**
* @brief find in effective nodes
*
* @param htable: the rcu_hash_table
* @param key: the key used for searching in the hash table
* @param key_len: the key's length
*
* @retval NULL or
*/
void *rcu_hash_find(struct rcu_hash_table *htable, const char *key, size_t key_len);
/**
* @brief list all effective nodes
*
* @retval the number of effective nodes
*/
size_t rcu_hash_list(struct rcu_hash_table *htable, void ***data_array);
2022-11-25 16:32:29 +08:00
size_t rcu_hash_count(struct rcu_hash_table *htable);
/**
* @brief if rcu hash is updating
*
* @retval True(1) False(0)
*/
int rcu_hash_is_updating(struct rcu_hash_table *htable);
2022-11-17 05:05:35 +08:00
/**
* @brief make add/del effective
*/
void rcu_hash_commit(struct rcu_hash_table *htable);
#ifdef __cplusplus
2022-11-17 05:05:35 +08:00
}
#endif
#endif