1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2023-11-01     Shell        Porting to RTT API
9  */
10 #ifndef __LIBADT_RT_UTHASH_H__
11 #define __LIBADT_RT_UTHASH_H__
12 
13 #include <rtthread.h>
14 
15 #define uthash_malloc(sz)    rt_malloc(sz)
16 #define uthash_free(ptr, sz) rt_free(ptr)
17 
18 /**
19  * for performance consideration, using libc implementations
20  * as the default case. If you care about the compatibility
21  * problem, define the RT_UTHASH_CONFIG_COMPATIBILITY_FIRST
22  * before including the rt_uthash.h.
23  */
24 #ifndef RT_UTHASH_CONFIG_COMPATIBILITY_FIRST
25 #define uthash_bzero(a, n) memset(a, '\0', n)
26 #define uthash_strlen(s)   strlen(s)
27 
28 #else
29 #define uthash_bzero(a, n) rt_memset(a, '\0', n)
30 #define uthash_strlen(s)   rt_strlen(s)
31 
32 #endif /* RT_UTHASH_CONFIG_COMPATIBILITY_FIRST */
33 
34 /* if any fatal happen, throw an exception and return a failure */
35 #define uthash_fatal(msg)  \
36     do                     \
37     {                      \
38         LOG_E(msg);        \
39         return -RT_ENOMEM; \
40     } while (0)
41 
42 #include "uthash.h"
43 
44 #define DEFINE_RT_UTHASH_TYPE(entry_name, key_type, key_name) \
45     typedef struct entry_name                                 \
46     {                                                         \
47         key_type key_name;                                    \
48         UT_hash_handle hh;                                    \
49     } *entry_name##_t;
50 
51 #define RT_UTHASH_ADD(head, key_member, keylen_in, value) \
52     HASH_ADD(hh, head, key_member, keylen_in, value)
53 #define RT_UTHASH_FIND(head, key_ptr, keylen_in, pval) \
54     HASH_FIND(hh, head, key_ptr, keylen_in, pval)
55 #define RT_UTHASH_DELETE(head, pobj) HASH_DELETE(hh, head, pobj)
56 
57 #endif /* __LIBADT_RT_UTHASH_H__ */
58