dlclose.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2006-2024 RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-11-17 yi.qiu first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtm.h>
  12. #include "dlmodule.h"
  13. /**
  14. * @brief close a dynamically loaded shared library.
  15. *
  16. * @param handle the handle which identifies the shared library to be closed.
  17. * @return int it returns RT_TRUE on success.
  18. *
  19. * @note This function is an API of POSIX standard, which is designed to decrease the reference count (nref) for a dynamically loaded module
  20. * and destroy it if no references remain.
  21. */
  22. int dlclose(void *handle)
  23. {
  24. struct rt_dlmodule *module;
  25. RT_ASSERT(handle != RT_NULL);
  26. module = (struct rt_dlmodule *)handle;
  27. rt_enter_critical();
  28. module->nref--;
  29. if (module->nref <= 0)
  30. {
  31. rt_exit_critical();
  32. dlmodule_destroy(module);
  33. }
  34. else
  35. {
  36. rt_exit_critical();
  37. }
  38. return RT_TRUE;
  39. }
  40. RTM_EXPORT(dlclose)