rt-thread-official/components/libc/posix/libdl/dlclose.c

49 lines
1.0 KiB
C
Raw Normal View History

2013-01-08 22:40:58 +08:00
/*
2024-11-12 15:38:28 +08:00
* Copyright (c) 2006-2024 RT-Thread Development Team
2013-01-08 22:40:58 +08:00
*
2018-08-30 20:27:45 +08:00
* SPDX-License-Identifier: Apache-2.0
2013-01-08 22:40:58 +08:00
*
* Change Logs:
2018-08-30 20:27:45 +08:00
* Date Author Notes
* 2010-11-17 yi.qiu first version
2013-01-08 22:40:58 +08:00
*/
#include <rtthread.h>
#include <rtm.h>
2018-08-30 20:27:45 +08:00
#include "dlmodule.h"
2024-11-12 15:38:28 +08:00
/**
* @brief close a dynamically loaded shared library.
*
* @param handle the handle which identifies the shared library to be closed.
* @return int it returns RT_TRUE on success.
*
* @note This function is an API of POSIX standard, which is designed to decrease the reference count (nref) for a dynamically loaded module
* and destroy it if no references remain.
*/
2018-08-30 20:27:45 +08:00
int dlclose(void *handle)
2013-01-08 22:40:58 +08:00
{
2018-08-30 20:27:45 +08:00
struct rt_dlmodule *module;
2013-01-08 22:40:58 +08:00
2018-08-30 20:27:45 +08:00
RT_ASSERT(handle != RT_NULL);
module = (struct rt_dlmodule *)handle;
2013-01-08 22:40:58 +08:00
2018-08-30 20:27:45 +08:00
rt_enter_critical();
module->nref--;
if (module->nref <= 0)
{
rt_exit_critical();
dlmodule_destroy(module);
}
else
{
rt_exit_critical();
}
return RT_TRUE;
}
RTM_EXPORT(dlclose)