rt_uthash.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include <rtthread.h>
  13. #define uthash_malloc(sz) rt_malloc(sz)
  14. #define uthash_free(ptr, sz) rt_free(ptr)
  15. /**
  16. * for performance consideration, using libc implementations
  17. * as the default case. If you care about the compatibility
  18. * problem, define the RT_UTHASH_CONFIG_COMPATIBILITY_FIRST
  19. * before including the rt_uthash.h.
  20. */
  21. #ifndef RT_UTHASH_CONFIG_COMPATIBILITY_FIRST
  22. #define uthash_bzero(a, n) memset(a, '\0', n)
  23. #define uthash_strlen(s) strlen(s)
  24. #else
  25. #define uthash_bzero(a, n) rt_memset(a, '\0', n)
  26. #define uthash_strlen(s) rt_strlen(s)
  27. #endif /* RT_UTHASH_CONFIG_COMPATIBILITY_FIRST */
  28. /* if any fatal happen, throw an exception and return a failure */
  29. #define uthash_fatal(msg) \
  30. do \
  31. { \
  32. LOG_E(msg); \
  33. return -RT_ENOMEM; \
  34. } while (0)
  35. #include "uthash.h"
  36. #define DEFINE_RT_UTHASH_TYPE(entry_name, key_type, key_name) \
  37. typedef struct entry_name \
  38. { \
  39. key_type key_name; \
  40. UT_hash_handle hh; \
  41. } *entry_name##_t;
  42. #define RT_UTHASH_ADD(head, key_member, keylen_in, value) \
  43. HASH_ADD(hh, head, key_member, keylen_in, value)
  44. #define RT_UTHASH_FIND(head, key_ptr, keylen_in, pval) \
  45. HASH_FIND(hh, head, key_ptr, keylen_in, pval)
  46. #define RT_UTHASH_DELETE(head, pobj) HASH_DELETE(hh, head, pobj)
  47. #endif /* __LIBADT_RT_UTHASH_H__ */