summaryrefslogtreecommitdiff
path: root/components/libc/posix/libdl/dlclose.c
blob: 87638924fa5a2d70d2bb264ffec9bb05ad41155a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Copyright (c) 2006-2024 RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2010-11-17     yi.qiu       first version
 */

#include <rtthread.h>
#include <rtm.h>

#include "dlmodule.h"

/**
 * @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.
 */
int dlclose(void *handle)
{
    struct rt_dlmodule *module;

    RT_ASSERT(handle != RT_NULL);

    module = (struct rt_dlmodule *)handle;

    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)