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 11 #include <rtthread.h> 12 #include <rtm.h> 13 14 #include "dlmodule.h" 15 16 /** 17 * @brief close a dynamically loaded shared library. 18 * 19 * @param handle the handle which identifies the shared library to be closed. 20 * @return int it returns RT_TRUE on success. 21 * 22 * @note This function is an API of POSIX standard, which is designed to decrease the reference count (nref) for a dynamically loaded module 23 * and destroy it if no references remain. 24 */ dlclose(void * handle)25int dlclose(void *handle) 26 { 27 struct rt_dlmodule *module; 28 29 RT_ASSERT(handle != RT_NULL); 30 31 module = (struct rt_dlmodule *)handle; 32 33 rt_enter_critical(); 34 module->nref--; 35 if (module->nref <= 0) 36 { 37 rt_exit_critical(); 38 39 dlmodule_destroy(module); 40 } 41 else 42 { 43 rt_exit_critical(); 44 } 45 46 return RT_TRUE; 47 } 48 RTM_EXPORT(dlclose) 49