Skip to content

Commit

Permalink
Name wrapped dlopen and phtread_* functions using GC_wrap_ macros
Browse files Browse the repository at this point in the history
(refactoring)

Issue #364 (bdwgc).

This is needed as the direct use of WRAP_[DL]FUNC() macro in a function
declaration confuses clang-format.

* gc_dlopen.c (GC_wrap_dlopen): New macro; undefine it after the
function.
* pthread_support.c (GC_wrap_pthread_sigmask, GC_wrap_pthread_cancel,
GC_wrap_pthread_exit, GC_wrap_pthread_join, GC_wrap_pthread_detach,
GC_wrap_pthread_create): Likewise.
* gc_dlopen.c (WRAP_DLFUNC(dlopen)): Change name to the relevant
GC_wrap_*.
* pthread_support.c (WRAP_FUNC(pthread_sigmask),
WRAP_FUNC(pthread_cancel), WRAP_FUNC(pthread_exit),
WRAP_FUNC(pthread_join), WRAP_FUNC(pthread_detach),
WRAP_FUNC(pthread_create)): Likewise.
  • Loading branch information
ivmai committed Oct 2, 2024
1 parent 2936975 commit c584704
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion gc_dlopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
# define REAL_DLFUNC(f) f
#endif

GC_API void * WRAP_DLFUNC(dlopen)(const char *path, int mode)
#define GC_wrap_dlopen WRAP_DLFUNC(dlopen)
GC_API void *GC_wrap_dlopen(const char *path, int mode)
{
void * result;

Expand All @@ -84,6 +85,7 @@ GC_API void * WRAP_DLFUNC(dlopen)(const char *path, int mode)
# endif
return result;
}
#undef GC_wrap_dlopen

#ifdef GC_USE_LD_WRAP
/* Define GC_ function as an alias for the plain one, which will be */
Expand Down
26 changes: 19 additions & 7 deletions pthread_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,9 @@ GC_INNER void GC_init_parallel(void)
}

#if !defined(GC_NO_PTHREAD_SIGMASK) && defined(GC_PTHREADS)
GC_API int WRAP_FUNC(pthread_sigmask)(int how, const sigset_t *set,
sigset_t *oset)
# define GC_wrap_pthread_sigmask WRAP_FUNC(pthread_sigmask)
GC_API int GC_wrap_pthread_sigmask(int how, const sigset_t *set,
sigset_t *oset)
{
# ifdef GC_WIN32_THREADS
/* pthreads-win32 does not support sigmask. */
Expand All @@ -1857,6 +1858,7 @@ GC_INNER void GC_init_parallel(void)
# endif
return REAL_FUNC(pthread_sigmask)(how, set, oset);
}
# undef GC_wrap_pthread_sigmask
#endif /* !GC_NO_PTHREAD_SIGMASK */

/* Wrapper for functions that are likely to block for an appreciable */
Expand Down Expand Up @@ -2255,7 +2257,8 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
/* risk growing the heap unnecessarily. But it seems that we don't */
/* really have an option in that the process is not in a fully */
/* functional state while a thread is exiting. */
GC_API int WRAP_FUNC(pthread_cancel)(pthread_t thread)
# define GC_wrap_pthread_cancel WRAP_FUNC(pthread_cancel)
GC_API int GC_wrap_pthread_cancel(pthread_t thread)
{
# ifdef CANCEL_SAFE
GC_thread t;
Expand All @@ -2276,10 +2279,12 @@ GC_API int GC_CALL GC_unregister_my_thread(void)
# endif
return REAL_FUNC(pthread_cancel)(thread);
}
# undef GC_wrap_pthread_cancel
#endif /* !GC_NO_PTHREAD_CANCEL */

#ifdef GC_HAVE_PTHREAD_EXIT
GC_API GC_PTHREAD_EXIT_ATTRIBUTE void WRAP_FUNC(pthread_exit)(void *retval)
# define GC_wrap_pthread_exit WRAP_FUNC(pthread_exit)
GC_API GC_PTHREAD_EXIT_ATTRIBUTE void GC_wrap_pthread_exit(void *retval)
{
GC_thread me;

Expand All @@ -2296,6 +2301,7 @@ GC_API int GC_CALL GC_unregister_my_thread(void)

REAL_FUNC(pthread_exit)(retval);
}
# undef GC_wrap_pthread_exit
#endif /* GC_HAVE_PTHREAD_EXIT */

GC_API void GC_CALL GC_allow_register_threads(void)
Expand Down Expand Up @@ -2417,7 +2423,8 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
UNLOCK();
}

GC_API int WRAP_FUNC(pthread_join)(pthread_t thread, void **retval)
# define GC_wrap_pthread_join WRAP_FUNC(pthread_join)
GC_API int GC_wrap_pthread_join(pthread_t thread, void **retval)
{
int result;
GC_thread t;
Expand Down Expand Up @@ -2469,8 +2476,10 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
# endif
return result;
}
# undef GC_wrap_pthread_join

GC_API int WRAP_FUNC(pthread_detach)(pthread_t thread)
# define GC_wrap_pthread_detach WRAP_FUNC(pthread_detach)
GC_API int GC_wrap_pthread_detach(pthread_t thread)
{
int result;
GC_thread t;
Expand All @@ -2492,6 +2501,7 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
}
return result;
}
# undef GC_wrap_pthread_detach

struct start_info {
void *(*start_routine)(void *);
Expand Down Expand Up @@ -2568,7 +2578,8 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
# endif
}

GC_API int WRAP_FUNC(pthread_create)(pthread_t *new_thread,
# define GC_wrap_pthread_create WRAP_FUNC(pthread_create)
GC_API int GC_wrap_pthread_create(pthread_t *new_thread,
GC_PTHREAD_CREATE_CONST pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
{
Expand Down Expand Up @@ -2663,6 +2674,7 @@ GC_API int GC_CALL GC_register_my_thread(const struct GC_stack_base *sb)
sem_destroy(&si.registered);
return result;
}
# undef GC_wrap_pthread_create

#endif /* GC_PTHREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 */

Expand Down

0 comments on commit c584704

Please sign in to comment.