From 1f2946b7ab07778eea7a51dcb4fcd25e1daf32d1 Mon Sep 17 00:00:00 2001 From: Antoine Juckler <6445757+ajuckler@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:07:17 +0900 Subject: [PATCH] include/threads.h: Replace thrd_ defines by actual function definitions --- include/threads.h | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/include/threads.h b/include/threads.h index 39d8a4932a..e97c1a77b7 100644 --- a/include/threads.h +++ b/include/threads.h @@ -33,6 +33,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -107,22 +108,35 @@ typedef CODE void (*tss_dtor_t)(FAR void *); * int thrd_create(FAR thrd_t *thr, thrd_start_t func, FAR void *arg); */ -#define thrd_create(thr,func,arg) \ - pthread_create(thr,NULL,(pthread_startroutine_t)(func),arg) +static inline int thrd_create(FAR thrd_t *thr, + thrd_start_t func, + FAR void *arg) +{ + return pthread_create(thr, + NULL, + (pthread_startroutine_t)func, + arg); +} /* thrd_equal: checks if two identifiers refer to the same thread * * int thrd_equal(thrd_t lhs, thrd_t rhs); */ -#define thrd_equal(lhs,rhs) ((lhs) == (rhs)) +static inline int thrd_equal(thrd_t lhs, thrd_t rhs) +{ + return (lhs == rhs) ? 1 : 0; +} /* thrd_current: obtains the current thread identifier * * thrd_t thrd_current(void); */ -#define thrd_current() ((thrd_t)_SCHED_GETTID()) +static inline thrd_t thrd_current(void) +{ + return pthread_self(); +} /* thrd_sleep: suspends execution of the calling thread for the given * period of time @@ -131,28 +145,41 @@ typedef CODE void (*tss_dtor_t)(FAR void *); * FAR struct timespec *remaining); */ -#define thrd_sleep(rqtp,rmtp) nanosleep(rqtp,rmtp) +static inline int thrd_sleep(FAR const struct timespec *time_point, + FAR struct timespec *remaining) +{ + return nanosleep(time_point, remaining); +} /* thrd_yield: yields the current time slice * * void thrd_yield(void); */ -#define thrd_yield() pthread_yield() +static inline void thrd_yield(void) +{ + pthread_yield(); +} /* thrd_exit: terminates the calling thread * * _Noreturn void thrd_exit(int res); */ -#define thrd_exit(res) pthread_exit((pthread_addr_t)(res)) +static inline noreturn void thrd_exit(int res) +{ + pthread_exit((pthread_addr_t)res); +} /* thrd_detach: detaches a thread * * int thrd_detach(thrd_t thr); */ -#define thrd_detach(thr) pthread_detach(thr) +static inline int thrd_detach(thrd_t thr) +{ + return pthread_detach(thr); +} /* thrd_join: blocks until a thread terminates *