From 80a2d058b8a182a357a9bdb5bc1bad864fbb6568 Mon Sep 17 00:00:00 2001 From: chao an Date: Mon, 7 Nov 2022 16:12:02 +0800 Subject: [PATCH] lib/atexit: correct return value of exitfunc lock Signed-off-by: chao an --- libs/libc/stdlib/lib_atexit.c | 46 +++-------------------------------- 1 file changed, 4 insertions(+), 42 deletions(-) diff --git a/libs/libc/stdlib/lib_atexit.c b/libs/libc/stdlib/lib_atexit.c index 74f831e3bc..0486cdf63b 100644 --- a/libs/libc/stdlib/lib_atexit.c +++ b/libs/libc/stdlib/lib_atexit.c @@ -58,45 +58,6 @@ static FAR struct atexit_list_s * get_exitfuncs(void) return &info->ta_exit; } -/**************************************************************************** - * Name: exitfunc_lock - * - * Description: - * Obtain the exit function lock. - * - * Returned Value: - * OK on success, or negated errno on failure - * - ****************************************************************************/ - -static int exitfunc_lock(void) -{ - FAR struct task_info_s *info = task_get_info(); - int ret = nxmutex_lock(&info->ta_lock); - - if (ret < 0) - { - ret = -ret; - } - - return ret; -} - -/**************************************************************************** - * Name: exitfunc_unlock - * - * Description: - * Release exit function lock . - * - ****************************************************************************/ - -static void exitfunc_unlock(void) -{ - FAR struct task_info_s *info = task_get_info(); - - nxmutex_unlock(&info->ta_lock); -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -104,6 +65,7 @@ static void exitfunc_unlock(void) int atexit_register(int type, CODE void (*func)(void), FAR void *arg, FAR void *dso) { + FAR struct task_info_s *info = task_get_info(); FAR struct atexit_list_s *aehead; int idx; int ret = ERROR; @@ -118,10 +80,10 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg, if (func) { - ret = exitfunc_lock(); + ret = nxmutex_lock(&info->ta_lock); if (ret < 0) { - return ret; + return -ret; } if ((idx = aehead->nfuncs) < ATEXIT_MAX) @@ -137,7 +99,7 @@ int atexit_register(int type, CODE void (*func)(void), FAR void *arg, ret = ERROR; } - exitfunc_unlock(); + nxmutex_unlock(&info->ta_lock); } return ret;