From 661ba7ec21865e0d0c9ea26d53b3af709e2a479a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 30 Sep 2022 22:57:11 +0800 Subject: [PATCH 001/133] build: Bump ABI suffix Signed-off-by: LIU Hao --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f4d59d631c..5716288c75 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) ## Define ABI information AS_VAR_SET([abi_major], [1]) AS_VAR_SET([abi_minor], [2]) -AS_VAR_SET([abi_suffix], [alpha.1]) +AS_VAR_SET([abi_suffix], [beta.1]) ## Check for assertions AC_ARG_ENABLE([debug-checks], AS_HELP_STRING([--enable-debug-checks], [enable assertions])) From 1956af07763cc7df0fb22343210ad7ad3873e04e Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 3 Oct 2022 03:11:46 +0800 Subject: [PATCH 002/133] thread: Initialize x87 precision to 80 bits for new threads (cherry picked from commit 45873f256a221998cb7f3a41b37788d3332a86c9) Signed-off-by: LIU Hao --- src/thread.c | 5 +++++ test/Makefile.inc.am | 1 + test/thread_x87_precision.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/thread_x87_precision.c diff --git a/src/thread.c b/src/thread.c index b544892728..2d441dcacc 100644 --- a/src/thread.c +++ b/src/thread.c @@ -18,6 +18,11 @@ do_win32_thread_thunk(LPVOID param) __MCF_SEH_DEFINE_TERMINATE_FILTER; _MCF_thread* self = param; +#if defined(__i386__) || defined(__amd64__) + /* Set x87 precision to 80 bits. */ + __asm__ volatile ("fninit"); +#endif /* x86 */ + /* Wait until the structure has been fully initialized. */ DWORD cmp = 0; if(_MCF_atomic_cmpxchg_32_rlx(&(self->__tid), &cmp, -1)) diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index d1ed06e743..285c5e31ad 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -34,6 +34,7 @@ check_PROGRAMS += \ %reldir%/tls_dtor_ignored_on__Exit.test \ %reldir%/thread_self_id.test \ %reldir%/thread_overlarge.test \ + %reldir%/thread_x87_precision.test \ %reldir%/gthr_c89_pedantic.test \ %reldir%/gthr_inline_alias.test \ %reldir%/gthr_once.test \ diff --git a/test/thread_x87_precision.c b/test/thread_x87_precision.c new file mode 100644 index 0000000000..960c86f331 --- /dev/null +++ b/test/thread_x87_precision.c @@ -0,0 +1,36 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/thread.h" +#include +#include + +static +void +thread_proc(_MCF_thread* self) + { +#if defined(__i386__) || defined(__amd64__) + assert(sizeof(long double) > 8); + static volatile long double eps = 0x0.000000000000001p0L; + static volatile long double ep1 = 0x1.000000000000001p0L; + + assert(ep1 != 1); + assert(eps + 1 == ep1); +#endif // x87 + + printf("thread %d quitting\n", self->__tid); + } + +int +main(void) + { + _MCF_thread* thrd = _MCF_thread_new(thread_proc, NULL, 0); + assert(thrd); + + printf("main waiting\n"); + _MCF_thread_wait(thrd, NULL); + printf("main wait finished\n"); + + _MCF_thread_wait(thrd, NULL); + } From cfa48170603ea0e22a61470520e10e495cee8aca Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 4 Oct 2022 19:52:28 +0800 Subject: [PATCH 003/133] gthr: Move `__MCF_gthr_active_p()` to the end, and make it `constexpr` (cherry picked from commit 3768a1eda78fa280fcd1f6f22a85882c24178fbc) Signed-off-by: LIU Hao --- src/gthr.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gthr.h b/src/gthr.h index 309b4021e5..e479e6f1ff 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -46,20 +46,13 @@ typedef __MCF_gthr_rc_mutex __gthread_recursive_mutex_t; /* Informs the runtime that threading support is active. * Windows creates new threads for console control handlers, so threading * cannot be disabled. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); __MCF_GTHR_ALIAS(__gthread_active_p, __MCF_gthr_active_p); -__MCF_DECLSPEC_GTHR_INLINE -int -__MCF_gthr_active_p(void) __MCF_NOEXCEPT - { - return 1; - } - /* Performs one-time initialization, like `pthread_once()`. */ __MCF_DECLSPEC_GTHR_INLINE int @@ -287,6 +280,13 @@ __MCF_GTHR_ALIAS(__gthread_yield, __MCF_gthr_yield); * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ +__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) +int +__MCF_gthr_active_p(void) __MCF_NOEXCEPT + { + return 1; + } + __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc) From 59d96460ab1380655dbf8a67b17c6b38619da121 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 4 Oct 2022 23:34:52 +0800 Subject: [PATCH 004/133] thread: Don't define functions with empty parentheses (cherry picked from commit dccd8f957397273a45b2bc7622fab6f0743a1a51) Signed-off-by: LIU Hao --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 2d441dcacc..76177c18a0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -96,7 +96,7 @@ _MCF_thread_drop_ref_nonnull(_MCF_thread* thrd) __MCF_DLLEXPORT void -_MCF_thread_exit() +_MCF_thread_exit(void) { ExitThread(0); __MCF_UNREACHABLE; From 297995778ccd223dea7c7304e8f86b8c6009fb1c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 5 Oct 2022 01:25:57 +0800 Subject: [PATCH 005/133] test/at{,_quick_}exit: Fix tests (cherry picked from commit 8a1f2c55c9fb273d3154191eeb438003065db6ce) Signed-off-by: LIU Hao --- test/at_quick_exit_order.c | 1 + test/atexit_order.c | 1 + 2 files changed, 2 insertions(+) diff --git a/test/at_quick_exit_order.c b/test/at_quick_exit_order.c index 3bf8c2850f..4a52399083 100644 --- a/test/at_quick_exit_order.c +++ b/test/at_quick_exit_order.c @@ -27,4 +27,5 @@ main(void) static int value = 42; __MCF_cxa_at_quick_exit(atexit_second, &value, NULL); __MCF_cxa_at_quick_exit(atexit_first, &value, NULL); + __MCF_quick_exit(1); } diff --git a/test/atexit_order.c b/test/atexit_order.c index 926bdca5f5..e24ae216a5 100644 --- a/test/atexit_order.c +++ b/test/atexit_order.c @@ -27,4 +27,5 @@ main(void) static int value = 42; __MCF_cxa_atexit(atexit_second, &value, NULL); __MCF_cxa_atexit(atexit_first, &value, NULL); + __MCF_exit(1); } From 1c05931c990ecea65777f5a2a545385b54acefb3 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 5 Oct 2022 21:36:24 +0800 Subject: [PATCH 006/133] fwd: Add `__MCF_ALIGN()` (cherry picked from commit 99faaac6fde4382d7de4fc8002bde9fe9cd6e668) Signed-off-by: LIU Hao --- src/fwd.h | 2 +- src/thread.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index bfcb391770..9a0b1b8cb9 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #ifdef __cplusplus @@ -83,6 +82,7 @@ extern "C" { #define __MCF_NOEXCEPT __MCF_CXX(throw()) #define __MCF_0_INIT { __MCF_C(0) } #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * 8U) +#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) #ifndef __MCF_DECLSPEC_FWD_IMPORT # define __MCF_DECLSPEC_FWD_IMPORT diff --git a/src/thread.h b/src/thread.h index 2c6d8ea4ca..dc4158734f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -35,7 +35,7 @@ struct __MCF_thread /* `__data_ptr` shall always point to `__data_storage` below. The space * preceding it is reserved for future use. It is not safe to assume the * offset of `__data_storage` to be a constant. */ - __extension__ char __data_storage[0] __attribute__((__aligned__(16))); + __extension__ char __data_storage[0] __MCF_ALIGN(16); }; /* Creates a thread. The `__nref` member is initialized to 2, because a running From b35b10634d509ea2cbbc9ae034f3019052a3232f Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 6 Oct 2022 21:51:51 +0800 Subject: [PATCH 007/133] xglobals: Remove a `__builtin_expect` (cherry picked from commit 406e086d75b2acb6534d57446864c426bdb27a78) Signed-off-by: LIU Hao --- src/xglobals.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xglobals.c b/src/xglobals.c index 33da76568b..4cb6df07c6 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -232,7 +232,7 @@ __stdcall __MCF_dll_startup(PVOID instance, DWORD reason, PVOID reserved) { /* Prevent this DLL from being unloaded. */ - if(__builtin_expect((long) reason, 3) == DLL_PROCESS_ATTACH) + if(reason == DLL_PROCESS_ATTACH) __MCF_CHECK(NT_SUCCESS(LdrAddRefDll(1, instance))); /* Call the common routine. This will not fail. */ From b4e047c0c99a96ad5ffb962e3e5d36c5ed484aee Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 6 Oct 2022 21:59:04 +0800 Subject: [PATCH 008/133] xglobals: Add `__MCF_CHECK_NT` (cherry picked from commit aa17f2ef4596c3c8c59ba05926b4a208393151ae) Signed-off-by: LIU Hao --- src/xglobals.c | 7 ++----- src/xglobals.i | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/xglobals.c b/src/xglobals.c index 4cb6df07c6..cdd9513ae4 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -171,10 +171,7 @@ do_on_process_attach(void) /* Attach the main thread. */ __MCF_main_thread.__tid = _MCF_thread_self_tid(); - __MCF_CHECK(NT_SUCCESS(NtDuplicateObject(GetCurrentProcess(), - GetCurrentThread(), GetCurrentProcess(), &(__MCF_main_thread.__handle), - 0, 0, DUPLICATE_SAME_ACCESS))); - + __MCF_CHECK_NT(NtDuplicateObject(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &(__MCF_main_thread.__handle), 0, 0, DUPLICATE_SAME_ACCESS)); __MCF_CHECK(__MCF_main_thread.__handle); _MCF_atomic_store_32_rel(__MCF_main_thread.__nref, 1); __MCF_CHECK(TlsSetValue(__MCF_win32_tls_index, &__MCF_main_thread)); @@ -233,7 +230,7 @@ __MCF_dll_startup(PVOID instance, DWORD reason, PVOID reserved) { /* Prevent this DLL from being unloaded. */ if(reason == DLL_PROCESS_ATTACH) - __MCF_CHECK(NT_SUCCESS(LdrAddRefDll(1, instance))); + __MCF_CHECK_NT(LdrAddRefDll(1, instance)); /* Call the common routine. This will not fail. */ do_image_tls_callback(instance, reason, reserved); diff --git a/src/xglobals.i b/src/xglobals.i index 7c5e778da8..64f7c3359e 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -62,6 +62,9 @@ extern BYTE __MCF_mutex_spin_field[2048]; RETURN __stdcall function(__VA_ARGS__) \ __attribute__((__dllimport__, __nothrow__)) +#define __MCF_CHECK_NT(...) \ + __MCF_CHECK(NT_SUCCESS(__VA_ARGS__)) + /* Declare KERNEL32 APIs here. */ __MCF_WINAPI(DWORD, GetLastError, void) __attribute__((__pure__)); __MCF_WINAPI(void, SetLastError, DWORD); From cc54da0373ad071bad5765779e4f4bce6dc9c821 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 7 Oct 2022 03:18:17 +0800 Subject: [PATCH 009/133] thread,gthr_aux,gthr,c11: Declare fields that are always passed via pointers as arrays instead --- src/c11.h | 33 ++++++++++++++-------------- src/cxa.c | 4 ++-- src/gthr.h | 6 ++--- src/gthr_aux.c | 10 ++++----- src/gthr_aux.h | 25 +++++++++++---------- src/thread.h | 8 +++---- src/xglobals.c | 6 ++--- test/c11_cnd_consumers.c | 12 +++++----- test/c11_cnd_consumers_recursive.c | 18 +++++++-------- test/c11_mtx_nonrecursive.c | 4 ++-- test/c11_mtx_timeout.c | 2 +- test/gthr_cond_consumers_recursive.c | 12 +++++----- 12 files changed, 70 insertions(+), 70 deletions(-) diff --git a/src/c11.h b/src/c11.h index 4c9055416f..1a7fd42176 100644 --- a/src/c11.h +++ b/src/c11.h @@ -34,9 +34,7 @@ typedef int __MCF_c11_thread_procedure(void* __arg); struct __MCF_c11_mutex { uint8_t __type; /* bit mask of `__MCF_mtx_type` */ - uint8_t __reserved_1; - uint16_t __reserved_2; - __MCF_gthr_rc_mutex __rc_mtx; + __MCF_gthr_rc_mutex __rc_mtx[1]; }; struct __MCF_c11_thread_record @@ -44,8 +42,9 @@ struct __MCF_c11_thread_record int __result; __MCF_c11_thread_procedure* __proc; void* __arg; - uint8_t __joinable; - intptr_t __reserved[2]; + uint8_t __joinable[1]; + uintptr_t __reserved_low; + uintptr_t __reserved_high; }; typedef __MCF_c11_thread_procedure* thrd_start_t; @@ -316,7 +315,7 @@ int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__ts); - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) &(__mtx->__rc_mtx), &__timeout); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -324,7 +323,7 @@ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT { - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) &(__mtx->__rc_mtx), NULL); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -351,7 +350,7 @@ __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT case mtx_timed | mtx_recursive: /* Initialize an unowned mutex. */ __mtx->__type = (uint8_t) __type; - __MCF_gthr_rc_mutex_init(&(__mtx->__rc_mtx)); + __MCF_gthr_rc_mutex_init(__mtx->__rc_mtx); return thrd_success; } } @@ -361,14 +360,14 @@ int __MCF_c11_mtx_check_recursion(mtx_t* __mtx) __MCF_NOEXCEPT { /* Check for recursion. */ - int __err = __MCF_gthr_rc_mutex_recurse(&(__mtx->__rc_mtx)); + int __err = __MCF_gthr_rc_mutex_recurse(__mtx->__rc_mtx); if(__err != 0) return thrd_busy; /* If recursion has happened but the mutex is not recursive, undo the * operation, and fail. */ if(!(__mtx->__type & mtx_recursive)) { - __mtx->__rc_mtx.__depth --; + __mtx->__rc_mtx[0].__depth --; return thrd_error; } @@ -384,7 +383,7 @@ __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT if(__err != thrd_busy) return __err; - __err = __MCF_gthr_rc_mutex_wait(&(__mtx->__rc_mtx), NULL); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -404,7 +403,7 @@ __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEP return __err; __timeout = __MCF_gthr_timeout_from_timespec(__ts); - __err = __MCF_gthr_rc_mutex_wait(&(__mtx->__rc_mtx), &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -420,7 +419,7 @@ __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT return __err; __timeout = 0; - __err = __MCF_gthr_rc_mutex_wait(&(__mtx->__rc_mtx), &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_busy : thrd_success; } @@ -428,7 +427,7 @@ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_release(&(__mtx->__rc_mtx)); + __MCF_gthr_rc_mutex_release(__mtx->__rc_mtx); return 0; } @@ -441,7 +440,7 @@ __MCF_c11_thrd_create(thrd_t* __thrdp, thrd_start_t __proc, void* __arg) __MCF_N __rec->__proc = __proc; __rec->__arg = __arg; - __rec->__joinable = true; + __rec->__joinable[0] = 1; __thrd = _MCF_thread_new(__MCF_c11_thread_thunk_v2, __rec, sizeof(*__rec)); *__thrdp = __thrd; @@ -470,7 +469,7 @@ __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT /* Fail if the thread has already been detached. */ __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__thrd); - if(_MCF_atomic_xchg_8_rlx(&(__rec->__joinable), 0) == 0) + if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return thrd_error; /* Free the thread. */ @@ -519,7 +518,7 @@ __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT /* Fail if the thread has already been detached. */ __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__thrd); - if(_MCF_atomic_xchg_8_rlx(&(__rec->__joinable), 0) == 0) + if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return thrd_error; /* Wait for it. */ diff --git a/src/cxa.c b/src/cxa.c index 3f282b1c8d..c52ae1cca9 100644 --- a/src/cxa.c +++ b/src/cxa.c @@ -84,7 +84,7 @@ __MCF_cxa_thread_atexit(__MCF_cxa_dtor_union dtor, void* this, void* dso) /* Push the element to the thread-specific queue. */ __MCF_dtor_element elem = { dtor.__cdecl_ptr, this, dso }; - int err = __MCF_dtor_queue_push(&(self->__atexit_queue), &elem); + int err = __MCF_dtor_queue_push(self->__atexit_queue, &elem); return err; } @@ -112,7 +112,7 @@ __MCF_cxa_finalize(void* dso) * accordance with the C++ standard. See [basic.start.term]/2. */ _MCF_thread* self = _MCF_thread_self(); if(self) - __MCF_dtor_queue_finalize(&(self->__atexit_queue), NULL, dso); + __MCF_dtor_queue_finalize(self->__atexit_queue, NULL, dso); /* Call destructors and callbacks registered with `__cxa_atexit()`. */ __MCF_dtor_queue_finalize(&__MCF_cxa_atexit_queue, &__MCF_cxa_atexit_mutex, dso); diff --git a/src/gthr.h b/src/gthr.h index e479e6f1ff..8773180a3d 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -522,7 +522,7 @@ __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, __rec->__proc = __proc; __rec->__arg = __arg; - __rec->__joinable = 1; + __rec->__joinable[0] = 1; __thrd = _MCF_thread_new(__MCF_gthr_thread_thunk_v2, __rec, sizeof(*__rec)); *__thrdp = __thrd; @@ -543,7 +543,7 @@ __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT /* Fail if the thread has already been detached. */ __rec = (__MCF_gthr_thread_record*) _MCF_thread_get_data(__thrd); - if(_MCF_atomic_xchg_8_rlx(&(__rec->__joinable), 0) == 0) + if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return -1; /* Wait for it. */ @@ -574,7 +574,7 @@ __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT /* Fail if the thread has already been detached. */ __rec = (__MCF_gthr_thread_record*) _MCF_thread_get_data(__thrd); - if(_MCF_atomic_xchg_8_rlx(&(__rec->__joinable), 0) == 0) + if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return -1; /* Free the thread. */ diff --git a/src/gthr_aux.c b/src/gthr_aux.c index 5b7bc13d54..433ae11646 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -52,8 +52,8 @@ __MCF_gthr_recursive_mutex_unlock_callback(intptr_t arg) /* Clear the depth counter and return it. */ intptr_t unlocked = rmtx->__depth; rmtx->__depth = 0; - _MCF_atomic_store_32_rlx(&(rmtx->__owner), 0); - _MCF_mutex_unlock(&(rmtx->__mutex)); + _MCF_atomic_store_32_rlx(rmtx->__owner, 0); + _MCF_mutex_unlock(rmtx->__mutex); __MCF_ASSERT(unlocked > 0); return unlocked; @@ -67,9 +67,9 @@ __MCF_gthr_recursive_mutex_relock_callback(intptr_t arg, intptr_t unlocked) __MCF_gthr_rc_mutex* rmtx = (__MCF_gthr_rc_mutex*) arg; /* Relock the mutex and restore the depth counter. */ - _MCF_mutex_lock(&(rmtx->__mutex), NULL); - __MCF_ASSERT(rmtx->__owner == 0); - _MCF_atomic_store_32_rlx(&(rmtx->__owner), (int32_t) _MCF_thread_self_tid()); + _MCF_mutex_lock(rmtx->__mutex, NULL); + __MCF_ASSERT(rmtx->__owner[0] == 0); + _MCF_atomic_store_32_rlx(rmtx->__owner, (int32_t) _MCF_thread_self_tid()); rmtx->__depth = (int32_t) unlocked; } diff --git a/src/gthr_aux.h b/src/gthr_aux.h index a5972899c3..7dfbed17cc 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -35,9 +35,9 @@ typedef void* __MCF_gthr_thread_procedure(void* __arg); struct __MCF_gthr_rc_mutex { - uint32_t __owner; /* owner thread ID */ + uint32_t __owner[1]; /* owner thread ID */ int __depth; /* recursion depth */ - _MCF_mutex __mutex; + _MCF_mutex __mutex[1]; }; struct __MCF_gthr_thread_record @@ -45,8 +45,9 @@ struct __MCF_gthr_thread_record void* __result; __MCF_gthr_thread_procedure* __proc; void* __arg; - uint8_t __joinable; - intptr_t __reserved[2]; + uint8_t __joinable[1]; + uintptr_t __reserved_low; + uintptr_t __reserved_high; }; /* This is an auxiliary function for exception handling in `__gthread_once()`. @@ -105,9 +106,9 @@ __MCF_ALWAYS_INLINE void __MCF_gthr_rc_mutex_init(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT { - __rmtx->__owner = 0; + __rmtx->__owner[0] = 0; __rmtx->__depth = 0; - _MCF_mutex_init(&(__rmtx->__mutex)); + _MCF_mutex_init(__rmtx->__mutex); } __MCF_ALWAYS_INLINE @@ -115,7 +116,7 @@ int __MCF_gthr_rc_mutex_recurse(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT { /* Check whether the mutex has already been owned. */ - if(_MCF_atomic_load_32_rlx(&(__rmtx->__owner)) != (int32_t) _MCF_thread_self_tid()) + if(_MCF_atomic_load_32_rlx(__rmtx->__owner) != (int32_t) _MCF_thread_self_tid()) return -1; /* Increment the recursion count. */ @@ -129,13 +130,13 @@ int __MCF_gthr_rc_mutex_wait(__MCF_gthr_rc_mutex* __rmtx, const int64_t* __timeout_opt) __MCF_NOEXCEPT { /* Attempt to take ownership. */ - int __err = _MCF_mutex_lock(&(__rmtx->__mutex), __timeout_opt); + int __err = _MCF_mutex_lock(__rmtx->__mutex, __timeout_opt); if(__err != 0) return __err; /* The calling thread owns the mutex now. */ - __MCF_ASSERT(__rmtx->__owner == 0); - _MCF_atomic_store_32_rlx(&(__rmtx->__owner), (int32_t) _MCF_thread_self_tid()); + __MCF_ASSERT(__rmtx->__owner[0] == 0); + _MCF_atomic_store_32_rlx(__rmtx->__owner, (int32_t) _MCF_thread_self_tid()); __MCF_ASSERT(__rmtx->__depth == 0); __rmtx->__depth = 1; return 0; @@ -152,8 +153,8 @@ __MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT return; /* Give up ownership now. */ - _MCF_atomic_store_32_rlx(&(__rmtx->__owner), 0); - _MCF_mutex_unlock(&(__rmtx->__mutex)); + _MCF_atomic_store_32_rlx(__rmtx->__owner, 0); + _MCF_mutex_unlock(__rmtx->__mutex); } #ifdef __cplusplus diff --git a/src/thread.h b/src/thread.h index dc4158734f..9b20f45d08 100644 --- a/src/thread.h +++ b/src/thread.h @@ -29,8 +29,8 @@ struct __MCF_thread _MCF_thread_procedure* __proc; /* user-defined thread procedure */ void* __data_ptr; /* pointer to user-defined data. */ - __MCF_dtor_queue __atexit_queue; /* for `__cxa_thread_atexit()` */ - __MCF_tls_table __tls_table; /* for `_MCF_tls_get()` and `_MCF_tls_set()` */ + __MCF_dtor_queue __atexit_queue[1]; /* for `__cxa_thread_atexit()` */ + __MCF_tls_table __tls_table[1]; /* for `_MCF_tls_get()` and `_MCF_tls_set()` */ /* `__data_ptr` shall always point to `__data_storage` below. The space * preceding it is reserved for future use. It is not safe to assume the @@ -251,7 +251,7 @@ _MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT { _MCF_thread* __self = _MCF_thread_self(); return (__self == NULL) ? NULL - : __MCF_tls_table_get(&(__self->__tls_table), __key); + : __MCF_tls_table_get(__self->__tls_table, __key); } __MCF_DECLSPEC_THREAD_INLINE @@ -260,7 +260,7 @@ _MCF_tls_set(_MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT { _MCF_thread* __self = _MCF_thread_self(); return (__self == NULL) ? -1 - : __MCF_tls_table_set(&(__self->__tls_table), __key, __value_opt); + : __MCF_tls_table_set(__self->__tls_table, __key, __value_opt); } #ifdef __cplusplus diff --git a/src/xglobals.c b/src/xglobals.c index cdd9513ae4..c4886fefff 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -136,7 +136,7 @@ __MCF_finalize_on_exit(void) /* Call destructors for thread-local objects before static ones, in * accordance with the C++ standard. See [basic.start.term]/2. * Thread-local destructors are not called according to POSIX. */ - __MCF_dtor_queue_finalize(&(self->__atexit_queue), NULL, NULL); + __MCF_dtor_queue_finalize(self->__atexit_queue, NULL, NULL); __MCF_run_dtors_atexit(); TlsSetValue(__MCF_win32_tls_index, NULL); @@ -188,8 +188,8 @@ do_on_thread_detach(void) /* Per-thread atexit callbacks may use TLS, so call them before * destructors of thread-local objects. */ - __MCF_dtor_queue_finalize(&(self->__atexit_queue), NULL, NULL); - __MCF_tls_table_finalize(&(self->__tls_table)); + __MCF_dtor_queue_finalize(self->__atexit_queue, NULL, NULL); + __MCF_tls_table_finalize(self->__tls_table); TlsSetValue(__MCF_win32_tls_index, NULL); _MCF_thread_drop_ref_nonnull(self); diff --git a/test/c11_cnd_consumers.c b/test/c11_cnd_consumers.c index e6c0028a84..a952c77c65 100644 --- a/test/c11_cnd_consumers.c +++ b/test/c11_cnd_consumers.c @@ -29,8 +29,8 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx.__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Consume it */ @@ -82,8 +82,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx.__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Produce one */ @@ -97,8 +97,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx.__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Inform end of input */ diff --git a/test/c11_cnd_consumers_recursive.c b/test/c11_cnd_consumers_recursive.c index e68ef0a005..d044f56fcf 100644 --- a/test/c11_cnd_consumers_recursive.c +++ b/test/c11_cnd_consumers_recursive.c @@ -33,9 +33,9 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__mutex.__locked); - assert(mutex.__rc_mtx.__depth == 3); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Consume it */ @@ -95,9 +95,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__mutex.__locked); - assert(mutex.__rc_mtx.__depth == 3); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Produce one */ @@ -111,9 +111,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx.__mutex.__locked); - assert(mutex.__rc_mtx.__depth == 3); - assert(mutex.__rc_mtx.__owner == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Inform end of input */ diff --git a/test/c11_mtx_nonrecursive.c b/test/c11_mtx_nonrecursive.c index 489e9114a1..3265540e48 100644 --- a/test/c11_mtx_nonrecursive.c +++ b/test/c11_mtx_nonrecursive.c @@ -20,11 +20,11 @@ main(void) r = mtx_trylock(&mutex); assert(r == thrd_success); - mutex.__rc_mtx.__owner = 42; /* don't expose the deadlock */ + mutex.__rc_mtx[0].__owner[0] = 42; /* don't expose the deadlock */ r = mtx_trylock(&mutex); assert(r == thrd_busy); - mutex.__rc_mtx.__owner = _MCF_thread_self_tid(); + mutex.__rc_mtx[0].__owner[0] = _MCF_thread_self_tid(); r = mtx_unlock(&mutex); assert(r == thrd_success); diff --git a/test/c11_mtx_timeout.c b/test/c11_mtx_timeout.c index e6274a78fb..2be1ae084b 100644 --- a/test/c11_mtx_timeout.c +++ b/test/c11_mtx_timeout.c @@ -35,7 +35,7 @@ main(void) now = _MCF_perf_counter(); timeout.tv_sec = time(NULL) + 1; timeout.tv_nsec = 100000000; - mutex.__rc_mtx.__owner = 42; + mutex.__rc_mtx[0].__owner[0] = 42; r = mtx_timedlock(&mutex, &timeout); assert(r == thrd_timedout); delta = _MCF_perf_counter() - now; diff --git a/test/gthr_cond_consumers_recursive.c b/test/gthr_cond_consumers_recursive.c index bf8b86142f..e4f46a814e 100644 --- a/test/gthr_cond_consumers_recursive.c +++ b/test/gthr_cond_consumers_recursive.c @@ -33,9 +33,9 @@ thread_proc(void* param) while(value == 0) { err = __gthread_cond_wait_recursive(&cond_produced, &mutex); assert(err == 0); - assert(mutex.__mutex.__locked); + assert(mutex.__mutex[0].__locked); assert(mutex.__depth == 3); - assert(mutex.__owner == _MCF_thread_self_tid()); + assert(mutex.__owner[0] == _MCF_thread_self_tid()); } /* Consume it */ @@ -88,9 +88,9 @@ main(void) while(value != 0) { err = __gthread_cond_wait_recursive(&cond_consumed, &mutex); assert(err == 0); - assert(mutex.__mutex.__locked); + assert(mutex.__mutex[0].__locked); assert(mutex.__depth == 3); - assert(mutex.__owner == _MCF_thread_self_tid()); + assert(mutex.__owner[0] == _MCF_thread_self_tid()); } /* Produce one */ @@ -104,9 +104,9 @@ main(void) while(value != 0) { err = __gthread_cond_wait_recursive(&cond_consumed, &mutex); assert(err == 0); - assert(mutex.__mutex.__locked); + assert(mutex.__mutex[0].__locked); assert(mutex.__depth == 3); - assert(mutex.__owner == _MCF_thread_self_tid()); + assert(mutex.__owner[0] == _MCF_thread_self_tid()); } /* Inform end of input */ From ac28b688659ae27d5113c627f078c8def6e69487 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 7 Oct 2022 03:50:41 +0800 Subject: [PATCH 010/133] c11,gthr: Ensure reserved fields are initialized to zeroes (cherry picked from commit 8e4f95be96ef49c80764f2f48f762ef3b31696de) Signed-off-by: LIU Hao --- src/c11.h | 2 +- src/gthr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c11.h b/src/c11.h index 1a7fd42176..b7200912b7 100644 --- a/src/c11.h +++ b/src/c11.h @@ -435,7 +435,7 @@ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrdp, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT { - __MCF_c11_thread_record __rec[1]; + __MCF_c11_thread_record __rec[1] = __MCF_0_INIT; _MCF_thread* __thrd; __rec->__proc = __proc; diff --git a/src/gthr.h b/src/gthr.h index 8773180a3d..844932bec3 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -517,7 +517,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT { - __MCF_gthr_thread_record __rec[1]; + __MCF_gthr_thread_record __rec[1] = __MCF_0_INIT; _MCF_thread* __thrd; __rec->__proc = __proc; From aa4f0321404e7b5b37cbe04e04805d04ec2105a6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 7 Oct 2022 04:07:08 +0800 Subject: [PATCH 011/133] xglobals: Perform initialization before the CRT in case of static linking (cherry picked from commit 5f1296959778dace6a9ab733a71affac3a6edda1) Signed-off-by: LIU Hao --- src/xglobals.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/xglobals.c b/src/xglobals.c index c4886fefff..eabb03c74f 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -241,10 +241,10 @@ __MCF_dll_startup(PVOID instance, DWORD reason, PVOID reserved) /* When building the static library, invoke the common routine from a TLS * callback. This requires the main executable be linked with 'tlssup.o'. - * `__xl_d` is being used by mingw-w64, so we use `__xl_e` here. */ -extern const PIMAGE_TLS_CALLBACK __MCF_xl_e; + * Such initialization should happen as early as possible. */ +extern const PIMAGE_TLS_CALLBACK __MCF_xl_b; -const PIMAGE_TLS_CALLBACK __MCF_xl_e - __attribute__((__section__(".CRT$XLE"), __used__)) = do_image_tls_callback; +const PIMAGE_TLS_CALLBACK __MCF_xl_b + __attribute__((__section__(".CRT$XLB"), __used__)) = do_image_tls_callback; #endif /* DLL_EXPORT */ From 4c54f3d10b6d48720ff620882b6087e302aa9b7b Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 7 Oct 2022 23:31:44 +0800 Subject: [PATCH 012/133] cxa: Remove expiring quick-exit callbacks after normal exit callbacks Because, in theory, it is possible to register quick-exit callbacks with the latter. (cherry picked from commit d6321dd95e0f7b4bf348b089ae54f13b948e01e1) Signed-off-by: LIU Hao --- src/cxa.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cxa.c b/src/cxa.c index c52ae1cca9..99c0a86bc7 100644 --- a/src/cxa.c +++ b/src/cxa.c @@ -103,11 +103,6 @@ __MCF_cxa_finalize(void* dso) if(!dso) return __MCF_finalize_on_exit(); - /* Remove quick exit callbacks that will expire. */ - _MCF_mutex_lock(&__MCF_cxa_at_quick_exit_mutex, NULL); - __MCF_dtor_queue_remove(&__MCF_cxa_at_quick_exit_queue, dso); - _MCF_mutex_unlock(&__MCF_cxa_at_quick_exit_mutex); - /* Call destructors for thread-local objects before static ones in * accordance with the C++ standard. See [basic.start.term]/2. */ _MCF_thread* self = _MCF_thread_self(); @@ -116,4 +111,9 @@ __MCF_cxa_finalize(void* dso) /* Call destructors and callbacks registered with `__cxa_atexit()`. */ __MCF_dtor_queue_finalize(&__MCF_cxa_atexit_queue, &__MCF_cxa_atexit_mutex, dso); + + /* Remove quick exit callbacks that will expire. */ + _MCF_mutex_lock(&__MCF_cxa_at_quick_exit_mutex, NULL); + __MCF_dtor_queue_remove(&__MCF_cxa_at_quick_exit_queue, dso); + _MCF_mutex_unlock(&__MCF_cxa_at_quick_exit_mutex); } From 0f28f9722a2970e34f3eabea77b114341c5f5454 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 8 Oct 2022 00:05:47 +0800 Subject: [PATCH 013/133] thread: Update comments about `long double` (cherry picked from commit 0f2fef07b40e24a611d60274ead2bfbe15f585f2) Signed-off-by: LIU Hao --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 76177c18a0..0d647ec9e3 100644 --- a/src/thread.c +++ b/src/thread.c @@ -19,7 +19,7 @@ do_win32_thread_thunk(LPVOID param) _MCF_thread* self = param; #if defined(__i386__) || defined(__amd64__) - /* Set x87 precision to 80 bits. */ + /* Set x87 precision to 64-bit mantissa (GNU `long double` format). */ __asm__ volatile ("fninit"); #endif /* x86 */ From f781e3d7e5b920d8f4170a2037e76607e276b96a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 8 Oct 2022 02:19:25 +0800 Subject: [PATCH 014/133] once: Fix errors in comments --- src/once.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/once.h b/src/once.h index 1b73f4fcb9..896dd7b4d3 100644 --- a/src/once.h +++ b/src/once.h @@ -67,8 +67,8 @@ _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT; * the flag has not been locked already, the behavior is undefined. * * This function changes it into the UNLOCKED state and wakes up the next - * threads that is sleeping on this flag, whose calls to `_MCF_once_wait()` - * will return 1. */ + * thread that is sleeping on this flag, whose call to `_MCF_once_wait()` will + * return 1. */ __MCF_DECLSPEC_ONCE_IMPORT void _MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT; From c897492e14959bcbaa59a798e0350b54dda2cdd1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 8 Oct 2022 03:52:46 +0800 Subject: [PATCH 015/133] mutex: Use `YieldProcessor()` This is the same with `__builtin_ia32_pause()` on x86, but is also supported on ARM etc. (cherry picked from commit a2c669f919df3f49ec89a275eea12e5333fc4fdb) Signed-off-by: LIU Hao --- src/mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mutex.c b/src/mutex.c index 0d012cdeb6..9608416c79 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -83,7 +83,7 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) spin *= (int) (__MCF_MUTEX_MAX_SPIN_COUNT / __MCF_MUTEX_SP_NFAIL_THRESHOLD); while(--spin >= 0) { - __builtin_ia32_pause(); + YieldProcessor(); /* Wait for my turn. */ uint8_t cmp = 1; From df68bf6cef8dcaf13db6092bcec2009a0d0f1eeb Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 8 Oct 2022 15:46:00 +0800 Subject: [PATCH 016/133] mutex: Add a branch hint for the spin count (cherry picked from commit 9ea79009c60142a59a0be3f4ebab2611a9ba0a7a) Signed-off-by: LIU Hao --- src/mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mutex.c b/src/mutex.c index 9608416c79..7af32ef418 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -82,7 +82,8 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) __MCF_ASSERT(spin > 0); spin *= (int) (__MCF_MUTEX_MAX_SPIN_COUNT / __MCF_MUTEX_SP_NFAIL_THRESHOLD); - while(--spin >= 0) { + while(__builtin_expect(spin, 100) > 0) { + spin --; YieldProcessor(); /* Wait for my turn. */ From c79a4b4a6b5703ad53574f2707b15f2af2b23c81 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 9 Oct 2022 15:17:57 +0800 Subject: [PATCH 017/133] xglobals: Normalize declarations of Windows APIs Signed-off-by: LIU Hao --- src/xglobals.c | 2 +- src/xglobals.i | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/xglobals.c b/src/xglobals.c index eabb03c74f..a797defe27 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -14,7 +14,7 @@ __MCF_DLLEXPORT EXCEPTION_DISPOSITION __cdecl -__MCF_seh_top(EXCEPTION_RECORD* rec, void* estab_frame, CONTEXT* ctx, void* disp_ctx) +__MCF_seh_top(EXCEPTION_RECORD* rec, PVOID estab_frame, CONTEXT* ctx, PVOID disp_ctx) { (void) estab_frame; (void) ctx; diff --git a/src/xglobals.i b/src/xglobals.i index 64f7c3359e..b95c283fdc 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -80,15 +80,16 @@ __MCF_WINAPI(LPVOID, HeapReAlloc, HANDLE, DWORD, LPVOID, SIZE_T) __attribute__(( __MCF_WINAPI(SIZE_T, HeapSize, HANDLE, DWORD, LPCVOID) __attribute__((__pure__)); __MCF_WINAPI(BOOL, HeapFree, HANDLE, DWORD, LPVOID); -__MCF_WINAPI(void, GetSystemTimeAsFileTime, LPFILETIME); +__MCF_WINAPI(void, GetSystemTimeAsFileTime, FILETIME*); #if _WIN32_WINNT >= 0x0602 -__MCF_WINAPI(void, GetSystemTimePreciseAsFileTime, LPFILETIME); +__MCF_WINAPI(void, GetSystemTimePreciseAsFileTime, FILETIME*); #endif __MCF_WINAPI(ULONGLONG, GetTickCount64, void); __MCF_WINAPI(BOOL, QueryPerformanceFrequency, LARGE_INTEGER*); __MCF_WINAPI(BOOL, QueryPerformanceCounter, LARGE_INTEGER*); -__MCF_WINAPI(HANDLE, CreateThread, LPSECURITY_ATTRIBUTES, SIZE_T, LPTHREAD_START_ROUTINE, LPVOID, DWORD, LPDWORD); +typedef DWORD __stdcall THREAD_START_ROUTINE(LPVOID); +__MCF_WINAPI(HANDLE, CreateThread, SECURITY_ATTRIBUTES*, SIZE_T, THREAD_START_ROUTINE*, LPVOID, DWORD, DWORD*); __MCF_WINAPI(void, ExitThread, DWORD) __attribute__((__noreturn__)); __MCF_WINAPI(BOOL, SwitchToThread, void); __MCF_WINAPI(BOOL, TerminateProcess, HANDLE, UINT); @@ -105,17 +106,18 @@ __MCF_WINAPI(void, RtlFillMemory, void*, SIZE_T, int); __MCF_WINAPI(void, RtlZeroMemory, void*, SIZE_T); __MCF_WINAPI(SIZE_T, RtlCompareMemory, const void*, const void*, SIZE_T) __attribute__((__pure__)); -__MCF_WINAPI(NTSTATUS, NtDuplicateObject, HANDLE, HANDLE, HANDLE, PHANDLE, ACCESS_MASK, ULONG, ULONG); +__MCF_WINAPI(NTSTATUS, NtDuplicateObject, HANDLE, HANDLE, HANDLE, HANDLE*, ACCESS_MASK, ULONG, ULONG); __MCF_WINAPI(NTSTATUS, NtClose, HANDLE); -__MCF_WINAPI(NTSTATUS, NtWaitForSingleObject, HANDLE, BOOLEAN, PLARGE_INTEGER); -__MCF_WINAPI(NTSTATUS, NtWaitForKeyedEvent, HANDLE, PVOID, BOOLEAN, PLARGE_INTEGER); -__MCF_WINAPI(NTSTATUS, NtReleaseKeyedEvent, HANDLE, PVOID, BOOLEAN, PLARGE_INTEGER); +__MCF_WINAPI(NTSTATUS, NtWaitForSingleObject, HANDLE, BOOLEAN, LARGE_INTEGER*); + +__MCF_WINAPI(NTSTATUS, NtWaitForKeyedEvent, HANDLE, PVOID, BOOLEAN, LARGE_INTEGER*); +__MCF_WINAPI(NTSTATUS, NtReleaseKeyedEvent, HANDLE, PVOID, BOOLEAN, LARGE_INTEGER*); /* Declare helper functions here. */ __MCF_DECLSPEC_XGLOBALS_IMPORT EXCEPTION_DISPOSITION __cdecl -__MCF_seh_top(EXCEPTION_RECORD* __rec, void* __estab_frame, CONTEXT* __ctx, void* __disp_ctx) __MCF_NOEXCEPT; +__MCF_seh_top(EXCEPTION_RECORD* __rec, PVOID __estab_frame, CONTEXT* __ctx, PVOID __disp_ctx) __MCF_NOEXCEPT; #if defined(__i386__) @@ -295,7 +297,7 @@ __MCF_ALWAYS_INLINE NTSTATUS __MCF_keyed_event_wait(const void* __key, const LARGE_INTEGER* __timeout) __MCF_NOEXCEPT { - NTSTATUS __status = NtWaitForKeyedEvent(NULL, (PVOID) __key, 0, (PLARGE_INTEGER) __timeout); + NTSTATUS __status = NtWaitForKeyedEvent(NULL, (PVOID) __key, 0, (LARGE_INTEGER*) __timeout); __MCF_ASSERT(NT_SUCCESS(__status)); return __status; } @@ -304,7 +306,7 @@ __MCF_ALWAYS_INLINE NTSTATUS __MCF_keyed_event_signal(const void* __key, const LARGE_INTEGER* __timeout) __MCF_NOEXCEPT { - NTSTATUS __status = NtReleaseKeyedEvent(NULL, (PVOID) __key, 0, (PLARGE_INTEGER) __timeout); + NTSTATUS __status = NtReleaseKeyedEvent(NULL, (PVOID) __key, 0, (LARGE_INTEGER*) __timeout); __MCF_ASSERT(NT_SUCCESS(__status)); return __status; } From 9bb611e8d08f389af780f79820ca443ad32cea5c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 9 Oct 2022 23:18:36 +0800 Subject: [PATCH 018/133] xglobals: Complement inline asm (cherry picked from commit fa6ff0e688d2a912caf3a771fbf5460d2c1c323e) Signed-off-by: LIU Hao --- src/xglobals.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index b95c283fdc..1368b5c465 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -445,7 +445,7 @@ __MCF_mcomp(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT /* AT&T Barking | Genuine Intel */ __MCF_PPSTR( { xorl %%eax, %%eax; | xor eax, eax; } - repz cmpsb; + { repz cmpsb; | repz cmpsb; } { setnzb %%al; | setnz al; } { sbbl %%ecx, %%ecx; | sbb ecx, ecx; } ) @@ -484,7 +484,7 @@ __MCF_mequal(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT /* AT&T Barking | Genuine Intel */ __MCF_PPSTR( { xorl %%eax, %%eax; | xor eax, eax; } - repz cmpsb; + { repz cmpsb; | repz cmpsb; } ) : "=@ccz"(__result), "+S"(__si), "+D"(__di), "+c"(__cx) : "m"(*(const __bytes*) __src), "m"(*(const __bytes*) __cmp) From cfd68c8df854191cabdd172598b5032a1ab3163f Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 11 Oct 2022 09:24:44 +0800 Subject: [PATCH 019/133] build: Bump ABI suffix Signed-off-by: LIU Hao --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 5716288c75..d15d717a64 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) ## Define ABI information AS_VAR_SET([abi_major], [1]) AS_VAR_SET([abi_minor], [2]) -AS_VAR_SET([abi_suffix], [beta.1]) +AS_VAR_SET([abi_suffix], [ga.1]) ## Check for assertions AC_ARG_ENABLE([debug-checks], AS_HELP_STRING([--enable-debug-checks], [enable assertions])) From b8f05f84ce30b52360f60e0ddbb1f434df9beec6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 12 Oct 2022 23:16:37 +0800 Subject: [PATCH 020/133] xglobals: Remove `__MCF_mmove()` as it's unused The overlapping case is handled explicitly in `memmove()` instead. Removal of this function saves a few bytes in the DLL. (cherry picked from commit 3b5b66183e1b929b1d178d7950c9c8e430d83ccb) Signed-off-by: LIU Hao --- src/memmove.c | 10 ++++++++-- src/xglobals.i | 16 ---------------- test/memory.c | 21 +++------------------ 3 files changed, 11 insertions(+), 36 deletions(-) diff --git a/src/memmove.c b/src/memmove.c index 6ce9780928..a9885f829c 100644 --- a/src/memmove.c +++ b/src/memmove.c @@ -6,7 +6,11 @@ void* __cdecl -__MCF_mmove(void* dst, const void* src, size_t size); +__MCF_mcopy(void* dst, const void* src, size_t size); + +void* +__cdecl +__MCF_mcopy_backward(void* dst, const void* src, size_t size); __MCF_DLLEXPORT void* @@ -18,5 +22,7 @@ void* __cdecl memmove(void* dst, const void* src, size_t size) { - return __MCF_mmove(dst, src, size); + return ((uintptr_t) dst - (uintptr_t) src >= size) + ? __MCF_mcopy(dst, src, size) + : __MCF_mcopy_backward(dst, src, size); } diff --git a/src/xglobals.i b/src/xglobals.i index 1368b5c465..be6087d253 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -200,12 +200,6 @@ void* __cdecl __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT; -/* Copy a block of potentially overlapped memory, like `memmove()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE -void* -__cdecl -__MCF_mmove(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT; - /* Fill a block of memory with the given byte, like `memset()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE void* @@ -368,16 +362,6 @@ __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCE return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE -void* -__cdecl -__MCF_mmove(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT - { - return ((uintptr_t) __dst - (uintptr_t) __src >= __size) - ? __MCF_mcopy(__dst, __src, __size) - : __MCF_mcopy_backward(__dst, __src, __size); - } - __MCF_DECLSPEC_XGLOBALS_INLINE void* __cdecl diff --git a/test/memory.c b/test/memory.c index 06c18b8a98..9b06eb2f36 100644 --- a/test/memory.c +++ b/test/memory.c @@ -66,34 +66,19 @@ main(void) SystemFunction036(comp, sizeof(comp)); pmemmove(data, comp, sizeof(comp)); - pmemmove(comp + 10, comp + 80, 20); - ptr = __MCF_mmove(data + 10, data + 80, 20); - assert(ptr == data + 10); - - pmemmove(comp + 70, comp + 10, 30); - ptr = __MCF_mmove(data + 70, data + 10, 30); - assert(ptr == data + 70); - - assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); - - // __MCF_mmove (forward) - SystemFunction036(comp, sizeof(comp)); - pmemmove(data, comp, sizeof(comp)); - pmemmove(comp + 10, comp + 20, 40); - ptr = __MCF_mmove(data + 10, data + 20, 40); + ptr = __MCF_mcopy(data + 10, data + 20, 40); assert(ptr == data + 10); assert(pmemcmp(comp, data, sizeof(comp)) == 0); assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); - // __MCF_mmove (backward) + // __MCF_mcopy_backward SystemFunction036(comp, sizeof(comp)); pmemmove(data, comp, sizeof(comp)); pmemmove(comp + 20, comp + 10, 40); - ptr = __MCF_mmove(data + 20, data + 10, 40); + ptr = __MCF_mcopy_backward(data + 20, data + 10, 40); assert(ptr == data + 20); assert(pmemcmp(comp, data, sizeof(comp)) == 0); From 050dafdf72695d3a3fea3cc05323a86711022d86 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 13 Oct 2022 23:08:55 +0800 Subject: [PATCH 021/133] mutex: Perform strong CAS in the spin loop (cherry picked from commit b3a40f90d4e73d0de54a8acdc55a1fd8cbb493ae) Signed-off-by: LIU Hao --- src/mutex.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/mutex.c b/src/mutex.c index 7af32ef418..bf88ee6053 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -94,16 +94,20 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) /* If this mutex has not been locked, lock it and decrement the * failure counter. Otherwise, do nothing. */ _MCF_atomic_load_pptr_rlx(&old, mutex); - if(old.__locked != 0) - continue; + do { + if(old.__locked != 0) + break; - new = old; - new.__locked = 1; + new = old; + new.__locked = 1; - uint32_t temp = old.__sp_nfail - 1U; - new.__sp_nfail = (temp - temp / (__MCF_MUTEX_SP_NFAIL_M + 1U)) & __MCF_MUTEX_SP_NFAIL_M; + uint32_t temp = old.__sp_nfail - 1U; + new.__sp_nfail = (temp - temp / (__MCF_MUTEX_SP_NFAIL_M + 1U)) & __MCF_MUTEX_SP_NFAIL_M; + } + while(!_MCF_atomic_cmpxchg_weak_pptr_acq(mutex, &old, &new)); - if(_MCF_atomic_cmpxchg_pptr_acq(mutex, &old, &new)) + /* If this mutex has been locked by the current thread, succeed. */ + if(old.__locked == 0) return 0; } From 89931b050888e56b556a9a38ba714ef3935ccea5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 14 Oct 2022 17:25:14 +0800 Subject: [PATCH 022/133] mutex: Use consistent types (`uint8_t` <=> `BYTE`) (cherry picked from commit 779c2ccb1a1e3b5192615b3ab6cf5338e2025113) Signed-off-by: LIU Hao --- src/mutex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mutex.c b/src/mutex.c index bf88ee6053..438ed64dee 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -87,7 +87,7 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) YieldProcessor(); /* Wait for my turn. */ - uint8_t cmp = 1; + BYTE cmp = 1; if(!_MCF_atomic_cmpxchg_weak_8_rlx(do_spin_byte_ptr(mutex, my_mask), &cmp, 0)) continue; From 9f0ec972711c687ccc671a5688e4e03c9933f807 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 16 Oct 2022 22:21:44 +0800 Subject: [PATCH 023/133] mutex: Move an XOR out of the loop so it can be optimized (cherry picked from commit a9de81427507a3e416ce426faff18deabb4d3a91) Signed-off-by: LIU Hao --- src/mutex.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mutex.c b/src/mutex.c index 438ed64dee..75add00fc7 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -72,10 +72,9 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) if(old.__locked == 0) return 0; - if(old.__sp_mask != new.__sp_mask) { - /* The current thread shall spin now. */ - uint32_t my_mask = (uint32_t) new.__sp_mask ^ old.__sp_mask; - __MCF_ASSERT((my_mask & (my_mask - 1)) == 0); + uint32_t my_mask = (uint32_t) old.__sp_mask ^ new.__sp_mask; + if(my_mask != 0) { + __MCF_ASSERT((my_mask & (my_mask - 1U)) == 0); /* Calculate the spin count for this loop. */ register int spin = (int) (__MCF_MUTEX_SP_NFAIL_THRESHOLD - old.__sp_nfail); From 40f2c3f358b98898a9b8f8f35ec49a73c14518f6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 17 Oct 2022 14:26:52 +0800 Subject: [PATCH 024/133] ci: Use `make distcheck` (cherry picked from commit b45ba5ed3d453d6a0762a5ccd62d89fbe69f6512) Signed-off-by: LIU Hao --- ci/build.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ci/build.sh b/ci/build.sh index 432a280088..303228ed8f 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -29,10 +29,9 @@ autoreconf -ifv cd $(mktemp -d) trap 'rm -rf ~+ || true' EXIT ~-/configure --disable-silent-rules --enable-debug-checks --disable-static -make -j$(nproc) # test -if ! make -j$(nproc) check +if ! make -j$(nproc) distcheck then cat ./test-suite.log exit ${_fail} From 72ca7cf515857c3eaef85da69e44724e7ee87384 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 18 Oct 2022 22:28:42 +0800 Subject: [PATCH 025/133] fwd: Force `where` into memory (cherry picked from commit 8c9f551bab1958915af8916e13400e495b969adb) Signed-off-by: LIU Hao --- src/fwd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fwd.c b/src/fwd.c index f82587ff84..ac6d0643fd 100644 --- a/src/fwd.c +++ b/src/fwd.c @@ -10,10 +10,10 @@ __MCF_DLLEXPORT void -__MCF_runtime_failure(const char* __where) +__MCF_runtime_failure(const char* where) { - /* The argument can be examined with a debugger. */ - __asm__ volatile ("" : : "r"(__where) : "memory"); + /* `where` can be examined with a debugger. */ + __asm__ volatile ("" : : "m"(where) : "memory"); __builtin_trap(); } From 52fff00aa1eea48abc43f57d2856548e00e13346 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 18 Oct 2022 22:25:54 +0800 Subject: [PATCH 026/133] thread: Tidy inline assembly in `_MCF_thread_self_tid()` (cherry picked from commit 7a62ad6dcaa5a5ed7689ae59d9a18a2d715ee85a) Signed-off-by: LIU Hao --- src/thread.h | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/thread.h b/src/thread.h index 9b20f45d08..ea63f29b16 100644 --- a/src/thread.h +++ b/src/thread.h @@ -217,31 +217,23 @@ uint32_t _MCF_thread_self_tid(void) __MCF_NOEXCEPT { uint32_t __tid; - __asm__ ( #if defined(__amd64__) - /* AT&T Barking | Genuine Intel */ - __MCF_PPSTR( - { movl %%gs:0x48, %0; | mov %0, gs:[0x48]; } - ) + /* Current TEB starts at `gs:0`. */ + __asm__ ("{ movl %%gs:0x48, %0 | mov %0, gs:[0x48] }" : "=r"(__tid)); #elif defined(__i386__) - /* AT&T Barking | Genuine Intel */ - __MCF_PPSTR( - { movl %%fs:0x24, %0; | mov %0, fs:[0x24]; } - ) + /* Current TEB starts at `fs:0`. */ + __asm__ ("{ movl %%fs:0x24, %0 | mov %0, fs:[0x24] }" : "=r"(__tid)); #elif defined(__aarch64__) - __MCF_PPSTR( - ldr %w0, [x18, #0x48]; - ) + /* Current TEB base is `x18`. */ + __asm__ ("ldr %w0, [x18, #0x48]" : "=r"(__tid)); #elif defined(__arm__) - __MCF_PPSTR( - mrc p15, 0, %0, c13, c0, 2; - ldr %0, [%0, #0x24]; - ) + /* Current TEB base is moved from co-processor p15. */ + char* __teb; + __asm__ ("mrc p15, #0, %0, c13, c0, #2" : "=r"(__teb)); + __tid = *(uint32_t*) (__teb + 0x24); #else -# error This CPU is not supported. +# error TODO: CPU not supported #endif - : "=r"(__tid) - ); return __tid; } From e91d206adbb6e9c630d540e1e41bae2f2f759ad9 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 18 Oct 2022 23:22:16 +0800 Subject: [PATCH 027/133] xglobals: Tidy SEH assembly (cherry picked from commit 5860706c8e87b9a9742cce86bf4ba06eadb1b556) Signed-off-by: LIU Hao --- src/xglobals.i | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index be6087d253..343fc03490 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -120,11 +120,8 @@ __cdecl __MCF_seh_top(EXCEPTION_RECORD* __rec, PVOID __estab_frame, CONTEXT* __ctx, PVOID __disp_ctx) __MCF_NOEXCEPT; #if defined(__i386__) - /* On x86, SEH is stack-based. */ -typedef struct __MCF_i386_seh_node __MCF_i386_seh_node; - -struct __MCF_i386_seh_node +struct __MCF_seh_i386_node { DWORD __next; DWORD __filter; @@ -132,38 +129,38 @@ struct __MCF_i386_seh_node __MCF_ALWAYS_INLINE void -__MCF_i386_seh_install(__MCF_i386_seh_node* __seh_node) __MCF_NOEXCEPT +__MCF_seh_i386_install(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT { - __seh_node->__next = __readfsdword(0U); + __asm__ volatile ("{ movl %%fs:0, %0 | mov %0, fs:[0] }" : "=r"(__seh_node->__next)); __seh_node->__filter = (DWORD) __MCF_seh_top; - __writefsdword(0U, (DWORD) __seh_node); + __asm__ volatile ("{ movl %0, %%fs:0 | mov fs:[0], %0 }" : : "r"(__seh_node)); } __MCF_ALWAYS_INLINE void -__MCF_i386_seh_cleanup(__MCF_i386_seh_node* __seh_node) __MCF_NOEXCEPT +__MCF_seh_i386_cleanup(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT { - __writefsdword(0U, __seh_node->__next); + __asm__ volatile ("{ movl %0, %%fs:0 | mov fs:[0], %0 }" : : "r"(__seh_node->__next)); } -# define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - __MCF_i386_seh_node __MCF_PPCAT2(__MCF_seh_node_, __LINE__) \ - __attribute__((__cleanup__(__MCF_i386_seh_cleanup))); \ - __MCF_i386_seh_install( \ - &(__MCF_PPCAT2(__MCF_seh_node_, __LINE__))) /* no semicolon */ - -#elif defined(__arm__) +# define __MCF_SEH_I386_NODE_NX(n) __MCF_seh_i386_node_##n +# define __MCF_SEH_I386_NODE_NAME __MCF_SEH_I386_NODE_NX(__LINE__) -/* On ARM, SEH is table-based. */ # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - __asm__ volatile (".seh_handler __MCF_seh_top, %except;") /* no semicolon */ - + struct __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME \ + __attribute__((__cleanup__(__MCF_seh_i386_cleanup))); \ + __MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME) /* no semicolon */ #else +/* Otherwise, SEH is table-based. */ +# ifdef __arm__ +# define __MCF_SEH_FLAG_PREFIX "%" +# else +# define __MCF_SEH_FLAG_PREFIX "@" +# endif -/* On x86_64 and AArch64, SEH is table-based. */ # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - __asm__ volatile (".seh_handler __MCF_seh_top, @except;") /* no semicolon */ - + __asm__ volatile (".seh_handler __MCF_seh_top, " \ + __MCF_SEH_FLAG_PREFIX "except") /* no semicolon */ #endif /* This structure contains timeout values that will be passed to NT syscalls. */ From 910d41b067ddfa7cd64aef57698f47254990be05 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 18 Oct 2022 23:22:23 +0800 Subject: [PATCH 028/133] fwd: Remove the now unused `__MCF_PPCAT2` and `__MCF_PPCAT3` (cherry picked from commit ecf44bb1fde3a1b69062a648638e5c809b997b21) Signed-off-by: LIU Hao --- src/fwd.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 9a0b1b8cb9..e43008430f 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -71,11 +71,8 @@ extern "C" { # #endif /* __cplusplus */ -#define __MCF_PPCAT2(x,y) x##y -#define __MCF_PPCAT3(x,y,z) x##y##z #define __MCF_PPSTR_NX(...) #__VA_ARGS__ #define __MCF_PPSTR(...) __MCF_PPSTR_NX(__VA_ARGS__) - #define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) #define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) #define __MCF_NEVER_INLINE __attribute__((__noinline__)) From 3e0dd2c1c2d75e3b25b89987418faac433afcdd2 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 18 Oct 2022 23:29:47 +0800 Subject: [PATCH 029/133] cond: Add type alias `__MCF_cond_unlock_result` (cherry picked from commit e19a59bfbc9428fa31b78fc25e9d6932d23a8f48) Signed-off-by: LIU Hao --- src/cond.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cond.c b/src/cond.c index 0172d58783..95d003ee5d 100644 --- a/src/cond.c +++ b/src/cond.c @@ -8,7 +8,9 @@ #include "cond.h" #include "xglobals.i" -struct unlock_result +typedef struct __MCF_cond_unlock_result __MCF_cond_unlock_result; + +struct __MCF_cond_unlock_result { _MCF_cond_relock_callback* relock_opt; intptr_t lock_arg; @@ -17,7 +19,7 @@ struct unlock_result static inline void -do_unlock_cleanup(struct unlock_result* res) +do_unlock_cleanup(__MCF_cond_unlock_result* res) { if(res->relock_opt) res->relock_opt(res->lock_arg, res->unlocked); @@ -28,7 +30,7 @@ int _MCF_cond_wait(_MCF_cond* cond, _MCF_cond_unlock_callback* unlock_opt, _MCF_cond_relock_callback* relock_opt, intptr_t lock_arg, const int64_t* timeout_opt) { __MCF_SEH_DEFINE_TERMINATE_FILTER; - struct unlock_result ul_res __attribute__((__cleanup__(do_unlock_cleanup))) = __MCF_0_INIT; + __MCF_cond_unlock_result ul_res __attribute__((__cleanup__(do_unlock_cleanup))) = __MCF_0_INIT; _MCF_cond old, new; NTSTATUS status; From f0b22d0c4f07a505dd9600fd1ca40c10197eca38 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 19 Oct 2022 00:07:15 +0800 Subject: [PATCH 030/133] memcmp,xglobals: Remove the now unused `__MCF_mcomp()` and `__MCF_mequal()` (cherry picked from commit 1b35eb655733324e169c1864d5dd5a5db1659253) Signed-off-by: LIU Hao --- src/memcmp.c | 15 ++++++--- src/xglobals.i | 85 -------------------------------------------------- test/memory.c | 18 +++++------ 3 files changed, 19 insertions(+), 99 deletions(-) diff --git a/src/memcmp.c b/src/memcmp.c index d66ad7c535..d39df3bdc8 100644 --- a/src/memcmp.c +++ b/src/memcmp.c @@ -4,10 +4,6 @@ #include "precompiled.i" -int -__cdecl -__MCF_mcomp(const void* src, const void* cmp, size_t size); - __MCF_DLLEXPORT int __cdecl @@ -18,5 +14,14 @@ int __cdecl memcmp(const void* src, const void* cmp, size_t size) { - return __MCF_mcomp(src, cmp, size); + const uint8_t* psrc = src; + const uint8_t* pcmp = cmp; + + /* Get the number of matching bytes. */ + SIZE_T mlen = RtlCompareMemory(psrc, pcmp, size); + if(mlen == size) + return 0; + + /* Return the difference between mismatching bytes. */ + return psrc[mlen] - pcmp[mlen]; } diff --git a/src/xglobals.i b/src/xglobals.i index 343fc03490..7933846674 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -209,21 +209,6 @@ void* __cdecl __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT; -/* Compare two blocks of memory, like `memcmp()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE -int -__cdecl -__MCF_mcomp(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT - __attribute__((__pure__)); - -/* Check whether two blocks of memory compare equal, like `memcmp() == 0`. - * The result is a boolean value. */ -__MCF_DECLSPEC_XGLOBALS_INLINE -bool -__cdecl -__MCF_mequal(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT - __attribute__((__pure__)); - /* Allocate a block of zeroed memory, like `calloc()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE void* @@ -409,76 +394,6 @@ __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE -int -__cdecl -__MCF_mcomp(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT - { - int __result; -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __si = (uintptr_t) __src; - uintptr_t __di = (uintptr_t) __cmp; - uintptr_t __cx = __size; - - __asm__ ( - /* AT&T Barking | Genuine Intel */ - __MCF_PPSTR( - { xorl %%eax, %%eax; | xor eax, eax; } - { repz cmpsb; | repz cmpsb; } - { setnzb %%al; | setnz al; } - { sbbl %%ecx, %%ecx; | sbb ecx, ecx; } - ) - : "=a"(__result), "+S"(__si), "+D"(__di), "+c"(__cx) - : "m"(*(const __bytes*) __src), "m"(*(const __bytes*) __cmp) - : "cc" - ); - __result |= (int) __cx; -#else - /* Call the generic but slower version in NTDLL. */ - SIZE_T __n = RtlCompareMemory(__src, __cmp, __size); - if(__n != __size) { - __result = *((const uint8_t*)__src + __n) - *((const uint8_t*)__cmp + __n); - __MCF_ASSERT(__result != 0); - } - else - __result = 0; -#endif - return __result; - } - -__MCF_DECLSPEC_XGLOBALS_INLINE -bool -__cdecl -__MCF_mequal(const void* __src, const void* __cmp, size_t __size) __MCF_NOEXCEPT - { - bool __result; -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __si = (uintptr_t) __src; - uintptr_t __di = (uintptr_t) __cmp; - uintptr_t __cx = __size; - - __asm__ ( - /* AT&T Barking | Genuine Intel */ - __MCF_PPSTR( - { xorl %%eax, %%eax; | xor eax, eax; } - { repz cmpsb; | repz cmpsb; } - ) - : "=@ccz"(__result), "+S"(__si), "+D"(__di), "+c"(__cx) - : "m"(*(const __bytes*) __src), "m"(*(const __bytes*) __cmp) - : "ax" - ); -#else - /* Call the generic but slower version in NTDLL. */ - SIZE_T __n = RtlCompareMemory(__src, __cmp, __size); - __result = __n == __size; -#endif - return __result; - } - __MCF_DECLSPEC_XGLOBALS_INLINE void* __MCF_malloc_0(size_t __size) __MCF_NOEXCEPT diff --git a/test/memory.c b/test/memory.c index 9b06eb2f36..5bc3dcafc8 100644 --- a/test/memory.c +++ b/test/memory.c @@ -45,7 +45,7 @@ main(void) assert(ptr == data + 50); assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); + assert(memcmp(comp, data, sizeof(comp)) == 0); // __MCF_mzero SystemFunction036(comp, sizeof(comp)); @@ -60,7 +60,7 @@ main(void) assert(ptr == data + 50); assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); + assert(memcmp(comp, data, sizeof(comp)) == 0); // __MCF_mcopy SystemFunction036(comp, sizeof(comp)); @@ -71,7 +71,7 @@ main(void) assert(ptr == data + 10); assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); + assert(memcmp(comp, data, sizeof(comp)) == 0); // __MCF_mcopy_backward SystemFunction036(comp, sizeof(comp)); @@ -82,40 +82,40 @@ main(void) assert(ptr == data + 20); assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mequal(comp, data, sizeof(comp)) != 0); + assert(memcmp(comp, data, sizeof(comp)) == 0); // __MCF_mcomp (equal) SystemFunction036(comp, sizeof(comp)); pmemmove(data, comp, sizeof(comp)); assert(pmemcmp(comp, data, sizeof(comp)) == 0); - assert(__MCF_mcomp(comp, data, sizeof(comp)) == 0); + assert(memcmp(comp, data, sizeof(comp)) == 0); // __MCF_mcomp (less 2) comp[72] = '1'; data[72] = '2'; assert(pmemcmp(comp, data, sizeof(comp)) < 0); - assert(__MCF_mcomp(comp, data, sizeof(comp)) < 0); + assert(memcmp(comp, data, sizeof(comp)) < 0); // __MCF_mcomp (greater 1) comp[71] = '\x80'; data[71] = '\x7F'; assert(pmemcmp(comp, data, sizeof(comp)) > 0); - assert(__MCF_mcomp(comp, data, sizeof(comp)) > 0); + assert(memcmp(comp, data, sizeof(comp)) > 0); // __MCF_mcomp (greater 2) comp[45] = '2'; data[45] = '1'; assert(pmemcmp(comp, data, sizeof(comp)) > 0); - assert(__MCF_mcomp(comp, data, sizeof(comp)) > 0); + assert(memcmp(comp, data, sizeof(comp)) > 0); // __MCF_mcomp (less 1) comp[44] = '\x7F'; data[44] = '\x80'; assert(pmemcmp(comp, data, sizeof(comp)) < 0); - assert(__MCF_mcomp(comp, data, sizeof(comp)) < 0); + assert(memcmp(comp, data, sizeof(comp)) < 0); } From 519483c39ca1516eddf092bf3222f3267cefb652 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 19 Oct 2022 00:30:44 +0800 Subject: [PATCH 031/133] xglobals: Tidy inline assembly (cherry picked from commit 35d3e0c030feb8f5dfad21a7e0fa036d2ef496f9) Signed-off-by: LIU Hao --- src/xglobals.i | 100 +++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 61 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index 7933846674..9d93a61a75 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -287,29 +287,39 @@ __MCF_keyed_event_signal(const void* __key, const LARGE_INTEGER* __timeout) __MC return __status; } +#if defined(__i386__) || defined(__amd64__) +/* Define macros for string operations for reducing code size. */ +# define __MCF_X86_REP_STOSB(di, cx, ax) \ + __asm__ volatile ( \ + "rep stosb" \ + : "+D"(*(di)), "+c"(*(cx)) : "a"(ax) \ + : "memory") /* no semicolon */ + +# define __MCF_X86_REP_MOVSB(di, si, cx) \ + __asm__ volatile ( \ + "rep movsb" \ + : "+D"(*(di)), "+S"(*(si)), "+c"(*(cx)) : \ + : "memory") /* no semicolon */ + +# define __MCF_X86_REP_MOVSB_R(di, si, cx) \ + __asm__ volatile ( \ + "std; rep movsb; cld" \ + : "+D"(*(di)), "+S"(*(si)), "+c"(*(cx)) : \ + : "memory") /* no semicolon */ +#endif + __MCF_DECLSPEC_XGLOBALS_INLINE void* __cdecl __MCF_mcopy(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT { __MCF_ASSERT((uintptr_t) __dst - (uintptr_t) __src >= __size); -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __di = (uintptr_t) __dst; - uintptr_t __si = (uintptr_t) __src; - uintptr_t __cx = __size; - - __asm__ ( - __MCF_PPSTR( - rep movsb; - ) - : "+D"(__di), "+S"(__si), "+c"(__cx), "=m"(*(__bytes*) __dst) - : "m"(*(const __bytes*) __src) - ); +#ifdef __MCF_X86_REP_MOVSB + char* __di = (char*) __dst; + char* __si = (char*) __src; + size_t __cx = __size; + __MCF_X86_REP_MOVSB(&__di, &__si, &__cx); #else - /* Call the generic but slower version in NTDLL. We have to call - * `RtlMoveMemory()` because `RtlCopyMemory()` isn't always exported. */ RtlMoveMemory(__dst, __src, __size); #endif return __dst; @@ -321,24 +331,12 @@ __cdecl __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT { __MCF_ASSERT((uintptr_t) __src - (uintptr_t) __dst >= __size); -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __di = (uintptr_t) __dst + __size - 1; - uintptr_t __si = (uintptr_t) __src + __size - 1; - uintptr_t __cx = __size; - - __asm__ ( - __MCF_PPSTR( - std; - rep movsb; - cld; - ) - : "+D"(__di), "+S"(__si), "+c"(__cx), "=m"(*(__bytes*) __dst) - : "m"(*(const __bytes*) __src) - ); +#ifdef __MCF_X86_REP_MOVSB_R + char* __di = (char*) __dst + __size - 1; + char* __si = (char*) __src + __size - 1; + size_t __cx = __size; + __MCF_X86_REP_MOVSB_R(&__di, &__si, &__cx); #else - /* Call the generic but slower version in NTDLL. */ RtlMoveMemory(__dst, __src, __size); #endif return __dst; @@ -349,21 +347,11 @@ void* __cdecl __MCF_mfill(void* __dst, int __val, size_t __size) __MCF_NOEXCEPT { -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __di = (uintptr_t) __dst; - uintptr_t __cx = __size; - - __asm__ ( - __MCF_PPSTR( - rep stosb; - ) - : "+D"(__di), "+c"(__cx), "=m"(*(__bytes*) __dst) - : "a"(__val) - ); +#ifdef __MCF_X86_REP_STOSB + char* __di = (char*) __dst; + size_t __cx = __size; + __MCF_X86_REP_STOSB(&__di, &__cx, __val); #else - /* Call the generic but slower version in NTDLL. */ RtlFillMemory(__dst, __size, __val); #endif return __dst; @@ -374,21 +362,11 @@ void* __cdecl __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT { -#if defined(__i386__) || defined(__amd64__) - /* Use inline assembly to reduce code size. */ - typedef char __bytes[__size]; - uintptr_t __di = (uintptr_t) __dst; - uintptr_t __cx = __size; - - __asm__ ( - __MCF_PPSTR( - rep stosb; - ) - : "+D"(__di), "+c"(__cx), "=m"(*(__bytes*) __dst) - : "a"(0) - ); +#ifdef __MCF_X86_REP_STOSB + char* __di = (char*) __dst; + size_t __cx = __size; + __MCF_X86_REP_STOSB(&__di, &__cx, 0); #else - /* Call the generic but slower version in NTDLL. */ RtlZeroMemory(__dst, __size); #endif return __dst; From c8e4caa39ea43b664c7013e19162cc9e28d5235f Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 19 Oct 2022 00:31:17 +0800 Subject: [PATCH 032/133] fwd: Remove unused `__MCF_PPSTR()` (cherry picked from commit a9a17540a75e9fc2371a5fc29cd62c40e9988b44) Signed-off-by: LIU Hao --- src/fwd.h | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index e43008430f..90982ceb88 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -71,15 +71,13 @@ extern "C" { # #endif /* __cplusplus */ -#define __MCF_PPSTR_NX(...) #__VA_ARGS__ -#define __MCF_PPSTR(...) __MCF_PPSTR_NX(__VA_ARGS__) -#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) -#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) -#define __MCF_NEVER_INLINE __attribute__((__noinline__)) -#define __MCF_NOEXCEPT __MCF_CXX(throw()) -#define __MCF_0_INIT { __MCF_C(0) } -#define __MCF_PTR_BITS (__SIZEOF_POINTER__ * 8U) -#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) +#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) +#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) +#define __MCF_NEVER_INLINE __attribute__((__noinline__)) +#define __MCF_NOEXCEPT __MCF_CXX(throw()) +#define __MCF_0_INIT { __MCF_C(0) } +#define __MCF_PTR_BITS (__SIZEOF_POINTER__ * 8U) +#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) #ifndef __MCF_DECLSPEC_FWD_IMPORT # define __MCF_DECLSPEC_FWD_IMPORT From d8760e09f09ec0c9d3902fcb86978d34ba341b2a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 19 Oct 2022 09:12:00 +0800 Subject: [PATCH 033/133] memcmp: Rename a variable (cherry picked from commit 8d1ce36e75ef93a8cb62d88d44a35b445cc88bab) Signed-off-by: LIU Hao --- src/memcmp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/memcmp.c b/src/memcmp.c index d39df3bdc8..7b6e159df9 100644 --- a/src/memcmp.c +++ b/src/memcmp.c @@ -18,10 +18,10 @@ memcmp(const void* src, const void* cmp, size_t size) const uint8_t* pcmp = cmp; /* Get the number of matching bytes. */ - SIZE_T mlen = RtlCompareMemory(psrc, pcmp, size); - if(mlen == size) + SIZE_T mp = RtlCompareMemory(psrc, pcmp, size); + if(mp == size) return 0; /* Return the difference between mismatching bytes. */ - return psrc[mlen] - pcmp[mlen]; + return psrc[mp] - pcmp[mp]; } From a7e95f40a36e6be343cf671dcac1a9a2ad7cf8f3 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 21 Oct 2022 14:43:38 +0800 Subject: [PATCH 034/133] thread: Add some checks for robustness (cherry picked from commit 2ade00e8a29e58ab50564b9ec740b4f0c863744f) Signed-off-by: LIU Hao --- src/thread.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 0d647ec9e3..e422b2d991 100644 --- a/src/thread.c +++ b/src/thread.c @@ -16,7 +16,7 @@ __stdcall do_win32_thread_thunk(LPVOID param) { __MCF_SEH_DEFINE_TERMINATE_FILTER; - _MCF_thread* self = param; + _MCF_thread* const self = param; #if defined(__i386__) || defined(__amd64__) /* Set x87 precision to 64-bit mantissa (GNU `long double` format). */ @@ -106,6 +106,9 @@ __MCF_DLLEXPORT int _MCF_thread_wait(const _MCF_thread* thrd, const int64_t* timeout_opt) { + if(!thrd) + return -1; + __MCF_winnt_timeout nt_timeout; __MCF_initialize_winnt_timeout_v2(&nt_timeout, timeout_opt); From 2d243aea02e0500a29a013491778a96f0ff0acf5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 22 Oct 2022 00:01:09 +0800 Subject: [PATCH 035/133] doc: Add a missing `struct` keyword (cherry picked from commit 08351235041651636e32bf8244c4166946b8a7e5) Signed-off-by: LIU Hao --- MUTEX.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MUTEX.md b/MUTEX.md index 503a988b59..f4ad30c502 100644 --- a/MUTEX.md +++ b/MUTEX.md @@ -5,7 +5,7 @@ The `_MCF_mutex` type in MCF Gthread is a one-pointer-size structure with fields like follows: ```c -typedef __MCF_mutex _MCF_mutex; +typedef struct __MCF_mutex _MCF_mutex; struct __MCF_mutex { From dbf772f3d22fcf7d588ba8f508b34beff98c1bbe Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 24 Oct 2022 13:32:11 +0800 Subject: [PATCH 036/133] thread: Remove initialization tricks for `__tid` --- src/thread.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/thread.c b/src/thread.c index e422b2d991..ee0fb82d15 100644 --- a/src/thread.c +++ b/src/thread.c @@ -18,16 +18,15 @@ do_win32_thread_thunk(LPVOID param) __MCF_SEH_DEFINE_TERMINATE_FILTER; _MCF_thread* const self = param; + /* `__tid` has to be set in case that this thread begins execution before + * `CreateThread()` returns from the other thread. */ + self->__tid = _MCF_thread_self_tid(); + #if defined(__i386__) || defined(__amd64__) /* Set x87 precision to 64-bit mantissa (GNU `long double` format). */ __asm__ volatile ("fninit"); #endif /* x86 */ - /* Wait until the structure has been fully initialized. */ - DWORD cmp = 0; - if(_MCF_atomic_cmpxchg_32_rlx(&(self->__tid), &cmp, -1)) - __MCF_keyed_event_wait(self, NULL); - /* Attach the thread and execute the user-defined procedure. */ TlsSetValue(__MCF_win32_tls_index, self); self->__proc(self); @@ -54,8 +53,10 @@ _MCF_thread_new(_MCF_thread_procedure* proc, const void* data_opt, size_t size) thrd->__proc = proc; thrd->__data_ptr = thrd->__data_storage; - /* Create the thread. The new thread will wait until `__tid` contains a - * valid thread ID. */ + if(data_opt) + __MCF_mcopy(thrd->__data_storage, data_opt, size); + + /* Create the thread now. */ DWORD tid; thrd->__handle = CreateThread(NULL, 0, do_win32_thread_thunk, thrd, 0, &tid); if(thrd->__handle == NULL) { @@ -63,16 +64,9 @@ _MCF_thread_new(_MCF_thread_procedure* proc, const void* data_opt, size_t size) return NULL; } - /* Copy user-defined data in, before setting the `__tid` field. */ - if(data_opt) - __MCF_mcopy(thrd->__data_storage, data_opt, size); - - /* Set the thread ID. If its old value is not zero, the new thread should - * have been waiting, so notify it. */ - if(_MCF_atomic_xchg_32_rlx(&(thrd->__tid), (int32_t) tid) != 0) - __MCF_keyed_event_signal(thrd, NULL); - - __MCF_ASSERT(thrd->__tid == tid); + /* Set `__tid` in case `CreateThread()` returns before the new thread begins + * execution. It may be overwritten by the new thread with the same value. */ + thrd->__tid = tid; return thrd; } From 9c0b89975fdaae1412bfc076f84cf784fb809656 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 24 Oct 2022 13:34:04 +0800 Subject: [PATCH 037/133] thread: Use atomic operations to store the TID --- src/thread.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thread.c b/src/thread.c index ee0fb82d15..3ba75c2495 100644 --- a/src/thread.c +++ b/src/thread.c @@ -20,7 +20,7 @@ do_win32_thread_thunk(LPVOID param) /* `__tid` has to be set in case that this thread begins execution before * `CreateThread()` returns from the other thread. */ - self->__tid = _MCF_thread_self_tid(); + _MCF_atomic_store_32_rlx(&(self->__tid), (int32_t) _MCF_thread_self_tid()); #if defined(__i386__) || defined(__amd64__) /* Set x87 precision to 64-bit mantissa (GNU `long double` format). */ @@ -66,7 +66,7 @@ _MCF_thread_new(_MCF_thread_procedure* proc, const void* data_opt, size_t size) /* Set `__tid` in case `CreateThread()` returns before the new thread begins * execution. It may be overwritten by the new thread with the same value. */ - thrd->__tid = tid; + _MCF_atomic_store_32_rlx(&(thrd->__tid), (int32_t) tid); return thrd; } From c993d4335d778a3fc379324ab6ceac0dbc3cc8b5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 25 Oct 2022 21:23:13 +0800 Subject: [PATCH 038/133] *: Add `__MCF_C_DECLARATIONS_{BEGIN,END}` macros (cherry picked from commit ac8d2a6de48f0aeac061e477742b65d807f06226) Signed-off-by: LIU Hao --- src/atomic.h | 7 +++++++ src/c11.h | 11 ++--------- src/clock.h | 10 ++-------- src/cond.h | 10 ++-------- src/cxa.h | 10 ++-------- src/dtor_queue.h | 10 ++-------- src/event.h | 10 ++-------- src/exit.h | 10 ++-------- src/fwd.h | 13 +++++-------- src/gthr.h | 11 ++--------- src/gthr_aux.h | 10 ++-------- src/mutex.h | 10 ++-------- src/once.h | 10 ++-------- src/sem.h | 10 ++-------- src/thread.h | 10 ++-------- src/tls.h | 10 ++-------- 16 files changed, 40 insertions(+), 122 deletions(-) diff --git a/src/atomic.h b/src/atomic.h index bbe10639d0..f8ece445af 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -7,6 +7,12 @@ #include "fwd.h" +__MCF_C_DECLARATIONS_BEGIN +#ifndef __MCF_DECLSPEC_ATOMIC_IMPORT +# define __MCF_DECLSPEC_ATOMIC_IMPORT +# define __MCF_DECLSPEC_ATOMIC_INLINE __MCF_GNU_INLINE +#endif + /* We don't use the generic builtins due to a GCC bug. * See for details. * @@ -271,4 +277,5 @@ __MCF_ATOMIC_FUNCTIONS(__MCF_ATOMIC_xsub_, rel) __MCF_ATOMIC_FUNCTIONS(__MCF_ATOMIC_xsub_, arl) __MCF_ATOMIC_FUNCTIONS(__MCF_ATOMIC_xsub_, cst) +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_ATOMIC_ */ diff --git a/src/c11.h b/src/c11.h index b7200912b7..8b24ef69bd 100644 --- a/src/c11.h +++ b/src/c11.h @@ -8,11 +8,7 @@ #include "fwd.h" #include "gthr_aux.h" -#ifdef __cplusplus -extern "C" { -#endif - -/* Define wrappers as required by the ISO/IEC C11 standard. */ +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_C11_IMPORT # define __MCF_DECLSPEC_C11_IMPORT # define __MCF_DECLSPEC_C11_INLINE __MCF_GNU_INLINE @@ -574,8 +570,5 @@ __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT return (__err != 0) ? thrd_error : thrd_success; } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_C11_ */ diff --git a/src/clock.h b/src/clock.h index 409d295ca6..a4f180edca 100644 --- a/src/clock.h +++ b/src/clock.h @@ -7,10 +7,7 @@ #include "fwd.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_CLOCK_IMPORT # define __MCF_DECLSPEC_CLOCK_IMPORT # define __MCF_DECLSPEC_CLOCK_INLINE __MCF_GNU_INLINE @@ -37,8 +34,5 @@ __MCF_DECLSPEC_CLOCK_IMPORT double _MCF_perf_counter(void) __MCF_NOEXCEPT; -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_CLOCK_ */ diff --git a/src/cond.h b/src/cond.h index 780bd9059b..beb2029518 100644 --- a/src/cond.h +++ b/src/cond.h @@ -8,10 +8,7 @@ #include "fwd.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_COND_IMPORT # define __MCF_DECLSPEC_COND_IMPORT # define __MCF_DECLSPEC_COND_INLINE __MCF_GNU_INLINE @@ -115,8 +112,5 @@ _MCF_cond_signal_all(_MCF_cond* __cond) __MCF_NOEXCEPT return _MCF_cond_signal_some(__cond, SIZE_MAX); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_COND_ */ diff --git a/src/cxa.h b/src/cxa.h index f71a0381d1..6bf57a52eb 100644 --- a/src/cxa.h +++ b/src/cxa.h @@ -7,10 +7,7 @@ #include "fwd.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_CXA_IMPORT # define __MCF_DECLSPEC_CXA_IMPORT # define __MCF_DECLSPEC_CXA_INLINE __MCF_GNU_INLINE @@ -79,8 +76,5 @@ __MCF_DECLSPEC_CXA_IMPORT void __MCF_cxa_finalize(void* __dso) __MCF_NOEXCEPT; -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_CXA_ */ diff --git a/src/dtor_queue.h b/src/dtor_queue.h index 0a495dd3a2..8e95fbb18b 100644 --- a/src/dtor_queue.h +++ b/src/dtor_queue.h @@ -7,10 +7,7 @@ #include "fwd.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_DTOR_QUEUE # define __MCF_DECLSPEC_DTOR_QUEUE # define __MCF_DECLSPEC_DTOR_QUEUE_INLINE __MCF_GNU_INLINE @@ -69,8 +66,5 @@ __MCF_DECLSPEC_DTOR_QUEUE void __MCF_dtor_queue_finalize(__MCF_dtor_queue* __queue, _MCF_mutex* __mutex_opt, void* __dso) __MCF_NOEXCEPT; -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_DTOR_QUEUE_ */ diff --git a/src/event.h b/src/event.h index eb180260b9..45adc259e3 100644 --- a/src/event.h +++ b/src/event.h @@ -8,10 +8,7 @@ #include "fwd.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_EVENT_IMPORT # define __MCF_DECLSPEC_EVENT_IMPORT # define __MCF_DECLSPEC_EVENT_INLINE __MCF_GNU_INLINE @@ -153,8 +150,5 @@ _MCF_event_set(_MCF_event* __event, int __value) __MCF_NOEXCEPT return _MCF_event_set_slow(__event, __value); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_EVENT_ */ diff --git a/src/exit.h b/src/exit.h index 5783edca66..b5767f2f45 100644 --- a/src/exit.h +++ b/src/exit.h @@ -7,10 +7,7 @@ #include "fwd.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_EXIT_IMPORT # define __MCF_DECLSPEC_EXIT_IMPORT # define __MCF_DECLSPEC_EXIT_INLINE __MCF_GNU_INLINE @@ -32,8 +29,5 @@ void __MCF_exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_EXIT_ */ diff --git a/src/fwd.h b/src/fwd.h index 90982ceb88..846c787363 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -11,10 +11,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - #ifndef _WIN32_WINNT # error Only Windows platforms are supported. #endif @@ -79,6 +75,10 @@ extern "C" { #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * 8U) #define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) +#define __MCF_C_DECLARATIONS_BEGIN __MCF_CXX(extern "C" {) +#define __MCF_C_DECLARATIONS_END __MCF_CXX(}) + +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_FWD_IMPORT # define __MCF_DECLSPEC_FWD_IMPORT # define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE @@ -170,8 +170,5 @@ uint32_t _MCF_get_win32_error(void) __MCF_NOEXCEPT __attribute__((__pure__)); -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_FWD_ */ diff --git a/src/gthr.h b/src/gthr.h index 844932bec3..93f62eb511 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -8,11 +8,7 @@ #include "fwd.h" #include "gthr_aux.h" -#ifdef __cplusplus -extern "C" { -#endif - -/* Define wrappers as required by 'gthr-default.h'. */ +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_GTHR_IMPORT # define __MCF_DECLSPEC_GTHR_IMPORT # define __MCF_DECLSPEC_GTHR_INLINE __MCF_GNU_INLINE @@ -605,8 +601,5 @@ __MCF_gthr_yield(void) __MCF_NOEXCEPT _MCF_yield(); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_GTHR_ */ diff --git a/src/gthr_aux.h b/src/gthr_aux.h index 7dfbed17cc..25549cbbf6 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -12,10 +12,7 @@ #include "thread.h" #include /* struct timespec */ -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_GTHR_AUX # define __MCF_DECLSPEC_GTHR_AUX # define __MCF_DECLSPEC_GTHR_AUX_INLINE __MCF_GNU_INLINE @@ -157,8 +154,5 @@ __MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT _MCF_mutex_unlock(__rmtx->__mutex); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_GTHR_AUX_ */ diff --git a/src/mutex.h b/src/mutex.h index 78dd83bc5e..14c722601e 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -8,10 +8,7 @@ #include "fwd.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_MUTEX_IMPORT # define __MCF_DECLSPEC_MUTEX_IMPORT # define __MCF_DECLSPEC_MUTEX_INLINE __MCF_GNU_INLINE @@ -127,8 +124,5 @@ _MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT _MCF_mutex_unlock_slow(__mutex); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_MUTEX_ */ diff --git a/src/once.h b/src/once.h index 896dd7b4d3..d51783212e 100644 --- a/src/once.h +++ b/src/once.h @@ -8,10 +8,7 @@ #include "fwd.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_ONCE_IMPORT # define __MCF_DECLSPEC_ONCE_IMPORT # define __MCF_DECLSPEC_ONCE_INLINE __MCF_GNU_INLINE @@ -113,8 +110,5 @@ _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT return _MCF_once_wait_slow(__once, __timeout_opt); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_ONCE_ */ diff --git a/src/sem.h b/src/sem.h index 05acf4b4d7..646243a5cd 100644 --- a/src/sem.h +++ b/src/sem.h @@ -8,10 +8,7 @@ #include "fwd.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_SEM_IMPORT # define __MCF_DECLSPEC_SEM_IMPORT # define __MCF_DECLSPEC_SEM_INLINE __MCF_GNU_INLINE @@ -115,8 +112,5 @@ _MCF_sem_signal(_MCF_sem* __sem) __MCF_NOEXCEPT return _MCF_sem_signal_some(__sem, 1); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_SEM_ */ diff --git a/src/thread.h b/src/thread.h index ea63f29b16..aa6081aac8 100644 --- a/src/thread.h +++ b/src/thread.h @@ -10,10 +10,7 @@ #include "tls.h" #include "atomic.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_THREAD_IMPORT # define __MCF_DECLSPEC_THREAD_IMPORT # define __MCF_DECLSPEC_THREAD_INLINE __MCF_GNU_INLINE @@ -255,8 +252,5 @@ _MCF_tls_set(_MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT : __MCF_tls_table_set(__self->__tls_table, __key, __value_opt); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_THREAD_ */ diff --git a/src/tls.h b/src/tls.h index 62ea46e101..937427838b 100644 --- a/src/tls.h +++ b/src/tls.h @@ -7,10 +7,7 @@ #include "fwd.h" -#ifdef __cplusplus -extern "C" { -#endif - +__MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_TLS_IMPORT # define __MCF_DECLSPEC_TLS_IMPORT # define __MCF_DECLSPEC_TLS_INLINE __MCF_GNU_INLINE @@ -105,8 +102,5 @@ _MCF_tls_key_delete(_MCF_tls_key* __key_opt) __MCF_NOEXCEPT _MCF_tls_key_delete_nonnull(__key_opt); } -#ifdef __cplusplus -} -#endif - +__MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_TLS_ */ From a59ac0ba80ef7d481598ecdcca0b907f898f6afd Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 25 Oct 2022 23:19:24 +0800 Subject: [PATCH 039/133] gthr_aux,fwd: Rename `__MCF_GTHR_ALIAS` to `__MCF_ALIAS` (cherry picked from commit 90a2295f1e72276f41252c4fac774f122072530c) Signed-off-by: LIU Hao --- src/c11.h | 50 ++++++++++++++++++++-------------------- src/fwd.h | 7 ++++++ src/gthr.h | 62 +++++++++++++++++++++++++------------------------- src/gthr_aux.h | 7 ------ 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/c11.h b/src/c11.h index 8b24ef69bd..9650a143bc 100644 --- a/src/c11.h +++ b/src/c11.h @@ -81,98 +81,98 @@ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func); -__MCF_GTHR_ALIAS(call_once, __MCF_c11_call_once); +__MCF_ALIAS(call_once, __MCF_c11_call_once); /* 7.26.3.1 The cnd_broadcast function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); +__MCF_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); /* 7.26.3.2 The cnd_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); +__MCF_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); /* 7.26.3.3 The cnd_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_init, __MCF_c11_cnd_init); +__MCF_ALIAS(cnd_init, __MCF_c11_cnd_init); /* 7.26.3.4 The cnd_signal function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_signal, __MCF_c11_cnd_signal); +__MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); /* 7.26.3.5 The cnd_timedwait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); +__MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); /* 7.26.3.6 The cnd_wait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(cnd_wait, __MCF_c11_cnd_wait); +__MCF_ALIAS(cnd_wait, __MCF_c11_cnd_wait); /* 7.26.4.1 The mtx_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); +__MCF_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); /* 7.26.4.2 The mtx_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_init, __MCF_c11_mtx_init); +__MCF_ALIAS(mtx_init, __MCF_c11_mtx_init); /* 7.26.4.3 The mtx_lock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_lock, __MCF_c11_mtx_lock); +__MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); /* 7.26.4.4 The mtx_timedlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); +__MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); /* 7.26.4.5 The mtx_trylock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); +__MCF_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); /* 7.26.4.6 The mtx_unlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); +__MCF_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); /* 7.26.5.1 The thrd_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrd, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(thrd_create, __MCF_c11_thrd_create); +__MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); /* 7.26.5.2 The thrd_current function */ __MCF_DECLSPEC_C11_INLINE @@ -180,14 +180,14 @@ thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -__MCF_GTHR_ALIAS(thrd_current, __MCF_c11_thrd_current); +__MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); /* 7.26.5.3 The thrd_detach function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(thrd_detach, __MCF_c11_thrd_detach); +__MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); /* 7.26.5.4 The thrd_equal function */ __MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) @@ -195,7 +195,7 @@ int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_GTHR_ALIAS(thrd_equal, __MCF_c11_thrd_equal); +__MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); /* 7.26.5.5 The thrd_exit function */ __MCF_DECLSPEC_C11_INLINE @@ -203,42 +203,42 @@ void __MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); -__MCF_GTHR_ALIAS(thrd_exit, __MCF_c11_thrd_exit); +__MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); /* 7.26.5.6 The thrd_join function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(thrd_join, __MCF_c11_thrd_join); +__MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); /* 7.26.5.7 The thrd_sleep function */ __MCF_DECLSPEC_C11_IMPORT int __MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); +__MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); /* 7.26.5.8 The thrd_yield function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(thrd_yield, __MCF_c11_thrd_yield); +__MCF_ALIAS(thrd_yield, __MCF_c11_thrd_yield); /* 7.26.6.1 The tss_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(tss_create, __MCF_c11_tss_create); +__MCF_ALIAS(tss_create, __MCF_c11_tss_create); /* 7.26.6.2 The tss_delete function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(tss_delete, __MCF_c11_tss_delete); +__MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); /* 7.26.6.3 The tss_get function */ __MCF_DECLSPEC_C11_INLINE @@ -246,14 +246,14 @@ void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_GTHR_ALIAS(tss_get, __MCF_c11_tss_get); +__MCF_ALIAS(tss_get, __MCF_c11_tss_get); /* 7.26.6.4 The tss_set function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(tss_set, __MCF_c11_tss_set); +__MCF_ALIAS(tss_set, __MCF_c11_tss_set); /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also diff --git a/src/fwd.h b/src/fwd.h index 846c787363..4efcc3c019 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -84,6 +84,13 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE #endif +/* Define a macro to alias functions, in order to prevent DLL hells. */ +#ifdef __cplusplus +# define __MCF_ALIAS(alias, target) static __typeof__(target)& alias = (target) +#else +# define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) +#endif + /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ #ifdef __cplusplus diff --git a/src/gthr.h b/src/gthr.h index 93f62eb511..cfe1f45ae2 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -47,28 +47,28 @@ int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); -__MCF_GTHR_ALIAS(__gthread_active_p, __MCF_gthr_active_p); +__MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); /* Performs one-time initialization, like `pthread_once()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc); -__MCF_GTHR_ALIAS(__gthread_once, __MCF_gthr_once); +__MCF_ALIAS(__gthread_once, __MCF_gthr_once); /* Allocates a thread-specific key, like `pthread_key_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_key_create, __MCF_gthr_key_create); +__MCF_ALIAS(__gthread_key_create, __MCF_gthr_key_create); /* Destroys a thread-specific key, like `pthread_key_delete()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); +__MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); /* Gets a thread-specific value, like `pthread_getspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE @@ -76,77 +76,77 @@ void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_GTHR_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); +__MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); /* Sets a thread-specific value, like `pthread_setspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); +__MCF_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); /* Initializes a mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); +__MCF_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); /* Destroys a mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); +__MCF_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); /* Locks a mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); +__MCF_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); /* Tries locking a mutex without blocking, like `pthread_mutex_trylock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); +__MCF_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); /* Tries locking a mutex until a time point, like `pthread_mutex_timedlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); +__MCF_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); /* Unlocks a mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); +__MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); +__MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); /* Destroys a recursive mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); +__MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); +__MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); /* Tries locking a recursive mutex without blocking, like * `pthread_mutex_trylock()`. */ @@ -154,7 +154,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); +__MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); /* Tries locking a recursive mutex until a time point, like * `pthread_mutex_timedlock()`. */ @@ -162,14 +162,14 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); +__MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); +__MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); /* Initializes a condition variable, like `pthread_cond_init()`. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -177,7 +177,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); +__MCF_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); /* Destroys a condition variable. This function does nothing. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -185,21 +185,21 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); +__MCF_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); +__MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); +__MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); /* Waits for a condition variable until a time point, like * `pthread_cond_timedwait()`. */ @@ -207,7 +207,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); +__MCF_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); /* Signals at most one thread that is waiting on the condition variable, like * `pthread_cond_signal()`. */ @@ -215,7 +215,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); +__MCF_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); /* Signals all threads that are waiting on the condition variable, like * `pthread_cond_broadcast()`. */ @@ -223,28 +223,28 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); +__MCF_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); /* Creates a thread, like `pthread_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_create, __MCF_gthr_create_v2); +__MCF_ALIAS(__gthread_create, __MCF_gthr_create_v2); /* Awaits a thread to terminate and gets its result, like `pthread_join()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_join, __MCF_gthr_join_v2); +__MCF_ALIAS(__gthread_join, __MCF_gthr_join_v2); /* Detaches a thread, like `pthread_detach()` */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); +__MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by @@ -254,7 +254,7 @@ __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -__MCF_GTHR_ALIAS(__gthread_self, __MCF_gthr_self); +__MCF_ALIAS(__gthread_self, __MCF_gthr_self); /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) @@ -262,14 +262,14 @@ int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_GTHR_ALIAS(__gthread_equal, __MCF_gthr_equal); +__MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); /* Gives up the current time slice, like `sched_yield()`. */ __MCF_DECLSPEC_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT; -__MCF_GTHR_ALIAS(__gthread_yield, __MCF_gthr_yield); +__MCF_ALIAS(__gthread_yield, __MCF_gthr_yield); /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also diff --git a/src/gthr_aux.h b/src/gthr_aux.h index 25549cbbf6..8676ddd10f 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -18,13 +18,6 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_DECLSPEC_GTHR_AUX_INLINE __MCF_GNU_INLINE #endif -/* Define macros for renaming symbols, in order to prevent DLL hells. */ -#ifdef __cplusplus -# define __MCF_GTHR_ALIAS(alias, target) static __MCF_CXX11(constexpr) __typeof__(target)& alias = (target) /* no semicolon */ -#else -# define __MCF_GTHR_ALIAS(alias, target) static __typeof__(target)* const alias = (target) /* no semicolon */ -#endif - /* Define reusable types. */ typedef struct __MCF_gthr_rc_mutex __MCF_gthr_rc_mutex; typedef struct __MCF_gthr_thread_record __MCF_gthr_thread_record; From f65ee957f629b5bab37b2126d678de3d9b910264 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 00:52:30 +0800 Subject: [PATCH 040/133] gthr: Fix a typo in comments (cherry picked from commit 6fcc17a6a1b1d7780ca46973ed4e424755f55f69) Signed-off-by: LIU Hao --- src/gthr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gthr.h b/src/gthr.h index cfe1f45ae2..7a31eb863b 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -248,7 +248,7 @@ __MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by - * `__gthr_create()`. Otherwise the behavior is undefined. */ + * `__gthread_create()`. Otherwise the behavior is undefined. */ __MCF_DECLSPEC_GTHR_INLINE __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT From 443e47a186e3105548c2aa8bad9a0f1cf96c3dcc Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 11:45:23 +0800 Subject: [PATCH 041/133] fwd: Update macros (cherry picked from commit a44b19b0dff9dc010c44e15eee765a0cf25154fb) Signed-off-by: LIU Hao --- src/fwd.h | 78 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 4efcc3c019..60ad64316f 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -17,66 +17,78 @@ #ifdef __cplusplus # /* C++ */ -# define __MCF_C(...) /* nothing */ -# define __MCF_C99(...) /* nothing */ -# define __MCF_C11(...) /* nothing */ +# define __MCF_C(...) /* nothing */ +# define __MCF_C99(...) /* nothing */ +# define __MCF_C11(...) /* nothing */ # #elif !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) # /* C89 */ -# define __MCF_C(...) __VA_ARGS__ -# define __MCF_C99(...) /* nothing */ -# define __MCF_C11(...) /* nothing */ +# define __MCF_C(...) __VA_ARGS__ +# define __MCF_C99(...) /* nothing */ +# define __MCF_C11(...) /* nothing */ # #elif __STDC_VERSION__ < 201103L # /* C99 */ -# define __MCF_C(...) __VA_ARGS__ -# define __MCF_C99(...) __VA_ARGS__ -# define __MCF_C11(...) /* nothing */ +# define __MCF_C(...) __VA_ARGS__ +# define __MCF_C99(...) __VA_ARGS__ +# define __MCF_C11(...) /* nothing */ # #else # /* C11 */ -# define __MCF_C(...) __VA_ARGS__ -# define __MCF_C99(...) __VA_ARGS__ -# define __MCF_C11(...) __VA_ARGS__ +# define __MCF_C(...) __VA_ARGS__ +# define __MCF_C99(...) __VA_ARGS__ +# define __MCF_C11(...) __VA_ARGS__ # #endif /* __STDC_VERSION__ */ #ifndef __cplusplus # /* C */ -# define __MCF_CXX(...) /* nothing */ -# define __MCF_CXX11(...) /* nothing */ -# define __MCF_CXX14(...) /* nothing */ +# define __MCF_CXX(...) /* nothing */ +# define __MCF_CXX11(...) /* nothing */ +# define __MCF_CXX14(...) /* nothing */ # #elif __cplusplus < 201103L # /* C++98 */ -# define __MCF_CXX(...) __VA_ARGS__ -# define __MCF_CXX11(...) /* nothing */ -# define __MCF_CXX14(...) /* nothing */ +# define __MCF_CXX(...) __VA_ARGS__ +# define __MCF_CXX11(...) /* nothing */ +# define __MCF_CXX14(...) /* nothing */ # #elif __cplusplus < 201402L # /* C++11 */ -# define __MCF_CXX(...) __VA_ARGS__ -# define __MCF_CXX11(...) __VA_ARGS__ -# define __MCF_CXX14(...) /* nothing */ +# define __MCF_CXX(...) __VA_ARGS__ +# define __MCF_CXX11(...) __VA_ARGS__ +# define __MCF_CXX14(...) /* nothing */ # #else # /* C++14 */ -# define __MCF_CXX(...) __VA_ARGS__ -# define __MCF_CXX11(...) __VA_ARGS__ -# define __MCF_CXX14(...) __VA_ARGS__ +# define __MCF_CXX(...) __VA_ARGS__ +# define __MCF_CXX11(...) __VA_ARGS__ +# define __MCF_CXX14(...) __VA_ARGS__ # #endif /* __cplusplus */ -#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) -#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) -#define __MCF_NEVER_INLINE __attribute__((__noinline__)) -#define __MCF_NOEXCEPT __MCF_CXX(throw()) -#define __MCF_0_INIT { __MCF_C(0) } -#define __MCF_PTR_BITS (__SIZEOF_POINTER__ * 8U) -#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) +#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) +#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) +#define __MCF_NEVER_INLINE __attribute__((__noinline__)) +#define __MCF_0_INIT {__MCF_C(0)} +#define __MCF_PTR_BITS (__SIZEOF_POINTER__ * __CHAR_BIT__) +#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) -#define __MCF_C_DECLARATIONS_BEGIN __MCF_CXX(extern "C" {) -#define __MCF_C_DECLARATIONS_END __MCF_CXX(}) +#ifndef __cplusplus +# define __MCF_NOEXCEPT +#elif __cplusplus < 201103L +# define __MCF_NOEXCEPT throw() +#else +# define __MCF_NOEXCEPT noexcept +#endif + +#ifndef __cplusplus +# define __MCF_C_DECLARATIONS_BEGIN +# define __MCF_C_DECLARATIONS_END +#else +# define __MCF_C_DECLARATIONS_BEGIN extern "C" { +# define __MCF_C_DECLARATIONS_END } /* extern "C" */ +#endif __MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_FWD_IMPORT From 7211e8725ebb19ab3b8b7ad29f1a98d9fccaba9f Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 13:26:21 +0800 Subject: [PATCH 042/133] gthr: Fix return value of `__gthread_recursive_mutex_trylock()` (cherry picked from commit a7899f121c16934a797bc41e9adb8d6298a94279) Signed-off-by: LIU Hao --- src/gthr.h | 10 +-- test/Makefile.inc.am | 6 +- test/c11_mtx_recursive_timeout.c | 43 +++++++++++ test/c11_mtx_recursive_trylock.c | 69 ++++++++++++++++++ test/c11_mtx_trylock.c | 9 ++- ...gthr_recursive_mutex.c => gthr_rc_mutex.c} | 0 test/gthr_rc_mutex_timeout.c | 40 ++++++++++ test/gthr_rc_mutex_trylock.c | 73 +++++++++++++++++++ 8 files changed, 242 insertions(+), 8 deletions(-) create mode 100644 test/c11_mtx_recursive_timeout.c create mode 100644 test/c11_mtx_recursive_trylock.c rename test/{gthr_recursive_mutex.c => gthr_rc_mutex.c} (100%) create mode 100644 test/gthr_rc_mutex_timeout.c create mode 100644 test/gthr_rc_mutex_trylock.c diff --git a/src/gthr.h b/src/gthr.h index 7a31eb863b..c40d9cdd95 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -363,7 +363,7 @@ __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { int64_t __timeout = 0; int __err = _MCF_mutex_lock(__mtx, &__timeout); - return (__err != 0) ? -1 : 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE @@ -372,7 +372,7 @@ __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __a { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__abs_time); int __err = _MCF_mutex_lock(__mtx, &__timeout); - return (__err != 0) ? -1 : 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE @@ -423,8 +423,7 @@ __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NO __timeout = 0; __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); - __MCF_ASSERT(__err == 0); - return 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE @@ -438,8 +437,7 @@ __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __timeout = __MCF_gthr_timeout_from_timespec(__abs_time); __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); - __MCF_ASSERT(__err == 0); - return 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index 285c5e31ad..5ebe29281f 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -42,7 +42,9 @@ check_PROGRAMS += \ %reldir%/gthr_mutex_timeout.test \ %reldir%/gthr_mutex.test \ %reldir%/gthr_mutex_nonrecursive.test \ - %reldir%/gthr_recursive_mutex.test \ + %reldir%/gthr_rc_mutex_trylock.test \ + %reldir%/gthr_rc_mutex_timeout.test \ + %reldir%/gthr_rc_mutex.test \ %reldir%/gthr_cond_timeout.test \ %reldir%/gthr_cond_consumers.test \ %reldir%/gthr_cond_consumers_recursive.test \ @@ -60,6 +62,8 @@ check_PROGRAMS += \ %reldir%/c11_mtx.test \ %reldir%/c11_mtx_nonrecursive.test \ %reldir%/c11_mtx_recursive.test \ + %reldir%/c11_mtx_recursive_trylock.test \ + %reldir%/c11_mtx_recursive_timeout.test \ %reldir%/c11_cnd_timeout.test \ %reldir%/c11_cnd_consumers.test \ %reldir%/c11_cnd_consumers_recursive.test \ diff --git a/test/c11_mtx_recursive_timeout.c b/test/c11_mtx_recursive_timeout.c new file mode 100644 index 0000000000..3cf2a24499 --- /dev/null +++ b/test/c11_mtx_recursive_timeout.c @@ -0,0 +1,43 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/c11.h" +#include "../src/clock.h" +#include +#include + +static mtx_t mutex; + +int +main(void) + { + double now, delta; + struct timespec timeout; + int r; + + r = mtx_init(&mutex, mtx_recursive | mtx_timed); + assert(r == thrd_success); + + /* Round the time up. */ + int64_t sleep_until = (int64_t) time(NULL) * 1000 + 2000; + _MCF_sleep(&sleep_until); + + now = _MCF_perf_counter(); + timeout.tv_sec = time(NULL) + 1; + timeout.tv_nsec = 100000000; + r = mtx_timedlock(&mutex, &timeout); /* lock it */ + assert(r == thrd_success); + delta = _MCF_perf_counter() - now; + printf("delta = %.6f\n", delta); + assert(delta <= 100); + + now = _MCF_perf_counter(); + timeout.tv_sec = time(NULL) + 1; + timeout.tv_nsec = 100000000; + r = mtx_timedlock(&mutex, &timeout); + assert(r == thrd_success); + delta = _MCF_perf_counter() - now; + printf("delta = %.6f\n", delta); + assert(delta <= 100); + } diff --git a/test/c11_mtx_recursive_trylock.c b/test/c11_mtx_recursive_trylock.c new file mode 100644 index 0000000000..1896f8f883 --- /dev/null +++ b/test/c11_mtx_recursive_trylock.c @@ -0,0 +1,69 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/c11.h" +#include "../src/sem.h" +#include +#include + +#define NTHREADS 64U +static thrd_t threads[NTHREADS]; +static mtx_t mutex; +static _MCF_sem start = __MCF_SEM_INIT(NTHREADS); +static int resource = 0; + +static +int +thread_proc(void* param) + { + (void) param; + _MCF_sem_wait(&start, NULL); + + for(;;) { + int r = mtx_trylock(&mutex); + if(r == thrd_success) { + printf("thread %d got %d\n", (int) _MCF_thread_self_tid(), r); + + /* Add a resource. */ + int old = resource; + _MCF_sleep((const int64_t[]) { -10 }); + resource = old + 1; + mtx_unlock(&mutex); + break; + } + else if(r == thrd_busy) { + /* Wait. */ + _MCF_sleep((const int64_t[]) { -10 }); + continue; + } + else + assert(0); + } + + printf("thread %d quitting\n", (int) _MCF_thread_self_tid()); + return 0; + } + +int +main(void) + { + int err = mtx_init(&mutex, mtx_plain); + assert(err == thrd_success); + + for(size_t k = 0; k < NTHREADS; ++k) { + int r = thrd_create(&threads[k], thread_proc, NULL); + assert(r == thrd_success); + assert(threads[k]); + } + + printf("main waiting\n"); + _MCF_sem_signal_some(&start, NTHREADS); + for(size_t k = 0; k < NTHREADS; ++k) { + int r = thrd_join(threads[k], NULL); + assert(r == thrd_success); + printf("main wait finished: %d\n", (int)k); + } + + assert(resource == NTHREADS); + } diff --git a/test/c11_mtx_trylock.c b/test/c11_mtx_trylock.c index 1896f8f883..bf9d949ef7 100644 --- a/test/c11_mtx_trylock.c +++ b/test/c11_mtx_trylock.c @@ -25,11 +25,18 @@ thread_proc(void* param) if(r == thrd_success) { printf("thread %d got %d\n", (int) _MCF_thread_self_tid(), r); + r = mtx_lock(&mutex); + assert(r == 0); + r = mtx_trylock(&mutex); + assert(r == 0); + /* Add a resource. */ int old = resource; _MCF_sleep((const int64_t[]) { -10 }); resource = old + 1; mtx_unlock(&mutex); + mtx_unlock(&mutex); + mtx_unlock(&mutex); break; } else if(r == thrd_busy) { @@ -48,7 +55,7 @@ thread_proc(void* param) int main(void) { - int err = mtx_init(&mutex, mtx_plain); + int err = mtx_init(&mutex, mtx_recursive); assert(err == thrd_success); for(size_t k = 0; k < NTHREADS; ++k) { diff --git a/test/gthr_recursive_mutex.c b/test/gthr_rc_mutex.c similarity index 100% rename from test/gthr_recursive_mutex.c rename to test/gthr_rc_mutex.c diff --git a/test/gthr_rc_mutex_timeout.c b/test/gthr_rc_mutex_timeout.c new file mode 100644 index 0000000000..9f3d51f623 --- /dev/null +++ b/test/gthr_rc_mutex_timeout.c @@ -0,0 +1,40 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/gthr.h" +#include "../src/clock.h" +#include +#include + +static __gthread_recursive_mutex_t mutex = __GTHREAD_RECURSIVE_MUTEX_INIT; + +int +main(void) + { + double now, delta; + __gthread_time_t timeout; + int r; + + /* Round the time up. */ + int64_t sleep_until = (int64_t) time(NULL) * 1000 + 2000; + _MCF_sleep(&sleep_until); + + now = _MCF_perf_counter(); + timeout.tv_sec = time(NULL) + 1; + timeout.tv_nsec = 100000000; + r = __gthread_recursive_mutex_timedlock(&mutex, &timeout); /* lock it */ + assert(r == 0); + delta = _MCF_perf_counter() - now; + printf("delta = %.6f\n", delta); + assert(delta <= 100); + + now = _MCF_perf_counter(); + timeout.tv_sec = time(NULL) + 1; + timeout.tv_nsec = 100000000; + r = __gthread_recursive_mutex_timedlock(&mutex, &timeout); + assert(r == 0); + delta = _MCF_perf_counter() - now; + printf("delta = %.6f\n", delta); + assert(delta <= 100); + } diff --git a/test/gthr_rc_mutex_trylock.c b/test/gthr_rc_mutex_trylock.c new file mode 100644 index 0000000000..54585cd12e --- /dev/null +++ b/test/gthr_rc_mutex_trylock.c @@ -0,0 +1,73 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/gthr.h" +#include "../src/sem.h" +#include +#include + +#define NTHREADS 64U +static __gthread_t threads[NTHREADS]; +static __gthread_recursive_mutex_t mutex = __GTHREAD_RECURSIVE_MUTEX_INIT; +static _MCF_sem start = __MCF_SEM_INIT(NTHREADS); +static int resource = 0; + +static +void* +thread_proc(void* param) + { + (void) param; + _MCF_sem_wait(&start, NULL); + + for(;;) { + int r = __gthread_recursive_mutex_trylock(&mutex); + if(r == 0) { + printf("thread %d got %d\n", (int) _MCF_thread_self_tid(), r); + + r = __gthread_recursive_mutex_trylock(&mutex); + assert(r == 0); + r = __gthread_recursive_mutex_lock(&mutex); + assert(r == 0); + + /* Add a resource. */ + int old = resource; + _MCF_sleep((const int64_t[]) { -10 }); + resource = old + 1; + __gthread_recursive_mutex_unlock(&mutex); + __gthread_recursive_mutex_unlock(&mutex); + __gthread_recursive_mutex_unlock(&mutex); + break; + } + else if(r == -1) { + /* Wait. */ + _MCF_sleep((const int64_t[]) { -10 }); + continue; + } + else + assert(0); + } + + printf("thread %d quitting\n", (int) _MCF_thread_self_tid()); + return NULL; + } + +int +main(void) + { + for(size_t k = 0; k < NTHREADS; ++k) { + int r = __gthread_create(&threads[k], thread_proc, NULL); + assert(r == 0); + assert(threads[k]); + } + + printf("main waiting\n"); + _MCF_sem_signal_some(&start, NTHREADS); + for(size_t k = 0; k < NTHREADS; ++k) { + int r = __gthread_join(threads[k], NULL); + assert(r == 0); + printf("main wait finished: %d\n", (int)k); + } + + assert(resource == NTHREADS); + } From 6e2238ba890f9d583f85dc286a73d987222d2a46 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 13:31:19 +0800 Subject: [PATCH 043/133] gthr,gthr_libobjc: Collapse a return value (cherry picked from commit 075270d8fb695f0d78a434f6b189201904c8992c) Signed-off-by: LIU Hao --- src/gthr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gthr.h b/src/gthr.h index c40d9cdd95..17ad48266b 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -329,7 +329,7 @@ int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT { int __err = _MCF_tls_set(__key, __val_opt); - return (__err != 0) ? -1 : 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE @@ -488,7 +488,7 @@ __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, co { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__abs_time); int __err = _MCF_cond_wait(__cond, __MCF_gthr_mutex_unlock_callback, __MCF_gthr_mutex_relock_callback, (intptr_t) __mtx, &__timeout); - return (__err != 0) ? -1 : 0; + return __err; } __MCF_DECLSPEC_GTHR_INLINE From b5681d9ab080ddefd71af78375823bee9205137e Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 23:12:32 +0800 Subject: [PATCH 044/133] gthr: Remove outdated comments (cherry picked from commit cc56438d4592ec0df9e8700afb72bb7b1e8eab2a) Signed-off-by: LIU Hao --- src/gthr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gthr.h b/src/gthr.h index 17ad48266b..b817c2226f 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -520,7 +520,7 @@ __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, __thrd = _MCF_thread_new(__MCF_gthr_thread_thunk_v2, __rec, sizeof(*__rec)); *__thrdp = __thrd; - return (__thrd == NULL) ? -1 : 0; /* as specified by POSIX */ + return (__thrd == NULL) ? -1 : 0; } __MCF_DECLSPEC_GTHR_INLINE From ef6beff3054f8c3c85a9d20a21ebbcf8bb0d2fac Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 26 Oct 2022 23:43:52 +0800 Subject: [PATCH 045/133] test: Add 'c11_thrd_sleep.c' (cherry picked from commit 678f3f4f06a330f06169950ac7ad4325b4de2ff0) Signed-off-by: LIU Hao --- test/Makefile.inc.am | 1 + test/c11_thrd_sleep.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 test/c11_thrd_sleep.c diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index 5ebe29281f..68f8246a4c 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -73,6 +73,7 @@ check_PROGRAMS += \ %reldir%/c11_tss_many.test \ %reldir%/c11_thrd_return.test \ %reldir%/c11_thrd_equal.test \ + %reldir%/c11_thrd_sleep.test \ %reldir%/c11_c89_pedantic.test \ %reldir%/atexit_thread_self.test \ %reldir%/atexit_order.test \ diff --git a/test/c11_thrd_sleep.c b/test/c11_thrd_sleep.c new file mode 100644 index 0000000000..c5260493ee --- /dev/null +++ b/test/c11_thrd_sleep.c @@ -0,0 +1,30 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/c11.h" +#include "../src/clock.h" +#include +#include + +int +main(void) + { + double now, delta; + struct timespec timeout; + int r; + + /* Round the time up. */ + int64_t sleep_until = (int64_t) time(NULL) * 1000 + 2000; + _MCF_sleep(&sleep_until); + + now = _MCF_perf_counter(); + timeout.tv_sec = 1; /* relative */ + timeout.tv_nsec = 300000000; + r = thrd_sleep(&timeout, NULL); + assert(r == 0); + delta = _MCF_perf_counter() - now; + printf("delta = %.6f\n", delta); + assert(delta >= 1200); + assert(delta <= 1400); + } From b0aa9d367bca1285ca79df34571ee7c5ec3dc76b Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 27 Oct 2022 12:11:52 +0800 Subject: [PATCH 046/133] precompiled,xglobals: Remove (cherry picked from commit abbcadb176a330ee2c645654f547d8f89ea92eb6) Signed-off-by: LIU Hao --- src/precompiled.i | 2 +- src/xglobals.i | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/precompiled.i b/src/precompiled.i index 30ab64a510..7a384cc8bb 100644 --- a/src/precompiled.i +++ b/src/precompiled.i @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/src/xglobals.i b/src/xglobals.i index 9d93a61a75..3a84bb0886 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -8,7 +8,7 @@ #include "fwd.h" #include #include -#include +#include #include #include From 3488bf912bdc2e6ec048fb7ac39f754b8be4717c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 27 Oct 2022 12:14:29 +0800 Subject: [PATCH 047/133] precompiled,xglobals: Remove (cherry picked from commit e2eec351ba3ad187ad63bc082aca4f206ae70098) Signed-off-by: LIU Hao --- src/precompiled.i | 1 - src/xglobals.i | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/precompiled.i b/src/precompiled.i index 7a384cc8bb..150fe7034d 100644 --- a/src/precompiled.i +++ b/src/precompiled.i @@ -18,7 +18,6 @@ #endif #include -#include #include #include #include diff --git a/src/xglobals.i b/src/xglobals.i index 3a84bb0886..51e84ce8ca 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -7,7 +7,6 @@ #include "fwd.h" #include -#include #include #include #include @@ -88,6 +87,7 @@ __MCF_WINAPI(ULONGLONG, GetTickCount64, void); __MCF_WINAPI(BOOL, QueryPerformanceFrequency, LARGE_INTEGER*); __MCF_WINAPI(BOOL, QueryPerformanceCounter, LARGE_INTEGER*); +typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES; typedef DWORD __stdcall THREAD_START_ROUTINE(LPVOID); __MCF_WINAPI(HANDLE, CreateThread, SECURITY_ATTRIBUTES*, SIZE_T, THREAD_START_ROUTINE*, LPVOID, DWORD, DWORD*); __MCF_WINAPI(void, ExitThread, DWORD) __attribute__((__noreturn__)); From 4fe0580adb30c1499878f369b55bc13c43bf01d1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 13:16:24 +0800 Subject: [PATCH 048/133] fwd: Remove `__MCF_ALIAS` macro (cherry picked from commit 397dea057e1422c5c2dadcc6195465481448586c) Signed-off-by: LIU Hao --- src/c11.h | 50 +++++++++++++++++++++---------------------- src/fwd.h | 7 ------ src/gthr.h | 62 +++++++++++++++++++++++++++--------------------------- 3 files changed, 56 insertions(+), 63 deletions(-) diff --git a/src/c11.h b/src/c11.h index 9650a143bc..0695768372 100644 --- a/src/c11.h +++ b/src/c11.h @@ -81,98 +81,98 @@ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func); -__MCF_ALIAS(call_once, __MCF_c11_call_once); +#define call_once __MCF_c11_call_once /* 7.26.3.1 The cnd_broadcast function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); +#define cnd_broadcast __MCF_c11_cnd_broadcast /* 7.26.3.2 The cnd_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); +#define cnd_destroy __MCF_c11_cnd_destroy /* 7.26.3.3 The cnd_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_init, __MCF_c11_cnd_init); +#define cnd_init __MCF_c11_cnd_init /* 7.26.3.4 The cnd_signal function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); +#define cnd_signal __MCF_c11_cnd_signal /* 7.26.3.5 The cnd_timedwait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); +#define cnd_timedwait __MCF_c11_cnd_timedwait /* 7.26.3.6 The cnd_wait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(cnd_wait, __MCF_c11_cnd_wait); +#define cnd_wait __MCF_c11_cnd_wait /* 7.26.4.1 The mtx_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); +#define mtx_destroy __MCF_c11_mtx_destroy /* 7.26.4.2 The mtx_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_init, __MCF_c11_mtx_init); +#define mtx_init __MCF_c11_mtx_init /* 7.26.4.3 The mtx_lock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); +#define mtx_lock __MCF_c11_mtx_lock /* 7.26.4.4 The mtx_timedlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); +#define mtx_timedlock __MCF_c11_mtx_timedlock /* 7.26.4.5 The mtx_trylock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); +#define mtx_trylock __MCF_c11_mtx_trylock /* 7.26.4.6 The mtx_unlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); +#define mtx_unlock __MCF_c11_mtx_unlock /* 7.26.5.1 The thrd_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrd, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT; -__MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); +#define thrd_create __MCF_c11_thrd_create /* 7.26.5.2 The thrd_current function */ __MCF_DECLSPEC_C11_INLINE @@ -180,14 +180,14 @@ thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -__MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); +#define thrd_current __MCF_c11_thrd_current /* 7.26.5.3 The thrd_detach function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT; -__MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); +#define thrd_detach __MCF_c11_thrd_detach /* 7.26.5.4 The thrd_equal function */ __MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) @@ -195,7 +195,7 @@ int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); +#define thrd_equal __MCF_c11_thrd_equal /* 7.26.5.5 The thrd_exit function */ __MCF_DECLSPEC_C11_INLINE @@ -203,42 +203,42 @@ void __MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); -__MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); +#define thrd_exit __MCF_c11_thrd_exit /* 7.26.5.6 The thrd_join function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); +#define thrd_join __MCF_c11_thrd_join /* 7.26.5.7 The thrd_sleep function */ __MCF_DECLSPEC_C11_IMPORT int __MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); +#define thrd_sleep __MCF_c11_thrd_sleep /* 7.26.5.8 The thrd_yield function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT; -__MCF_ALIAS(thrd_yield, __MCF_c11_thrd_yield); +#define thrd_yield __MCF_c11_thrd_yield /* 7.26.6.1 The tss_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(tss_create, __MCF_c11_tss_create); +#define tss_create __MCF_c11_tss_create /* 7.26.6.2 The tss_delete function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT; -__MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); +#define tss_delete __MCF_c11_tss_delete /* 7.26.6.3 The tss_get function */ __MCF_DECLSPEC_C11_INLINE @@ -246,14 +246,14 @@ void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_ALIAS(tss_get, __MCF_c11_tss_get); +#define tss_get __MCF_c11_tss_get /* 7.26.6.4 The tss_set function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(tss_set, __MCF_c11_tss_set); +#define tss_set __MCF_c11_tss_set /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also diff --git a/src/fwd.h b/src/fwd.h index 60ad64316f..0dec9f6eb5 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -96,13 +96,6 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE #endif -/* Define a macro to alias functions, in order to prevent DLL hells. */ -#ifdef __cplusplus -# define __MCF_ALIAS(alias, target) static __typeof__(target)& alias = (target) -#else -# define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) -#endif - /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ #ifdef __cplusplus diff --git a/src/gthr.h b/src/gthr.h index b817c2226f..71bbfd8b79 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -47,28 +47,28 @@ int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); -__MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); +#define __gthread_active_p __MCF_gthr_active_p /* Performs one-time initialization, like `pthread_once()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc); -__MCF_ALIAS(__gthread_once, __MCF_gthr_once); +#define __gthread_once __MCF_gthr_once /* Allocates a thread-specific key, like `pthread_key_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_key_create, __MCF_gthr_key_create); +#define __gthread_key_create __MCF_gthr_key_create /* Destroys a thread-specific key, like `pthread_key_delete()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); +#define __gthread_key_delete __MCF_gthr_key_delete /* Gets a thread-specific value, like `pthread_getspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE @@ -76,77 +76,77 @@ void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); +#define __gthread_getspecific __MCF_gthr_getspecific /* Sets a thread-specific value, like `pthread_setspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); +#define __gthread_setspecific __MCF_gthr_setspecific /* Initializes a mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); +#define __gthread_mutex_init __MCF_gthr_mutex_init /* Destroys a mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); +#define __gthread_mutex_destroy __MCF_gthr_mutex_destroy /* Locks a mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); +#define __gthread_mutex_lock __MCF_gthr_mutex_lock /* Tries locking a mutex without blocking, like `pthread_mutex_trylock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); +#define __gthread_mutex_trylock __MCF_gthr_mutex_trylock /* Tries locking a mutex until a time point, like `pthread_mutex_timedlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); +#define __gthread_mutex_timedlock __MCF_gthr_mutex_timedlock /* Unlocks a mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); +#define __gthread_mutex_unlock __MCF_gthr_mutex_unlock /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); +#define __gthread_recursive_mutex_init __MCF_gthr_recursive_mutex_init /* Destroys a recursive mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); +#define __gthread_recursive_mutex_destroy __MCF_gthr_recursive_mutex_destroy /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); +#define __gthread_recursive_mutex_lock __MCF_gthr_recursive_mutex_lock /* Tries locking a recursive mutex without blocking, like * `pthread_mutex_trylock()`. */ @@ -154,7 +154,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); +#define __gthread_recursive_mutex_trylock __MCF_gthr_recursive_mutex_trylock /* Tries locking a recursive mutex until a time point, like * `pthread_mutex_timedlock()`. */ @@ -162,14 +162,14 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); +#define __gthread_recursive_mutex_timedlock __MCF_gthr_recursive_mutex_timedlock /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); +#define __gthread_recursive_mutex_unlock __MCF_gthr_recursive_mutex_unlock /* Initializes a condition variable, like `pthread_cond_init()`. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -177,7 +177,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); +#define __gthread_cond_init __MCF_gthr_cond_init /* Destroys a condition variable. This function does nothing. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -185,21 +185,21 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); +#define __gthread_cond_destroy __MCF_gthr_cond_destroy /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); +#define __gthread_cond_wait __MCF_gthr_cond_wait /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); +#define __gthread_cond_wait_recursive __MCF_gthr_cond_wait_recursive /* Waits for a condition variable until a time point, like * `pthread_cond_timedwait()`. */ @@ -207,7 +207,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); +#define __gthread_cond_timedwait __MCF_gthr_cond_timedwait /* Signals at most one thread that is waiting on the condition variable, like * `pthread_cond_signal()`. */ @@ -215,7 +215,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); +#define __gthread_cond_signal __MCF_gthr_cond_signal /* Signals all threads that are waiting on the condition variable, like * `pthread_cond_broadcast()`. */ @@ -223,28 +223,28 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); +#define __gthread_cond_broadcast __MCF_gthr_cond_broadcast /* Creates a thread, like `pthread_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_create, __MCF_gthr_create_v2); +#define __gthread_create __MCF_gthr_create_v2 /* Awaits a thread to terminate and gets its result, like `pthread_join()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_join, __MCF_gthr_join_v2); +#define __gthread_join __MCF_gthr_join_v2 /* Detaches a thread, like `pthread_detach()` */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); +#define __gthread_detach __MCF_gthr_detach_v2 /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by @@ -254,7 +254,7 @@ __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -__MCF_ALIAS(__gthread_self, __MCF_gthr_self); +#define __gthread_self __MCF_gthr_self /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) @@ -262,14 +262,14 @@ int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -__MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); +#define __gthread_equal __MCF_gthr_equal /* Gives up the current time slice, like `sched_yield()`. */ __MCF_DECLSPEC_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT; -__MCF_ALIAS(__gthread_yield, __MCF_gthr_yield); +#define __gthread_yield __MCF_gthr_yield /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also From 155c94a6a6a1121f7119d222d7f727cc3ce56ef7 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 13:28:33 +0800 Subject: [PATCH 049/133] Revert "fwd: Remove `__MCF_ALIAS` macro" This reverts commit 4fe0580adb30c1499878f369b55bc13c43bf01d1. --- src/c11.h | 50 +++++++++++++++++++++---------------------- src/fwd.h | 7 ++++++ src/gthr.h | 62 +++++++++++++++++++++++++++--------------------------- 3 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/c11.h b/src/c11.h index 0695768372..9650a143bc 100644 --- a/src/c11.h +++ b/src/c11.h @@ -81,98 +81,98 @@ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func); -#define call_once __MCF_c11_call_once +__MCF_ALIAS(call_once, __MCF_c11_call_once); /* 7.26.3.1 The cnd_broadcast function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT; -#define cnd_broadcast __MCF_c11_cnd_broadcast +__MCF_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); /* 7.26.3.2 The cnd_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT; -#define cnd_destroy __MCF_c11_cnd_destroy +__MCF_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); /* 7.26.3.3 The cnd_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT; -#define cnd_init __MCF_c11_cnd_init +__MCF_ALIAS(cnd_init, __MCF_c11_cnd_init); /* 7.26.3.4 The cnd_signal function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT; -#define cnd_signal __MCF_c11_cnd_signal +__MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); /* 7.26.3.5 The cnd_timedwait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -#define cnd_timedwait __MCF_c11_cnd_timedwait +__MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); /* 7.26.3.6 The cnd_wait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT; -#define cnd_wait __MCF_c11_cnd_wait +__MCF_ALIAS(cnd_wait, __MCF_c11_cnd_wait); /* 7.26.4.1 The mtx_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT; -#define mtx_destroy __MCF_c11_mtx_destroy +__MCF_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); /* 7.26.4.2 The mtx_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT; -#define mtx_init __MCF_c11_mtx_init +__MCF_ALIAS(mtx_init, __MCF_c11_mtx_init); /* 7.26.4.3 The mtx_lock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT; -#define mtx_lock __MCF_c11_mtx_lock +__MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); /* 7.26.4.4 The mtx_timedlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; -#define mtx_timedlock __MCF_c11_mtx_timedlock +__MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); /* 7.26.4.5 The mtx_trylock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT; -#define mtx_trylock __MCF_c11_mtx_trylock +__MCF_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); /* 7.26.4.6 The mtx_unlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT; -#define mtx_unlock __MCF_c11_mtx_unlock +__MCF_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); /* 7.26.5.1 The thrd_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrd, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT; -#define thrd_create __MCF_c11_thrd_create +__MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); /* 7.26.5.2 The thrd_current function */ __MCF_DECLSPEC_C11_INLINE @@ -180,14 +180,14 @@ thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -#define thrd_current __MCF_c11_thrd_current +__MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); /* 7.26.5.3 The thrd_detach function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT; -#define thrd_detach __MCF_c11_thrd_detach +__MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); /* 7.26.5.4 The thrd_equal function */ __MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) @@ -195,7 +195,7 @@ int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -#define thrd_equal __MCF_c11_thrd_equal +__MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); /* 7.26.5.5 The thrd_exit function */ __MCF_DECLSPEC_C11_INLINE @@ -203,42 +203,42 @@ void __MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); -#define thrd_exit __MCF_c11_thrd_exit +__MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); /* 7.26.5.6 The thrd_join function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT; -#define thrd_join __MCF_c11_thrd_join +__MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); /* 7.26.5.7 The thrd_sleep function */ __MCF_DECLSPEC_C11_IMPORT int __MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; -#define thrd_sleep __MCF_c11_thrd_sleep +__MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); /* 7.26.5.8 The thrd_yield function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT; -#define thrd_yield __MCF_c11_thrd_yield +__MCF_ALIAS(thrd_yield, __MCF_c11_thrd_yield); /* 7.26.6.1 The tss_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT; -#define tss_create __MCF_c11_tss_create +__MCF_ALIAS(tss_create, __MCF_c11_tss_create); /* 7.26.6.2 The tss_delete function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT; -#define tss_delete __MCF_c11_tss_delete +__MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); /* 7.26.6.3 The tss_get function */ __MCF_DECLSPEC_C11_INLINE @@ -246,14 +246,14 @@ void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -#define tss_get __MCF_c11_tss_get +__MCF_ALIAS(tss_get, __MCF_c11_tss_get); /* 7.26.6.4 The tss_set function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT; -#define tss_set __MCF_c11_tss_set +__MCF_ALIAS(tss_set, __MCF_c11_tss_set); /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also diff --git a/src/fwd.h b/src/fwd.h index 0dec9f6eb5..60ad64316f 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -96,6 +96,13 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE #endif +/* Define a macro to alias functions, in order to prevent DLL hells. */ +#ifdef __cplusplus +# define __MCF_ALIAS(alias, target) static __typeof__(target)& alias = (target) +#else +# define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) +#endif + /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ #ifdef __cplusplus diff --git a/src/gthr.h b/src/gthr.h index 71bbfd8b79..b817c2226f 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -47,28 +47,28 @@ int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); -#define __gthread_active_p __MCF_gthr_active_p +__MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); /* Performs one-time initialization, like `pthread_once()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc); -#define __gthread_once __MCF_gthr_once +__MCF_ALIAS(__gthread_once, __MCF_gthr_once); /* Allocates a thread-specific key, like `pthread_key_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; -#define __gthread_key_create __MCF_gthr_key_create +__MCF_ALIAS(__gthread_key_create, __MCF_gthr_key_create); /* Destroys a thread-specific key, like `pthread_key_delete()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT; -#define __gthread_key_delete __MCF_gthr_key_delete +__MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); /* Gets a thread-specific value, like `pthread_getspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE @@ -76,77 +76,77 @@ void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); -#define __gthread_getspecific __MCF_gthr_getspecific +__MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); /* Sets a thread-specific value, like `pthread_setspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT; -#define __gthread_setspecific __MCF_gthr_setspecific +__MCF_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); /* Initializes a mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_mutex_init __MCF_gthr_mutex_init +__MCF_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); /* Destroys a mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_mutex_destroy __MCF_gthr_mutex_destroy +__MCF_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); /* Locks a mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_mutex_lock __MCF_gthr_mutex_lock +__MCF_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); /* Tries locking a mutex without blocking, like `pthread_mutex_trylock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_mutex_trylock __MCF_gthr_mutex_trylock +__MCF_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); /* Tries locking a mutex until a time point, like `pthread_mutex_timedlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -#define __gthread_mutex_timedlock __MCF_gthr_mutex_timedlock +__MCF_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); /* Unlocks a mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_mutex_unlock __MCF_gthr_mutex_unlock +__MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_init __MCF_gthr_recursive_mutex_init +__MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); /* Destroys a recursive mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_destroy __MCF_gthr_recursive_mutex_destroy +__MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_lock __MCF_gthr_recursive_mutex_lock +__MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); /* Tries locking a recursive mutex without blocking, like * `pthread_mutex_trylock()`. */ @@ -154,7 +154,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_trylock __MCF_gthr_recursive_mutex_trylock +__MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); /* Tries locking a recursive mutex until a time point, like * `pthread_mutex_timedlock()`. */ @@ -162,14 +162,14 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_timedlock __MCF_gthr_recursive_mutex_timedlock +__MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -#define __gthread_recursive_mutex_unlock __MCF_gthr_recursive_mutex_unlock +__MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); /* Initializes a condition variable, like `pthread_cond_init()`. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -177,7 +177,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -#define __gthread_cond_init __MCF_gthr_cond_init +__MCF_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); /* Destroys a condition variable. This function does nothing. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -185,21 +185,21 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -#define __gthread_cond_destroy __MCF_gthr_cond_destroy +__MCF_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT; -#define __gthread_cond_wait __MCF_gthr_cond_wait +__MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; -#define __gthread_cond_wait_recursive __MCF_gthr_cond_wait_recursive +__MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); /* Waits for a condition variable until a time point, like * `pthread_cond_timedwait()`. */ @@ -207,7 +207,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; -#define __gthread_cond_timedwait __MCF_gthr_cond_timedwait +__MCF_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); /* Signals at most one thread that is waiting on the condition variable, like * `pthread_cond_signal()`. */ @@ -215,7 +215,7 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -#define __gthread_cond_signal __MCF_gthr_cond_signal +__MCF_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); /* Signals all threads that are waiting on the condition variable, like * `pthread_cond_broadcast()`. */ @@ -223,28 +223,28 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT; -#define __gthread_cond_broadcast __MCF_gthr_cond_broadcast +__MCF_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); /* Creates a thread, like `pthread_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT; -#define __gthread_create __MCF_gthr_create_v2 +__MCF_ALIAS(__gthread_create, __MCF_gthr_create_v2); /* Awaits a thread to terminate and gets its result, like `pthread_join()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT; -#define __gthread_join __MCF_gthr_join_v2 +__MCF_ALIAS(__gthread_join, __MCF_gthr_join_v2); /* Detaches a thread, like `pthread_detach()` */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT; -#define __gthread_detach __MCF_gthr_detach_v2 +__MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by @@ -254,7 +254,7 @@ __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); -#define __gthread_self __MCF_gthr_self +__MCF_ALIAS(__gthread_self, __MCF_gthr_self); /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) @@ -262,14 +262,14 @@ int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); -#define __gthread_equal __MCF_gthr_equal +__MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); /* Gives up the current time slice, like `sched_yield()`. */ __MCF_DECLSPEC_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT; -#define __gthread_yield __MCF_gthr_yield +__MCF_ALIAS(__gthread_yield, __MCF_gthr_yield); /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also From f8d0de285cb2069ef3c64927d47c0dbb376af96c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 13:27:30 +0800 Subject: [PATCH 050/133] fwd: Reorder `__MCF_UNREACHABLE` (cherry picked from commit e2a492b4ec0395835f3ae4403c99f2b62401ff5e) Signed-off-by: LIU Hao --- src/fwd.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 60ad64316f..24dfaf6c15 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -90,6 +90,12 @@ # define __MCF_C_DECLARATIONS_END } /* extern "C" */ #endif +#ifdef __MCF_DEBUG +# define __MCF_UNREACHABLE __MCF_runtime_failure(__FUNCTION__) +#else +# define __MCF_UNREACHABLE __builtin_unreachable() +#endif + __MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_FWD_IMPORT # define __MCF_DECLSPEC_FWD_IMPORT @@ -113,12 +119,6 @@ extern "C++" template<> struct __MCF_static_assert { char __unused; }; # define __MCF_STATIC_ASSERT(...) ((int) sizeof(struct { char: 1|-!(__VA_ARGS__); }) - 1) #endif -#ifdef __MCF_DEBUG -# define __MCF_UNREACHABLE __MCF_runtime_failure(__FUNCTION__) -#else -# define __MCF_UNREACHABLE __builtin_unreachable() -#endif - /* The `__MCF_ASSERT()` and `__MCF_CHECK()` macros perform run-time checks. If * an argument yields false, `__MCF_ASSERT()` results in undefined behavior, * and `__MCF_CHECK()` effects abnormal termination of the current program. */ From e7ddf906defdbf68f332e7b644111f2d730c4cf6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 13:27:46 +0800 Subject: [PATCH 051/133] fwd: Provide `__MCF_ALIAS` in assembly (cherry picked from commit b957394eab0b8abb36b55c8e9e7a2629267a880a) Signed-off-by: LIU Hao --- src/fwd.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 24dfaf6c15..7cd913fe93 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -103,11 +103,10 @@ __MCF_C_DECLARATIONS_BEGIN #endif /* Define a macro to alias functions, in order to prevent DLL hells. */ -#ifdef __cplusplus -# define __MCF_ALIAS(alias, target) static __typeof__(target)& alias = (target) -#else -# define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) -#endif +#define __MCF_ALIAS(alias, target) \ + extern __typeof__(target) alias __attribute__((__copy__(target))); \ + __asm__(".set " __MINGW64_STRINGIFY(__MINGW_USYMBOL(alias)) ", " \ + __MINGW64_STRINGIFY(__MINGW_USYMBOL(target)) "\n") /* no semicolon */ /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ From 82a15620dd2e3d6c6a7ccd1f8734e49c5e77865d Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 14:44:33 +0800 Subject: [PATCH 052/133] fwd: Do name aliases directly (cherry picked from commit 78e89f4573aa9ac43ebfd3f9b7f2b74ffead7abd) Signed-off-by: LIU Hao --- src/fwd.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 7cd913fe93..04bfbcfc9a 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -104,9 +104,9 @@ __MCF_C_DECLARATIONS_BEGIN /* Define a macro to alias functions, in order to prevent DLL hells. */ #define __MCF_ALIAS(alias, target) \ - extern __typeof__(target) alias __attribute__((__copy__(target))); \ - __asm__(".set " __MINGW64_STRINGIFY(__MINGW_USYMBOL(alias)) ", " \ - __MINGW64_STRINGIFY(__MINGW_USYMBOL(target)) "\n") /* no semicolon */ + extern __typeof__(target) alias \ + __asm__(__MINGW64_STRINGIFY(__MINGW_USYMBOL(target))) \ + __attribute__((__copy__(target))) /* no semicolon */ /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ From ed66153603b33d81d164d756a9933437294a6287 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 28 Oct 2022 16:53:35 +0800 Subject: [PATCH 053/133] fwd: Use `__MINGW_ASM_CALL` (cherry picked from commit ad1df18fdbc0c1c6abc9b53420d0e7d0ad1c21bb) Signed-off-by: LIU Hao --- src/fwd.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 04bfbcfc9a..a8fdb2cbe3 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -104,8 +104,7 @@ __MCF_C_DECLARATIONS_BEGIN /* Define a macro to alias functions, in order to prevent DLL hells. */ #define __MCF_ALIAS(alias, target) \ - extern __typeof__(target) alias \ - __asm__(__MINGW64_STRINGIFY(__MINGW_USYMBOL(target))) \ + extern __typeof__(target) alias __MINGW_ASM_CALL(target) \ __attribute__((__copy__(target))) /* no semicolon */ /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it From 9f2ba7435e67afd62dd7ad5b477fa09ce94743c7 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 29 Oct 2022 00:31:38 +0800 Subject: [PATCH 054/133] xglobals,thread: Rename nullable pointer parameters (cherry picked from commit decd9bb51140e3aa2cc4a2fb08db3df89c23fc09) Signed-off-by: LIU Hao --- src/thread.c | 6 +++--- src/thread.h | 2 +- src/xglobals.i | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/thread.c b/src/thread.c index 3ba75c2495..8701bdd240 100644 --- a/src/thread.c +++ b/src/thread.c @@ -98,15 +98,15 @@ _MCF_thread_exit(void) __MCF_DLLEXPORT int -_MCF_thread_wait(const _MCF_thread* thrd, const int64_t* timeout_opt) +_MCF_thread_wait(const _MCF_thread* thrd_opt, const int64_t* timeout_opt) { - if(!thrd) + if(!thrd_opt) return -1; __MCF_winnt_timeout nt_timeout; __MCF_initialize_winnt_timeout_v2(&nt_timeout, timeout_opt); - NTSTATUS status = NtWaitForSingleObject(thrd->__handle, false, nt_timeout.__li); + NTSTATUS status = NtWaitForSingleObject(thrd_opt->__handle, false, nt_timeout.__li); __MCF_ASSERT(NT_SUCCESS(status)); return (status != STATUS_WAIT_0) ? -1 : 0; } diff --git a/src/thread.h b/src/thread.h index aa6081aac8..deeb6b686f 100644 --- a/src/thread.h +++ b/src/thread.h @@ -103,7 +103,7 @@ _MCF_thread_exit(void) __MCF_NOEXCEPT * timed out. */ __MCF_DECLSPEC_THREAD_IMPORT int -_MCF_thread_wait(const _MCF_thread* __thrd, const int64_t* __timeout_opt) __MCF_NOEXCEPT; +_MCF_thread_wait(const _MCF_thread* __thrd_opt, const int64_t* __timeout_opt) __MCF_NOEXCEPT; /* Gets a non-owning pointer to the current thread object. * diff --git a/src/xglobals.i b/src/xglobals.i index 51e84ce8ca..114ecfd859 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -238,7 +238,7 @@ __MCF_msize(const void* __ptr) __MCF_NOEXCEPT /* Free a block of memory, like `free()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE void -__MCF_mfree(void* __ptr) __MCF_NOEXCEPT; +__MCF_mfree(void* __ptr_opt) __MCF_NOEXCEPT; /* These functions set the last error code and return the second argument. * They should be subject to tail-call optimization. */ @@ -407,15 +407,15 @@ __MCF_msize(const void* __ptr) __MCF_NOEXCEPT __MCF_DECLSPEC_XGLOBALS_INLINE void -__MCF_mfree(void* __ptr) __MCF_NOEXCEPT +__MCF_mfree(void* __ptr_opt) __MCF_NOEXCEPT { - if(!__ptr) + if(!__ptr_opt) return; #ifdef __MCF_DEBUG - __MCF_mfill(__ptr, 0xFE, HeapSize(GetProcessHeap(), 0, __ptr)); + __MCF_mfill(__ptr_opt, 0xFE, HeapSize(GetProcessHeap(), 0, __ptr_opt)); #endif - int __succ = HeapFree(GetProcessHeap(), 0, __ptr); + int __succ = HeapFree(GetProcessHeap(), 0, __ptr_opt); __MCF_ASSERT(__succ); } From 515ec9e882e8dbf338b822f4f36cf695ad4fdf69 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 29 Oct 2022 00:56:35 +0800 Subject: [PATCH 055/133] fwd: Remove `__MINGW_ASM_CALL` It seems to be too new. (cherry picked from commit 42a5391910b1a7a9e73558ec9be8c4bc29b3ad40) Signed-off-by: LIU Hao --- src/fwd.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index a8fdb2cbe3..86a8584370 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -73,6 +73,8 @@ #define __MCF_0_INIT {__MCF_C(0)} #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * __CHAR_BIT__) #define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) +#define __MCF_SX(...) #__VA_ARGS__ +#define __MCF_S(...) __MCF_SX(__VA_ARGS__) #ifndef __cplusplus # define __MCF_NOEXCEPT @@ -104,8 +106,8 @@ __MCF_C_DECLARATIONS_BEGIN /* Define a macro to alias functions, in order to prevent DLL hells. */ #define __MCF_ALIAS(alias, target) \ - extern __typeof__(target) alias __MINGW_ASM_CALL(target) \ - __attribute__((__copy__(target))) /* no semicolon */ + extern __typeof__(target) alias __asm__(__MCF_S(__USER_LABEL_PREFIX__) #target) \ + __attribute__((__copy__(target))) /* no semicolon */ /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ From d7996466e97ce45da23a679b39f0d333cf371462 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 29 Oct 2022 20:12:30 +0800 Subject: [PATCH 056/133] fwd: Reformat macros (cherry picked from commit 768b15b361036341a8c14775bd24a2fc21f6042e) Signed-off-by: LIU Hao --- src/fwd.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 86a8584370..92a4eeac4e 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -67,14 +67,14 @@ # #endif /* __cplusplus */ -#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) #define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) #define __MCF_NEVER_INLINE __attribute__((__noinline__)) -#define __MCF_0_INIT {__MCF_C(0)} +#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) +#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * __CHAR_BIT__) -#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) -#define __MCF_SX(...) #__VA_ARGS__ -#define __MCF_S(...) __MCF_SX(__VA_ARGS__) +#define __MCF_0_INIT {__MCF_C(0)} +#define __MCF_SX(...) #__VA_ARGS__ +#define __MCF_S(...) __MCF_SX(__VA_ARGS__) #ifndef __cplusplus # define __MCF_NOEXCEPT From 76ebf4ed5011c41f2206b91c48061547a1b4ad98 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 29 Oct 2022 22:13:10 +0800 Subject: [PATCH 057/133] build: Bump ABI version Signed-off-by: LIU Hao --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d15d717a64..2fdfceebf4 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) ## Define ABI information AS_VAR_SET([abi_major], [1]) AS_VAR_SET([abi_minor], [2]) -AS_VAR_SET([abi_suffix], [ga.1]) +AS_VAR_SET([abi_suffix], [ga.2]) ## Check for assertions AC_ARG_ENABLE([debug-checks], AS_HELP_STRING([--enable-debug-checks], [enable assertions])) From dd02e6d6d15e2fb5d070ec6776f1ade040a35641 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 29 Oct 2022 23:14:14 +0800 Subject: [PATCH 058/133] build: Use `-fasynchronous-unwind-tables` in place of `-funwind-tables` for debugging (cherry picked from commit 7cba33c363305a022cca3200a84783338da336b1) Signed-off-by: LIU Hao --- src/Makefile.inc.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.inc.am b/src/Makefile.inc.am index 60ac60264c..94a7b03b70 100644 --- a/src/Makefile.inc.am +++ b/src/Makefile.inc.am @@ -51,7 +51,7 @@ lib_libmcfgthread_la_SOURCES = \ ${AM_V_GEN}${LIBTOOL} ${AM_V_lt} --tag=RC --mode=compile ${RC} ${DEFAULT_INCLUDES} ${AM_RCFLAGS} ${RCFLAGS} $< -o $@ lib_libmcfgthread_la_CFLAGS = \ - ${AM_CFLAGS} -nostdlib -f{freestanding,unwind-tables} + ${AM_CFLAGS} -nostdlib -f{freestanding,asynchronous-unwind-tables} lib_libmcfgthread_la_LIBADD = \ -lkernel32 -lntdll From bb33ec9780931048250e76078657be7bb127c5b2 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:22:05 +0800 Subject: [PATCH 059/133] fwd: Reorder macros (cherry picked from commit 8f4e51ce365f43499006ead26c28241bd53d3878) Signed-off-by: LIU Hao --- src/fwd.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 92a4eeac4e..bad37e7d87 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -67,15 +67,16 @@ # #endif /* __cplusplus */ -#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) -#define __MCF_NEVER_INLINE __attribute__((__noinline__)) -#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) #define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * __CHAR_BIT__) #define __MCF_0_INIT {__MCF_C(0)} #define __MCF_SX(...) #__VA_ARGS__ #define __MCF_S(...) __MCF_SX(__VA_ARGS__) +#define __MCF_ALWAYS_INLINE __MCF_GNU_INLINE __attribute__((__always_inline__, __artificial__)) +#define __MCF_NEVER_INLINE __attribute__((__noinline__)) +#define __MCF_GNU_INLINE extern __inline__ __attribute__((__gnu_inline__)) + #ifndef __cplusplus # define __MCF_NOEXCEPT #elif __cplusplus < 201103L From aad6e618fabd657a10c133d0aa32684f9a5dafb7 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:24:21 +0800 Subject: [PATCH 060/133] *: Reformat attributes (cherry picked from commit 6c37a0882296b7203775fae294afb6af6464a56f) Signed-off-by: LIU Hao --- src/c11.h | 12 ++++-------- src/exit.h | 9 +++------ src/fwd.h | 6 ++---- src/gthr.h | 12 ++++-------- src/gthr_aux.h | 3 +-- src/thread.h | 21 +++++++-------------- src/tls.h | 3 +-- src/xglobals.c | 3 +-- src/xglobals.i | 12 ++++-------- 9 files changed, 27 insertions(+), 54 deletions(-) diff --git a/src/c11.h b/src/c11.h index 9650a143bc..59f5d40639 100644 --- a/src/c11.h +++ b/src/c11.h @@ -177,8 +177,7 @@ __MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); /* 7.26.5.2 The thrd_current function */ __MCF_DECLSPEC_C11_INLINE thrd_t -__MCF_c11_thrd_current(void) __MCF_NOEXCEPT - __attribute__((__const__, __returns_nonnull__)); +__MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); __MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); @@ -192,16 +191,14 @@ __MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); /* 7.26.5.4 The thrd_equal function */ __MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) int -__MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); __MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); /* 7.26.5.5 The thrd_exit function */ __MCF_DECLSPEC_C11_INLINE void -__MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT - __attribute__((__noreturn__)); +__MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); __MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); @@ -243,8 +240,7 @@ __MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); /* 7.26.6.3 The tss_get function */ __MCF_DECLSPEC_C11_INLINE void* -__MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); __MCF_ALIAS(tss_get, __MCF_c11_tss_get); diff --git a/src/exit.h b/src/exit.h index b5767f2f45..42d7ab4e16 100644 --- a/src/exit.h +++ b/src/exit.h @@ -16,18 +16,15 @@ __MCF_C_DECLARATIONS_BEGIN /* Declare 'real' functions here. */ __MCF_DECLSPEC_EXIT_IMPORT void -__MCF__Exit(int __status) __MCF_NOEXCEPT - __attribute__((__noreturn__)); +__MCF__Exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); __MCF_DECLSPEC_EXIT_IMPORT void -__MCF_quick_exit(int __status) __MCF_NOEXCEPT - __attribute__((__noreturn__)); +__MCF_quick_exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); __MCF_DECLSPEC_EXIT_IMPORT void -__MCF_exit(int __status) __MCF_NOEXCEPT - __attribute__((__noreturn__)); +__MCF_exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); __MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_EXIT_ */ diff --git a/src/fwd.h b/src/fwd.h index bad37e7d87..c858f2ffb8 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -182,13 +182,11 @@ _MCF_maxz(size_t __x, size_t __y) __MCF_NOEXCEPT __MCF_DECLSPEC_FWD_IMPORT void -__MCF_runtime_failure(const char* __where) - __attribute__((__noreturn__, __noinline__, __cold__)); +__MCF_runtime_failure(const char* __where) __attribute__((__noreturn__, __noinline__, __cold__)); __MCF_DECLSPEC_FWD_IMPORT uint32_t -_MCF_get_win32_error(void) __MCF_NOEXCEPT - __attribute__((__pure__)); +_MCF_get_win32_error(void) __MCF_NOEXCEPT __attribute__((__pure__)); __MCF_C_DECLARATIONS_END #endif /* __MCFGTHREAD_FWD_ */ diff --git a/src/gthr.h b/src/gthr.h index b817c2226f..f975ffa898 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -44,8 +44,7 @@ typedef __MCF_gthr_rc_mutex __gthread_recursive_mutex_t; * cannot be disabled. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) int -__MCF_gthr_active_p(void) __MCF_NOEXCEPT - __attribute__((__const__)); +__MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); __MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); @@ -73,8 +72,7 @@ __MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); /* Gets a thread-specific value, like `pthread_getspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE void* -__MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); __MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); @@ -251,16 +249,14 @@ __MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); * `__gthread_create()`. Otherwise the behavior is undefined. */ __MCF_DECLSPEC_GTHR_INLINE __gthread_t -__MCF_gthr_self(void) __MCF_NOEXCEPT - __attribute__((__const__, __returns_nonnull__)); +__MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); __MCF_ALIAS(__gthread_self, __MCF_gthr_self); /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) int -__MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); __MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); diff --git a/src/gthr_aux.h b/src/gthr_aux.h index 8676ddd10f..b4b78efcdc 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -51,8 +51,7 @@ __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT; * number of milliseconds since the Unix epoch, with boundary checking. */ __MCF_DECLSPEC_GTHR_AUX int64_t -__MCF_gthr_timeout_from_timespec(const struct timespec* __abs_time) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_gthr_timeout_from_timespec(const struct timespec* __abs_time) __MCF_NOEXCEPT __attribute__((__pure__)); /* These are auxiliary functions for condition variables. The argument is a * pointer to a plain `_MCF_mutex`. */ diff --git a/src/thread.h b/src/thread.h index deeb6b686f..2f56906cec 100644 --- a/src/thread.h +++ b/src/thread.h @@ -53,8 +53,7 @@ _MCF_thread_new(_MCF_thread_procedure* __proc, const void* __data_opt, size_t __ /* Gets a pointer to user-defined data of a thread. */ __MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_CXX(const) void* -_MCF_thread_get_data(const _MCF_thread* __thrd) __MCF_NOEXCEPT - __attribute__((__pure__)); +_MCF_thread_get_data(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Adds a reference count of a thread structure. This may be useful if you * wish to pass a pointer to other code. */ @@ -76,20 +75,17 @@ _MCF_thread_drop_ref(_MCF_thread* __thrd_opt) __MCF_NOEXCEPT; /* Gets the ID of a thread. */ __MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) uint32_t -_MCF_thread_get_tid(const _MCF_thread* __thrd) __MCF_NOEXCEPT - __attribute__((__pure__)); +_MCF_thread_get_tid(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Gets the handle of a thread. */ __MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_HANDLE -_MCF_thread_get_handle(const _MCF_thread* __thrd) __MCF_NOEXCEPT - __attribute__((__pure__)); +_MCF_thread_get_handle(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Exits from a thread. */ __MCF_DECLSPEC_THREAD_IMPORT void -_MCF_thread_exit(void) __MCF_NOEXCEPT - __attribute__((__noreturn__)); +_MCF_thread_exit(void) __MCF_NOEXCEPT __attribute__((__noreturn__)); /* Waits for a thread to finish execution. * @@ -111,14 +107,12 @@ _MCF_thread_wait(const _MCF_thread* __thrd_opt, const int64_t* __timeout_opt) __ * that were created by `_MCF_thread_new()`. */ __MCF_DECLSPEC_THREAD_IMPORT _MCF_thread* -_MCF_thread_self(void) __MCF_NOEXCEPT - __attribute__((__const__)); +_MCF_thread_self(void) __MCF_NOEXCEPT __attribute__((__const__)); /* Gets the thread ID of the current thread. */ __MCF_DECLSPEC_THREAD_INLINE uint32_t -_MCF_thread_self_tid(void) __MCF_NOEXCEPT - __attribute__((__const__)); +_MCF_thread_self_tid(void) __MCF_NOEXCEPT __attribute__((__const__)); /* Gives up the current time slice. */ __MCF_DECLSPEC_THREAD_IMPORT @@ -145,8 +139,7 @@ _MCF_sleep(const int64_t* __timeout_opt) __MCF_NOEXCEPT; * a null pointer otherwise. No return value is reserved to indicate errors. */ __MCF_DECLSPEC_THREAD_INLINE void* -_MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT - __attribute__((__pure__)); +_MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT __attribute__((__pure__)); /* Sets a thread-local value. The calling thread shall have been created by * `_MCF_thread_new()`, or shall be the main thread. diff --git a/src/tls.h b/src/tls.h index 937427838b..b21817521b 100644 --- a/src/tls.h +++ b/src/tls.h @@ -72,8 +72,7 @@ _MCF_tls_key_delete(_MCF_tls_key* __key_opt) __MCF_NOEXCEPT; * otherwise. No return value is reserved to indicate errors. */ __MCF_DECLSPEC_TLS_IMPORT void* -__MCF_tls_table_get(const __MCF_tls_table* __table, const _MCF_tls_key* __key) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_tls_table_get(const __MCF_tls_table* __table, const _MCF_tls_key* __key) __MCF_NOEXCEPT __attribute__((__pure__)); /* Sets a value into the table. * diff --git a/src/xglobals.c b/src/xglobals.c index a797defe27..3fdc69d9d6 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -244,7 +244,6 @@ __MCF_dll_startup(PVOID instance, DWORD reason, PVOID reserved) * Such initialization should happen as early as possible. */ extern const PIMAGE_TLS_CALLBACK __MCF_xl_b; -const PIMAGE_TLS_CALLBACK __MCF_xl_b - __attribute__((__section__(".CRT$XLB"), __used__)) = do_image_tls_callback; +const PIMAGE_TLS_CALLBACK __MCF_xl_b __attribute__((__section__(".CRT$XLB"), __used__)) = do_image_tls_callback; #endif /* DLL_EXPORT */ diff --git a/src/xglobals.i b/src/xglobals.i index 114ecfd859..4b98757bd3 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -212,28 +212,24 @@ __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT; /* Allocate a block of zeroed memory, like `calloc()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE void* -__MCF_malloc_0(size_t __size) __MCF_NOEXCEPT - __attribute__((__warn_unused_result__, __malloc__, __alloc_size__(1))); +__MCF_malloc_0(size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __malloc__, __alloc_size__(1))); /* Re-allocate a block of memory, like `realloc()`. If the existent * block should be extended, vacuum bytes are filled with zeroes. */ __MCF_DECLSPEC_XGLOBALS_INLINE void* -__MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT - __attribute__((__warn_unused_result__, __alloc_size__(2))); +__MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __alloc_size__(2))); /* Allocate a copy of a block of memory, like `malloc()` followed by * `memcpy()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE void* -__MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT - __attribute__((__warn_unused_result__, __alloc_size__(2))); +__MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __alloc_size__(2))); /* Get the size of an allocated block, like `malloc_usable_size()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE size_t -__MCF_msize(const void* __ptr) __MCF_NOEXCEPT - __attribute__((__pure__)); +__MCF_msize(const void* __ptr) __MCF_NOEXCEPT __attribute__((__pure__)); /* Free a block of memory, like `free()`. */ __MCF_DECLSPEC_XGLOBALS_INLINE From 489e35cf6c87c0791af2db5bb15def169e303363 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:26:32 +0800 Subject: [PATCH 061/133] xglobals: Reorder macros (cherry picked from commit 9b2439086b4897100d74f53157880b0c2dd99840) Signed-off-by: LIU Hao --- src/xglobals.i | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index 4b98757bd3..807b20e023 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -44,10 +44,6 @@ extern __MCF_dtor_queue __MCF_cxa_at_quick_exit_queue; extern _MCF_cond __MCF_interrupt_cond; extern BYTE __MCF_mutex_spin_field[2048]; -/* Hard-code these. */ -#define GetCurrentProcess() ((HANDLE) -1) -#define GetCurrentThread() ((HANDLE) -2) - /* Undefine macros that redirect to standard functions. * This ensures we call the ones from KERNEL32. */ #undef RtlCopyMemory @@ -57,12 +53,14 @@ extern BYTE __MCF_mutex_spin_field[2048]; #undef RtlCompareMemory #undef RtlEqualMemory -#define __MCF_WINAPI(RETURN, function, ...) \ - RETURN __stdcall function(__VA_ARGS__) \ - __attribute__((__dllimport__, __nothrow__)) +/* Hard-code these. */ +#define GetCurrentProcess() ((HANDLE) -1) +#define GetCurrentThread() ((HANDLE) -2) -#define __MCF_CHECK_NT(...) \ - __MCF_CHECK(NT_SUCCESS(__VA_ARGS__)) +#define __MCF_CHECK_NT(...) __MCF_CHECK(NT_SUCCESS(__VA_ARGS__)) + +#define __MCF_WINAPI(RETURN, function, ...) \ + RETURN __stdcall function(__VA_ARGS__) __attribute__((__dllimport__, __nothrow__)) /* Declare KERNEL32 APIs here. */ __MCF_WINAPI(DWORD, GetLastError, void) __attribute__((__pure__)); From 5460c9a03697ead89dc8fc5b643023f9afbd0dac Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:56:43 +0800 Subject: [PATCH 062/133] fwd: Revert to the old `__MCF_ALIAS` (cherry picked from commit 15dd0c32fb15347b4b69c4673ea0532da7880d00) Signed-off-by: LIU Hao --- src/fwd.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index c858f2ffb8..325fdf52a3 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -105,10 +105,14 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE #endif -/* Define a macro to alias functions, in order to prevent DLL hells. */ -#define __MCF_ALIAS(alias, target) \ - extern __typeof__(target) alias __asm__(__MCF_S(__USER_LABEL_PREFIX__) #target) \ - __attribute__((__copy__(target))) /* no semicolon */ +/* Define a macro for aliasing functions, in order to prevent DLL hells. This + * is probably not a perfect solution for C, but at least it allows aliases to + * be inlined. */ +#ifdef __cplusplus +# define __MCF_ALIAS(alias, target) static __typeof__(target)& alias = (target) +#else +# define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) +#endif /* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ From 893f3acffd3b44240c551585f552f6d7bdc14071 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:56:54 +0800 Subject: [PATCH 063/133] fwd: Compact `__MCF_STATIC_ASSERT` (cherry picked from commit de0f79c7d1dfa20b46a6f3b7eef0708588ca7f75) Signed-off-by: LIU Hao --- src/fwd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index 325fdf52a3..5e501ae8fb 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -119,9 +119,9 @@ __MCF_C_DECLARATIONS_BEGIN #ifdef __cplusplus extern "C++" template struct __MCF_static_assert; extern "C++" template<> struct __MCF_static_assert { char __unused; }; -# define __MCF_STATIC_ASSERT(...) ((int) sizeof(__MCF_static_assert<(__VA_ARGS__)>) - 1) +# define __MCF_STATIC_ASSERT(...) ((int) sizeof(::__MCF_static_assert<(__VA_ARGS__)>)-1) #else -# define __MCF_STATIC_ASSERT(...) ((int) sizeof(struct { char: 1|-!(__VA_ARGS__); }) - 1) +# define __MCF_STATIC_ASSERT(...) ((int) sizeof(struct{char:1|-!(__VA_ARGS__);})-1) #endif /* The `__MCF_ASSERT()` and `__MCF_CHECK()` macros perform run-time checks. If From 1b1fb9f40fb414912677e51d902d6c9f90196c8a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 00:59:22 +0800 Subject: [PATCH 064/133] c11: Rename end-of-value enumerators (cherry picked from commit 4ca0546798e0965640ab58d567a5708648c7a03c) Signed-off-by: LIU Hao --- src/c11.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/c11.h b/src/c11.h index 59f5d40639..14cb0ca0a3 100644 --- a/src/c11.h +++ b/src/c11.h @@ -60,20 +60,20 @@ __MCF_c11_thread_thunk_v2(_MCF_thread* __thrd) __MCF_NOEXCEPT; /* Define enumeration constants. */ enum __MCF_mtx_type { - mtx_plain = 0, - mtx_recursive = 1, - mtx_timed = 2, - __MCF_mtx_end + mtx_plain = 0, + mtx_recursive = 1, + mtx_timed = 2, + __MCF_mtx_type_end }; enum __MCF_thrd_error { - thrd_success = 0, - thrd_busy = 1, - thrd_error = 2, - thrd_nomem = 3, - thrd_timedout = 4, - __MCF_thrd_end + thrd_success = 0, + thrd_busy = 1, + thrd_error = 2, + thrd_nomem = 3, + thrd_timedout = 4, + __MCF_thrd_error_end }; /* 7.26.2.1 The call_once function */ From 005747197ce65e3aa8817a727671c20bc91d44be Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 02:21:52 +0800 Subject: [PATCH 065/133] gthr,gthr_libobjc,c11,libcxx: Allow aliases to be disabled (cherry picked from commit 643ca26bf405d3ddd16ed43167dc299b8bbe39de) Signed-off-by: LIU Hao --- src/c11.h | 50 +++++++++++++++++++++++++++++++++++++++++++ src/gthr.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) diff --git a/src/c11.h b/src/c11.h index 14cb0ca0a3..f779e44a02 100644 --- a/src/c11.h +++ b/src/c11.h @@ -81,175 +81,225 @@ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func); +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(call_once, __MCF_c11_call_once); +#endif /* 7.26.3.1 The cnd_broadcast function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); +#endif /* 7.26.3.2 The cnd_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); +#endif /* 7.26.3.3 The cnd_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_init, __MCF_c11_cnd_init); +#endif /* 7.26.3.4 The cnd_signal function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); +#endif /* 7.26.3.5 The cnd_timedwait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); +#endif /* 7.26.3.6 The cnd_wait function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_wait, __MCF_c11_cnd_wait); +#endif /* 7.26.4.1 The mtx_destroy function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); +#endif /* 7.26.4.2 The mtx_init function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_init, __MCF_c11_mtx_init); +#endif /* 7.26.4.3 The mtx_lock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); +#endif /* 7.26.4.4 The mtx_timedlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); +#endif /* 7.26.4.5 The mtx_trylock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); +#endif /* 7.26.4.6 The mtx_unlock function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); +#endif /* 7.26.5.1 The thrd_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrd, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); +#endif /* 7.26.5.2 The thrd_current function */ __MCF_DECLSPEC_C11_INLINE thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); +#endif /* 7.26.5.3 The thrd_detach function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); +#endif /* 7.26.5.4 The thrd_equal function */ __MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); +#endif /* 7.26.5.5 The thrd_exit function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); +#endif /* 7.26.5.6 The thrd_join function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); +#endif /* 7.26.5.7 The thrd_sleep function */ __MCF_DECLSPEC_C11_IMPORT int __MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); +#endif /* 7.26.5.8 The thrd_yield function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_yield, __MCF_c11_thrd_yield); +#endif /* 7.26.6.1 The tss_create function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(tss_create, __MCF_c11_tss_create); +#endif /* 7.26.6.2 The tss_delete function */ __MCF_DECLSPEC_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); +#endif /* 7.26.6.3 The tss_get function */ __MCF_DECLSPEC_C11_INLINE void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(tss_get, __MCF_c11_tss_get); +#endif /* 7.26.6.4 The tss_set function */ __MCF_DECLSPEC_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT; +#ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(tss_set, __MCF_c11_tss_set); +#endif /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also diff --git a/src/gthr.h b/src/gthr.h index f975ffa898..34df1e17d7 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -46,105 +46,135 @@ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); +#endif /* Performs one-time initialization, like `pthread_once()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc); +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_once, __MCF_gthr_once); +#endif /* Allocates a thread-specific key, like `pthread_key_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_key_create, __MCF_gthr_key_create); +#endif /* Destroys a thread-specific key, like `pthread_key_delete()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); +#endif /* Gets a thread-specific value, like `pthread_getspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); +#endif /* Sets a thread-specific value, like `pthread_setspecific()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); +#endif /* Initializes a mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); +#endif /* Destroys a mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); +#endif /* Locks a mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); +#endif /* Tries locking a mutex without blocking, like `pthread_mutex_trylock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); +#endif /* Tries locking a mutex until a time point, like `pthread_mutex_timedlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); +#endif /* Unlocks a mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); +#endif /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); +#endif /* Destroys a recursive mutex. This function does nothing. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); +#endif /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); +#endif /* Tries locking a recursive mutex without blocking, like * `pthread_mutex_trylock()`. */ @@ -152,7 +182,9 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); +#endif /* Tries locking a recursive mutex until a time point, like * `pthread_mutex_timedlock()`. */ @@ -160,14 +192,18 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); +#endif /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); +#endif /* Initializes a condition variable, like `pthread_cond_init()`. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -175,7 +211,9 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); +#endif /* Destroys a condition variable. This function does nothing. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ @@ -183,21 +221,27 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); +#endif /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); +#endif /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); +#endif /* Waits for a condition variable until a time point, like * `pthread_cond_timedwait()`. */ @@ -205,7 +249,9 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); +#endif /* Signals at most one thread that is waiting on the condition variable, like * `pthread_cond_signal()`. */ @@ -213,7 +259,9 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); +#endif /* Signals all threads that are waiting on the condition variable, like * `pthread_cond_broadcast()`. */ @@ -221,28 +269,36 @@ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); +#endif /* Creates a thread, like `pthread_create()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_create, __MCF_gthr_create_v2); +#endif /* Awaits a thread to terminate and gets its result, like `pthread_join()`. */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_join, __MCF_gthr_join_v2); +#endif /* Detaches a thread, like `pthread_detach()` */ __MCF_DECLSPEC_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); +#endif /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by @@ -251,21 +307,27 @@ __MCF_DECLSPEC_GTHR_INLINE __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_self, __MCF_gthr_self); +#endif /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ __MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); +#endif /* Gives up the current time slice, like `sched_yield()`. */ __MCF_DECLSPEC_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT; +#ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_yield, __MCF_gthr_yield); +#endif /* Define inline functions after all declarations. * We would like to keep them away from declarations for conciseness, which also From b51f33ae385ee97dcfdb440989049c67b0d608a6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 02:25:02 +0800 Subject: [PATCH 066/133] *: Shorten `__MCF_DECLSPEC_*` macros --- src/atomic.h | 6 +-- src/c11.c | 4 +- src/c11.h | 106 +++++++++++++++++++------------------- src/clock.c | 4 +- src/clock.h | 14 ++--- src/cond.c | 4 +- src/cond.h | 26 +++++----- src/cxa.c | 4 +- src/cxa.h | 26 +++++----- src/dtor_queue.c | 2 +- src/dtor_queue.h | 2 +- src/event.c | 4 +- src/event.h | 26 +++++----- src/exit.c | 4 +- src/exit.h | 12 ++--- src/fwd.c | 4 +- src/fwd.h | 10 ++-- src/gthr.c | 4 +- src/gthr.h | 130 +++++++++++++++++++++++------------------------ src/gthr_aux.c | 2 +- src/gthr_aux.h | 6 +-- src/mutex.c | 4 +- src/mutex.h | 22 ++++---- src/once.c | 4 +- src/once.h | 20 ++++---- src/sem.c | 4 +- src/sem.h | 22 ++++---- src/thread.c | 4 +- src/thread.h | 52 +++++++++---------- src/tls.c | 4 +- src/tls.h | 20 ++++---- src/xglobals.c | 4 +- src/xglobals.i | 60 +++++++++++----------- 33 files changed, 310 insertions(+), 310 deletions(-) diff --git a/src/atomic.h b/src/atomic.h index f8ece445af..3eae677be9 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -8,9 +8,9 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_ATOMIC_IMPORT -# define __MCF_DECLSPEC_ATOMIC_IMPORT -# define __MCF_DECLSPEC_ATOMIC_INLINE __MCF_GNU_INLINE +#ifndef __MCF_ATOMIC_IMPORT +# define __MCF_ATOMIC_IMPORT +# define __MCF_ATOMIC_INLINE __MCF_GNU_INLINE #endif /* We don't use the generic builtins due to a GCC bug. diff --git a/src/c11.c b/src/c11.c index 0c3b53da8d..453d96d60a 100644 --- a/src/c11.c +++ b/src/c11.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_C11_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_C11_INLINE __MCF_DLLEXPORT +#define __MCF_C11_IMPORT __MCF_DLLEXPORT +#define __MCF_C11_INLINE __MCF_DLLEXPORT #include "c11.h" #include "clock.h" diff --git a/src/c11.h b/src/c11.h index f779e44a02..f1e6c8270f 100644 --- a/src/c11.h +++ b/src/c11.h @@ -9,9 +9,9 @@ #include "gthr_aux.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_C11_IMPORT -# define __MCF_DECLSPEC_C11_IMPORT -# define __MCF_DECLSPEC_C11_INLINE __MCF_GNU_INLINE +#ifndef __MCF_C11_IMPORT +# define __MCF_C11_IMPORT +# define __MCF_C11_INLINE __MCF_GNU_INLINE #endif /* N1570 7.26.1 Introduction */ @@ -53,7 +53,7 @@ typedef _MCF_cond cnd_t; typedef struct __MCF_c11_mutex mtx_t; /* This is the actual thread function for a C11 thread. */ -__MCF_DECLSPEC_C11_IMPORT +__MCF_C11_IMPORT void __MCF_c11_thread_thunk_v2(_MCF_thread* __thrd) __MCF_NOEXCEPT; @@ -77,7 +77,7 @@ enum __MCF_thrd_error }; /* 7.26.2.1 The call_once function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func); @@ -86,7 +86,7 @@ __MCF_ALIAS(call_once, __MCF_c11_call_once); #endif /* 7.26.3.1 The cnd_broadcast function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT; @@ -95,7 +95,7 @@ __MCF_ALIAS(cnd_broadcast, __MCF_c11_cnd_broadcast); #endif /* 7.26.3.2 The cnd_destroy function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT; @@ -104,7 +104,7 @@ __MCF_ALIAS(cnd_destroy, __MCF_c11_cnd_destroy); #endif /* 7.26.3.3 The cnd_init function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT; @@ -113,7 +113,7 @@ __MCF_ALIAS(cnd_init, __MCF_c11_cnd_init); #endif /* 7.26.3.4 The cnd_signal function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT; @@ -122,7 +122,7 @@ __MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); #endif /* 7.26.3.5 The cnd_timedwait function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; @@ -131,7 +131,7 @@ __MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); #endif /* 7.26.3.6 The cnd_wait function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT; @@ -140,7 +140,7 @@ __MCF_ALIAS(cnd_wait, __MCF_c11_cnd_wait); #endif /* 7.26.4.1 The mtx_destroy function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT; @@ -149,7 +149,7 @@ __MCF_ALIAS(mtx_destroy, __MCF_c11_mtx_destroy); #endif /* 7.26.4.2 The mtx_init function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT; @@ -158,7 +158,7 @@ __MCF_ALIAS(mtx_init, __MCF_c11_mtx_init); #endif /* 7.26.4.3 The mtx_lock function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT; @@ -167,7 +167,7 @@ __MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); #endif /* 7.26.4.4 The mtx_timedlock function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; @@ -176,7 +176,7 @@ __MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); #endif /* 7.26.4.5 The mtx_trylock function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT; @@ -185,7 +185,7 @@ __MCF_ALIAS(mtx_trylock, __MCF_c11_mtx_trylock); #endif /* 7.26.4.6 The mtx_unlock function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT; @@ -194,7 +194,7 @@ __MCF_ALIAS(mtx_unlock, __MCF_c11_mtx_unlock); #endif /* 7.26.5.1 The thrd_create function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrd, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT; @@ -203,7 +203,7 @@ __MCF_ALIAS(thrd_create, __MCF_c11_thrd_create); #endif /* 7.26.5.2 The thrd_current function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); @@ -212,7 +212,7 @@ __MCF_ALIAS(thrd_current, __MCF_c11_thrd_current); #endif /* 7.26.5.3 The thrd_detach function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT; @@ -221,7 +221,7 @@ __MCF_ALIAS(thrd_detach, __MCF_c11_thrd_detach); #endif /* 7.26.5.4 The thrd_equal function */ -__MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) +__MCF_C11_INLINE __MCF_CXX11(constexpr) int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); @@ -230,7 +230,7 @@ __MCF_ALIAS(thrd_equal, __MCF_c11_thrd_equal); #endif /* 7.26.5.5 The thrd_exit function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_thrd_exit(int __res) __MCF_NOEXCEPT __attribute__((__noreturn__)); @@ -239,7 +239,7 @@ __MCF_ALIAS(thrd_exit, __MCF_c11_thrd_exit); #endif /* 7.26.5.6 The thrd_join function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT; @@ -248,7 +248,7 @@ __MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); #endif /* 7.26.5.7 The thrd_sleep function */ -__MCF_DECLSPEC_C11_IMPORT +__MCF_C11_IMPORT int __MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; @@ -257,7 +257,7 @@ __MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); #endif /* 7.26.5.8 The thrd_yield function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT; @@ -266,7 +266,7 @@ __MCF_ALIAS(thrd_yield, __MCF_c11_thrd_yield); #endif /* 7.26.6.1 The tss_create function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT; @@ -275,7 +275,7 @@ __MCF_ALIAS(tss_create, __MCF_c11_tss_create); #endif /* 7.26.6.2 The tss_delete function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT; @@ -284,7 +284,7 @@ __MCF_ALIAS(tss_delete, __MCF_c11_tss_delete); #endif /* 7.26.6.3 The tss_get function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); @@ -293,7 +293,7 @@ __MCF_ALIAS(tss_get, __MCF_c11_tss_get); #endif /* 7.26.6.4 The tss_set function */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT; @@ -306,7 +306,7 @@ __MCF_ALIAS(tss_set, __MCF_c11_tss_set); * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func) { @@ -321,7 +321,7 @@ __MCF_c11_call_once(once_flag* __flag, __MCF_once_callback* __init_func) _MCF_once_release(__flag); } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT { @@ -329,14 +329,14 @@ __MCF_c11_cnd_broadcast(cnd_t* __cond) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_cnd_destroy(cnd_t* __cond) __MCF_NOEXCEPT { (void) __cond; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT { @@ -344,7 +344,7 @@ __MCF_c11_cnd_init(cnd_t* __cond) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT { @@ -352,7 +352,7 @@ __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT { @@ -361,7 +361,7 @@ __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts return (__err != 0) ? thrd_timedout : thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT { @@ -370,14 +370,14 @@ __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_mtx_destroy(mtx_t* __mtx) __MCF_NOEXCEPT { (void) __mtx; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT { @@ -417,7 +417,7 @@ __MCF_c11_mtx_check_recursion(mtx_t* __mtx) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT { @@ -430,7 +430,7 @@ __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT { @@ -449,7 +449,7 @@ __MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEP return (__err != 0) ? thrd_timedout : thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT { @@ -465,7 +465,7 @@ __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT return (__err != 0) ? thrd_busy : thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT { @@ -473,7 +473,7 @@ __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_create(thrd_t* __thrdp, thrd_start_t __proc, void* __arg) __MCF_NOEXCEPT { @@ -489,7 +489,7 @@ __MCF_c11_thrd_create(thrd_t* __thrdp, thrd_start_t __proc, void* __arg) __MCF_N return (__thrd == NULL) ? thrd_nomem : thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE thrd_t __MCF_c11_thrd_current(void) __MCF_NOEXCEPT { @@ -498,7 +498,7 @@ __MCF_c11_thrd_current(void) __MCF_NOEXCEPT return __self; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT { @@ -519,14 +519,14 @@ __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE __MCF_CXX11(constexpr) +__MCF_C11_INLINE __MCF_CXX11(constexpr) int __MCF_c11_thrd_equal(thrd_t __t1, thrd_t __t2) __MCF_NOEXCEPT { return __t1 == __t2; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_thrd_exit(int __result) __MCF_NOEXCEPT { @@ -546,7 +546,7 @@ __MCF_c11_thrd_exit(int __result) __MCF_NOEXCEPT _MCF_thread_exit(); } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT { @@ -578,14 +578,14 @@ __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT return thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_thrd_yield(void) __MCF_NOEXCEPT { _MCF_yield(); } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT { @@ -594,21 +594,21 @@ __MCF_c11_tss_create(tss_t* __keyp, tss_dtor_t __dtor_opt) __MCF_NOEXCEPT return (__key == NULL) ? thrd_nomem : thrd_success; } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void __MCF_c11_tss_delete(tss_t __key) __MCF_NOEXCEPT { _MCF_tls_key_delete(__key); } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE void* __MCF_c11_tss_get(tss_t __key) __MCF_NOEXCEPT { return _MCF_tls_get(__key); } -__MCF_DECLSPEC_C11_INLINE +__MCF_C11_INLINE int __MCF_c11_tss_set(tss_t __key, void* __val_opt) __MCF_NOEXCEPT { diff --git a/src/clock.c b/src/clock.c index 91ee3a42fb..7a270e79e6 100644 --- a/src/clock.c +++ b/src/clock.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_CLOCK_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_CLOCK_INLINE __MCF_DLLEXPORT +#define __MCF_CLOCK_IMPORT __MCF_DLLEXPORT +#define __MCF_CLOCK_INLINE __MCF_DLLEXPORT #include "clock.h" #include "xglobals.i" diff --git a/src/clock.h b/src/clock.h index a4f180edca..23c5da90f3 100644 --- a/src/clock.h +++ b/src/clock.h @@ -8,29 +8,29 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_CLOCK_IMPORT -# define __MCF_DECLSPEC_CLOCK_IMPORT -# define __MCF_DECLSPEC_CLOCK_INLINE __MCF_GNU_INLINE +#ifndef __MCF_CLOCK_IMPORT +# define __MCF_CLOCK_IMPORT +# define __MCF_CLOCK_INLINE __MCF_GNU_INLINE #endif /* Get the number of milliseconds since 1970-01-01T00:00:00Z. */ -__MCF_DECLSPEC_CLOCK_IMPORT +__MCF_CLOCK_IMPORT int64_t _MCF_utc_now(void) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CLOCK_IMPORT +__MCF_CLOCK_IMPORT double _MCF_hires_utc_now(void) __MCF_NOEXCEPT; /* Get the number of milliseconds since system startup. * This value is monotonic. */ -__MCF_DECLSPEC_CLOCK_IMPORT +__MCF_CLOCK_IMPORT int64_t _MCF_tick_count(void) __MCF_NOEXCEPT; /* Get the value of the performance counter in milliseconds. * This value is monotonic. */ -__MCF_DECLSPEC_CLOCK_IMPORT +__MCF_CLOCK_IMPORT double _MCF_perf_counter(void) __MCF_NOEXCEPT; diff --git a/src/cond.c b/src/cond.c index 95d003ee5d..d1fc7d604f 100644 --- a/src/cond.c +++ b/src/cond.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_COND_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_COND_INLINE __MCF_DLLEXPORT +#define __MCF_COND_IMPORT __MCF_DLLEXPORT +#define __MCF_COND_INLINE __MCF_DLLEXPORT #include "cond.h" #include "xglobals.i" diff --git a/src/cond.h b/src/cond.h index beb2029518..57f00d6e58 100644 --- a/src/cond.h +++ b/src/cond.h @@ -9,9 +9,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_COND_IMPORT -# define __MCF_DECLSPEC_COND_IMPORT -# define __MCF_DECLSPEC_COND_INLINE __MCF_GNU_INLINE +#ifndef __MCF_COND_IMPORT +# define __MCF_COND_IMPORT +# define __MCF_COND_INLINE __MCF_GNU_INLINE #endif /* Define the condition variable struct. @@ -26,7 +26,7 @@ struct __MCF_cond /* Initializes a condition variable dynamically. * Static ones should be initialized with `{0}`, like other structs. */ -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE void _MCF_cond_init(_MCF_cond* __cond) __MCF_NOEXCEPT; @@ -48,7 +48,7 @@ _MCF_cond_init(_MCF_cond* __cond) __MCF_NOEXCEPT; * * Returns 0 if the condition variable has been signaled or there is a spurious * wakeup, or -1 if the wait operation has timed out. */ -__MCF_DECLSPEC_COND_IMPORT +__MCF_COND_IMPORT int _MCF_cond_wait(_MCF_cond* __cond, _MCF_cond_unlock_callback* __unlock_opt, _MCF_cond_relock_callback* __relock_opt, intptr_t __lock_arg, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -56,19 +56,19 @@ _MCF_cond_wait(_MCF_cond* __cond, _MCF_cond_unlock_callback* __unlock_opt, _MCF_ * variable. * * Returns the number of threads that have been woken up. */ -__MCF_DECLSPEC_COND_IMPORT +__MCF_COND_IMPORT size_t _MCF_cond_signal_some_slow(_MCF_cond* __cond, size_t __max) __MCF_NOEXCEPT; -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal_some(_MCF_cond* __cond, size_t __max) __MCF_NOEXCEPT; -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal(_MCF_cond* __cond) __MCF_NOEXCEPT; -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal_all(_MCF_cond* __cond) __MCF_NOEXCEPT; @@ -77,7 +77,7 @@ _MCF_cond_signal_all(_MCF_cond* __cond) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE void _MCF_cond_init(_MCF_cond* __cond) __MCF_NOEXCEPT { @@ -85,7 +85,7 @@ _MCF_cond_init(_MCF_cond* __cond) __MCF_NOEXCEPT _MCF_atomic_store_pptr_rel(__cond, &__temp); } -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal_some(_MCF_cond* __cond, size_t __max) __MCF_NOEXCEPT { @@ -98,14 +98,14 @@ _MCF_cond_signal_some(_MCF_cond* __cond, size_t __max) __MCF_NOEXCEPT return _MCF_cond_signal_some_slow(__cond, __max); } -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal(_MCF_cond* __cond) __MCF_NOEXCEPT { return _MCF_cond_signal_some(__cond, 1); } -__MCF_DECLSPEC_COND_INLINE +__MCF_COND_INLINE size_t _MCF_cond_signal_all(_MCF_cond* __cond) __MCF_NOEXCEPT { diff --git a/src/cxa.c b/src/cxa.c index 99c0a86bc7..95ee5ff824 100644 --- a/src/cxa.c +++ b/src/cxa.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_CXA_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_CXA_INLINE __MCF_DLLEXPORT +#define __MCF_CXA_IMPORT __MCF_DLLEXPORT +#define __MCF_CXA_INLINE __MCF_DLLEXPORT #include "cxa.h" #include "once.h" #include "mutex.h" diff --git a/src/cxa.h b/src/cxa.h index 6bf57a52eb..b0d9663410 100644 --- a/src/cxa.h +++ b/src/cxa.h @@ -8,9 +8,9 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_CXA_IMPORT -# define __MCF_DECLSPEC_CXA_IMPORT -# define __MCF_DECLSPEC_CXA_INLINE __MCF_GNU_INLINE +#ifndef __MCF_CXA_IMPORT +# define __MCF_CXA_IMPORT +# define __MCF_CXA_INLINE __MCF_GNU_INLINE #endif /* See for details about @@ -36,43 +36,43 @@ union __attribute__((__transparent_union__)) __MCF_cxa_dtor_union }; /* Declare 'real' functions here. */ -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_cxa_guard_acquire(int64_t* __guard) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT void __MCF_cxa_guard_release(int64_t* __guard) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT void __MCF_cxa_guard_abort(int64_t* __guard) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_cxa_atexit(__MCF_cxa_dtor_union __dtor, void* __this, void* __dso) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_atexit(__MCF_atexit_callback __atfn) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_cxa_at_quick_exit(__MCF_cxa_dtor_union __dtor, void* __this, void* __dso) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_at_quick_exit(__MCF_atexit_callback __atfn) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_cxa_thread_atexit(__MCF_cxa_dtor_union __dtor, void* __this, void* __dso) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT int __MCF_thread_atexit(__MCF_atexit_callback __atfn) __MCF_NOEXCEPT; -__MCF_DECLSPEC_CXA_IMPORT +__MCF_CXA_IMPORT void __MCF_cxa_finalize(void* __dso) __MCF_NOEXCEPT; diff --git a/src/dtor_queue.c b/src/dtor_queue.c index 6e1f9a56ac..f906be7b4c 100644 --- a/src/dtor_queue.c +++ b/src/dtor_queue.c @@ -4,7 +4,7 @@ #include "precompiled.i" #define __MCF_DECLSPEC_DTOR_QUEUE __MCF_DLLEXPORT -#define __MCF_DECLSPEC_DTOR_QUEUE_INLINE __MCF_DLLEXPORT +#define __MCF_DTOR_QUEUE_INLINE __MCF_DLLEXPORT #include "dtor_queue.h" #include "mutex.h" #include "xglobals.i" diff --git a/src/dtor_queue.h b/src/dtor_queue.h index 8e95fbb18b..6c719a913c 100644 --- a/src/dtor_queue.h +++ b/src/dtor_queue.h @@ -10,7 +10,7 @@ __MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_DTOR_QUEUE # define __MCF_DECLSPEC_DTOR_QUEUE -# define __MCF_DECLSPEC_DTOR_QUEUE_INLINE __MCF_GNU_INLINE +# define __MCF_DTOR_QUEUE_INLINE __MCF_GNU_INLINE #endif /* Define the cxa_atexit queue structure. */ diff --git a/src/event.c b/src/event.c index 823444f4b8..3510be97a8 100644 --- a/src/event.c +++ b/src/event.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_EVENT_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_EVENT_INLINE __MCF_DLLEXPORT +#define __MCF_EVENT_IMPORT __MCF_DLLEXPORT +#define __MCF_EVENT_INLINE __MCF_DLLEXPORT #include "event.h" #include "xglobals.i" diff --git a/src/event.h b/src/event.h index 45adc259e3..7533fc1e4b 100644 --- a/src/event.h +++ b/src/event.h @@ -9,9 +9,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_EVENT_IMPORT -# define __MCF_DECLSPEC_EVENT_IMPORT -# define __MCF_DECLSPEC_EVENT_INLINE __MCF_GNU_INLINE +#ifndef __MCF_EVENT_IMPORT +# define __MCF_EVENT_IMPORT +# define __MCF_EVENT_INLINE __MCF_GNU_INLINE #endif /* Define the event struct. @@ -41,12 +41,12 @@ struct __MCF_event * * Returns 0 if the initialization is successful, or -1 in case of invalid * arguments. */ -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_init(_MCF_event* __event, int __value_init) __MCF_NOEXCEPT; /* Gets the current value of an event. */ -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE uint8_t _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT; @@ -64,11 +64,11 @@ _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT; * * Returns 0 if the value does not equal the lowest byte of `__undesired`, or * -1 if the operation has timed out, or -2 in case of invalid arguments. */ -__MCF_DECLSPEC_EVENT_IMPORT +__MCF_EVENT_IMPORT int _MCF_event_await_change_slow(_MCF_event* __event, int __undesired, const int64_t* __timeout_opt) __MCF_NOEXCEPT; -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_await_change(_MCF_event* __event, int __undesired, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -77,11 +77,11 @@ _MCF_event_await_change(_MCF_event* __event, int __undesired, const int64_t* __t * * Returns 0 if the value has been updated successfully, or -1 in case of * invalid arguments. */ -__MCF_DECLSPEC_EVENT_IMPORT +__MCF_EVENT_IMPORT int _MCF_event_set_slow(_MCF_event* __event, int __value) __MCF_NOEXCEPT; -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_set(_MCF_event* __event, int __value) __MCF_NOEXCEPT; @@ -90,7 +90,7 @@ _MCF_event_set(_MCF_event* __event, int __value) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_init(_MCF_event* __event, int __value_init) __MCF_NOEXCEPT { @@ -102,7 +102,7 @@ _MCF_event_init(_MCF_event* __event, int __value_init) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE uint8_t _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT { @@ -111,7 +111,7 @@ _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT return __temp.__value; } -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_await_change(_MCF_event* __event, int __undesired, const int64_t* __timeout_opt) __MCF_NOEXCEPT { @@ -132,7 +132,7 @@ _MCF_event_await_change(_MCF_event* __event, int __undesired, const int64_t* __t return _MCF_event_await_change_slow(__event, __undesired, __timeout_opt); } -__MCF_DECLSPEC_EVENT_INLINE +__MCF_EVENT_INLINE int _MCF_event_set(_MCF_event* __event, int __value) __MCF_NOEXCEPT { diff --git a/src/exit.c b/src/exit.c index 24765b7411..7b9b095ac7 100644 --- a/src/exit.c +++ b/src/exit.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_EXIT_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_EXIT_INLINE __MCF_DLLEXPORT +#define __MCF_EXIT_IMPORT __MCF_DLLEXPORT +#define __MCF_EXIT_INLINE __MCF_DLLEXPORT #include "exit.h" #include "xglobals.i" diff --git a/src/exit.h b/src/exit.h index 42d7ab4e16..5540174892 100644 --- a/src/exit.h +++ b/src/exit.h @@ -8,21 +8,21 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_EXIT_IMPORT -# define __MCF_DECLSPEC_EXIT_IMPORT -# define __MCF_DECLSPEC_EXIT_INLINE __MCF_GNU_INLINE +#ifndef __MCF_EXIT_IMPORT +# define __MCF_EXIT_IMPORT +# define __MCF_EXIT_INLINE __MCF_GNU_INLINE #endif /* Declare 'real' functions here. */ -__MCF_DECLSPEC_EXIT_IMPORT +__MCF_EXIT_IMPORT void __MCF__Exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); -__MCF_DECLSPEC_EXIT_IMPORT +__MCF_EXIT_IMPORT void __MCF_quick_exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); -__MCF_DECLSPEC_EXIT_IMPORT +__MCF_EXIT_IMPORT void __MCF_exit(int __status) __MCF_NOEXCEPT __attribute__((__noreturn__)); diff --git a/src/fwd.c b/src/fwd.c index ac6d0643fd..04001151a2 100644 --- a/src/fwd.c +++ b/src/fwd.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_FWD_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_FWD_INLINE __MCF_DLLEXPORT +#define __MCF_FWD_IMPORT __MCF_DLLEXPORT +#define __MCF_FWD_INLINE __MCF_DLLEXPORT #include "fwd.h" #include "xglobals.i" diff --git a/src/fwd.h b/src/fwd.h index 5e501ae8fb..481628736b 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -100,9 +100,9 @@ #endif __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_FWD_IMPORT -# define __MCF_DECLSPEC_FWD_IMPORT -# define __MCF_DECLSPEC_FWD_INLINE __MCF_GNU_INLINE +#ifndef __MCF_FWD_IMPORT +# define __MCF_FWD_IMPORT +# define __MCF_FWD_INLINE __MCF_GNU_INLINE #endif /* Define a macro for aliasing functions, in order to prevent DLL hells. This @@ -184,11 +184,11 @@ _MCF_maxz(size_t __x, size_t __y) __MCF_NOEXCEPT return (__x < __y) ? __y : __x; } -__MCF_DECLSPEC_FWD_IMPORT +__MCF_FWD_IMPORT void __MCF_runtime_failure(const char* __where) __attribute__((__noreturn__, __noinline__, __cold__)); -__MCF_DECLSPEC_FWD_IMPORT +__MCF_FWD_IMPORT uint32_t _MCF_get_win32_error(void) __MCF_NOEXCEPT __attribute__((__pure__)); diff --git a/src/gthr.c b/src/gthr.c index 26610a6bac..f3dc2ba69d 100644 --- a/src/gthr.c +++ b/src/gthr.c @@ -3,6 +3,6 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_GTHR_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_GTHR_INLINE __MCF_DLLEXPORT +#define __MCF_GTHR_IMPORT __MCF_DLLEXPORT +#define __MCF_GTHR_INLINE __MCF_DLLEXPORT #include "gthr.h" diff --git a/src/gthr.h b/src/gthr.h index 34df1e17d7..913fb1ef47 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -9,9 +9,9 @@ #include "gthr_aux.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_GTHR_IMPORT -# define __MCF_DECLSPEC_GTHR_IMPORT -# define __MCF_DECLSPEC_GTHR_INLINE __MCF_GNU_INLINE +#ifndef __MCF_GTHR_IMPORT +# define __MCF_GTHR_IMPORT +# define __MCF_GTHR_INLINE __MCF_GNU_INLINE #endif /* Enable full C++11 threading support. */ @@ -42,7 +42,7 @@ typedef __MCF_gthr_rc_mutex __gthread_recursive_mutex_t; /* Informs the runtime that threading support is active. * Windows creates new threads for console control handlers, so threading * cannot be disabled. */ -__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) +__MCF_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_active_p(void) __MCF_NOEXCEPT __attribute__((__const__)); @@ -51,7 +51,7 @@ __MCF_ALIAS(__gthread_active_p, __MCF_gthr_active_p); #endif /* Performs one-time initialization, like `pthread_once()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc); @@ -60,7 +60,7 @@ __MCF_ALIAS(__gthread_once, __MCF_gthr_once); #endif /* Allocates a thread-specific key, like `pthread_key_create()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; @@ -69,7 +69,7 @@ __MCF_ALIAS(__gthread_key_create, __MCF_gthr_key_create); #endif /* Destroys a thread-specific key, like `pthread_key_delete()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT; @@ -78,7 +78,7 @@ __MCF_ALIAS(__gthread_key_delete, __MCF_gthr_key_delete); #endif /* Gets a thread-specific value, like `pthread_getspecific()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT __attribute__((__pure__)); @@ -87,7 +87,7 @@ __MCF_ALIAS(__gthread_getspecific, __MCF_gthr_getspecific); #endif /* Sets a thread-specific value, like `pthread_setspecific()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT; @@ -96,7 +96,7 @@ __MCF_ALIAS(__gthread_setspecific, __MCF_gthr_setspecific); #endif /* Initializes a mutex, like `pthread_mutex_init()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -105,7 +105,7 @@ __MCF_ALIAS(__gthread_mutex_init, __MCF_gthr_mutex_init); #endif /* Destroys a mutex. This function does nothing. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -114,7 +114,7 @@ __MCF_ALIAS(__gthread_mutex_destroy, __MCF_gthr_mutex_destroy); #endif /* Locks a mutex, like `pthread_mutex_lock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -123,7 +123,7 @@ __MCF_ALIAS(__gthread_mutex_lock, __MCF_gthr_mutex_lock); #endif /* Tries locking a mutex without blocking, like `pthread_mutex_trylock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -132,7 +132,7 @@ __MCF_ALIAS(__gthread_mutex_trylock, __MCF_gthr_mutex_trylock); #endif /* Tries locking a mutex until a time point, like `pthread_mutex_timedlock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; @@ -141,7 +141,7 @@ __MCF_ALIAS(__gthread_mutex_timedlock, __MCF_gthr_mutex_timedlock); #endif /* Unlocks a mutex, like `pthread_mutex_unlock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -150,7 +150,7 @@ __MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); #endif /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -159,7 +159,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); #endif /* Destroys a recursive mutex. This function does nothing. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; @@ -168,7 +168,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destro #endif /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; @@ -178,7 +178,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); /* Tries locking a recursive mutex without blocking, like * `pthread_mutex_trylock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; @@ -188,7 +188,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_tryloc /* Tries locking a recursive mutex until a time point, like * `pthread_mutex_timedlock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; @@ -197,7 +197,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_time #endif /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; @@ -207,7 +207,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock) /* Initializes a condition variable, like `pthread_cond_init()`. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT; @@ -217,7 +217,7 @@ __MCF_ALIAS(__gthread_cond_init, __MCF_gthr_cond_init); /* Destroys a condition variable. This function does nothing. * This function exists not in GCC's 'gthr.h' but in 'gthr-posix.h'. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT; @@ -226,7 +226,7 @@ __MCF_ALIAS(__gthread_cond_destroy, __MCF_gthr_cond_destroy); #endif /* Waits for a condition variable, like `pthread_cond_wait()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT; @@ -235,7 +235,7 @@ __MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); #endif /* Waits for a condition variable, like `pthread_cond_wait()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; @@ -245,7 +245,7 @@ __MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); /* Waits for a condition variable until a time point, like * `pthread_cond_timedwait()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; @@ -255,7 +255,7 @@ __MCF_ALIAS(__gthread_cond_timedwait, __MCF_gthr_cond_timedwait); /* Signals at most one thread that is waiting on the condition variable, like * `pthread_cond_signal()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT; @@ -265,7 +265,7 @@ __MCF_ALIAS(__gthread_cond_signal, __MCF_gthr_cond_signal); /* Signals all threads that are waiting on the condition variable, like * `pthread_cond_broadcast()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT; @@ -274,7 +274,7 @@ __MCF_ALIAS(__gthread_cond_broadcast, __MCF_gthr_cond_broadcast); #endif /* Creates a thread, like `pthread_create()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT; @@ -283,7 +283,7 @@ __MCF_ALIAS(__gthread_create, __MCF_gthr_create_v2); #endif /* Awaits a thread to terminate and gets its result, like `pthread_join()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT; @@ -292,7 +292,7 @@ __MCF_ALIAS(__gthread_join, __MCF_gthr_join_v2); #endif /* Detaches a thread, like `pthread_detach()` */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT; @@ -303,7 +303,7 @@ __MCF_ALIAS(__gthread_detach, __MCF_gthr_detach_v2); /* Gets a thread itself, like `pthread_self()`. * The thread shall be the main thread, or shall have been created by * `__gthread_create()`. Otherwise the behavior is undefined. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT __attribute__((__const__, __returns_nonnull__)); @@ -312,7 +312,7 @@ __MCF_ALIAS(__gthread_self, __MCF_gthr_self); #endif /* Checks whether two thread IDs compare equal, like `pthread_equal()`. */ -__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) +__MCF_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT __attribute__((__pure__)); @@ -321,7 +321,7 @@ __MCF_ALIAS(__gthread_equal, __MCF_gthr_equal); #endif /* Gives up the current time slice, like `sched_yield()`. */ -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT; @@ -334,14 +334,14 @@ __MCF_ALIAS(__gthread_yield, __MCF_gthr_yield); * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) +__MCF_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_active_p(void) __MCF_NOEXCEPT { return 1; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc) { @@ -358,7 +358,7 @@ __MCF_gthr_once(__gthread_once_t* __once, __MCF_once_callback* __init_proc) return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT { @@ -367,7 +367,7 @@ __MCF_gthr_key_create(__gthread_key_t* __keyp, _MCF_tls_dtor* __dtor_opt) __MCF_ return (__key == NULL) ? -1 : 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT { @@ -375,14 +375,14 @@ __MCF_gthr_key_delete(__gthread_key_t __key) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE void* __MCF_gthr_getspecific(__gthread_key_t __key) __MCF_NOEXCEPT { return _MCF_tls_get(__key); } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXCEPT { @@ -390,7 +390,7 @@ __MCF_gthr_setspecific(__gthread_key_t __key, const void* __val_opt) __MCF_NOEXC return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -398,7 +398,7 @@ __MCF_gthr_mutex_init(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -406,7 +406,7 @@ __MCF_gthr_mutex_destroy(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -415,7 +415,7 @@ __MCF_gthr_mutex_lock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -424,7 +424,7 @@ __MCF_gthr_mutex_trylock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT { @@ -433,7 +433,7 @@ __MCF_gthr_mutex_timedlock(__gthread_mutex_t* __mtx, const __gthread_time_t* __a return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -441,7 +441,7 @@ __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -449,7 +449,7 @@ __MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXC return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -457,7 +457,7 @@ __MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NO return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -470,7 +470,7 @@ __MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXC return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -484,7 +484,7 @@ __MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NO return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT { @@ -498,7 +498,7 @@ __MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -506,7 +506,7 @@ __MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOE return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT { @@ -514,7 +514,7 @@ __MCF_gthr_cond_init(__gthread_cond_t* __cond) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT { @@ -522,7 +522,7 @@ __MCF_gthr_cond_destroy(__gthread_cond_t* __cond) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_NOEXCEPT { @@ -531,7 +531,7 @@ __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_N return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { @@ -540,7 +540,7 @@ __MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mut return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT { @@ -549,7 +549,7 @@ __MCF_gthr_cond_timedwait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx, co return __err; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT { @@ -557,7 +557,7 @@ __MCF_gthr_cond_signal(__gthread_cond_t* __cond) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT { @@ -565,7 +565,7 @@ __MCF_gthr_cond_broadcast(__gthread_cond_t* __cond) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, void* __arg) __MCF_NOEXCEPT { @@ -581,7 +581,7 @@ __MCF_gthr_create_v2(__gthread_t* __thrdp, __MCF_gthr_thread_procedure* __proc, return (__thrd == NULL) ? -1 : 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT { @@ -613,7 +613,7 @@ __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE int __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT { @@ -634,7 +634,7 @@ __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE __gthread_t __MCF_gthr_self(void) __MCF_NOEXCEPT { @@ -643,14 +643,14 @@ __MCF_gthr_self(void) __MCF_NOEXCEPT return __self; } -__MCF_DECLSPEC_GTHR_INLINE __MCF_CXX11(constexpr) +__MCF_GTHR_INLINE __MCF_CXX11(constexpr) int __MCF_gthr_equal(__gthread_t __t1, __gthread_t __t2) __MCF_NOEXCEPT { return __t1 == __t2; } -__MCF_DECLSPEC_GTHR_INLINE +__MCF_GTHR_INLINE void __MCF_gthr_yield(void) __MCF_NOEXCEPT { diff --git a/src/gthr_aux.c b/src/gthr_aux.c index 433ae11646..dd23748718 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -4,7 +4,7 @@ #include "precompiled.i" #define __MCF_DECLSPEC_GTHR_AUX __MCF_DLLEXPORT -#define __MCF_DECLSPEC_GTHR_AUX_INLINE __MCF_DLLEXPORT +#define __MCF_GTHR_AUX_INLINE __MCF_DLLEXPORT #include "gthr_aux.h" __MCF_DLLEXPORT diff --git a/src/gthr_aux.h b/src/gthr_aux.h index b4b78efcdc..1dbf34d282 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -15,7 +15,7 @@ __MCF_C_DECLARATIONS_BEGIN #ifndef __MCF_DECLSPEC_GTHR_AUX # define __MCF_DECLSPEC_GTHR_AUX -# define __MCF_DECLSPEC_GTHR_AUX_INLINE __MCF_GNU_INLINE +# define __MCF_GTHR_AUX_INLINE __MCF_GNU_INLINE #endif /* Define reusable types. */ @@ -43,7 +43,7 @@ struct __MCF_gthr_thread_record /* This is an auxiliary function for exception handling in `__gthread_once()`. * Ideally, if the target function throws exception we would like to allow * attempts to retry. Sadly this is not possible in standard C. */ -__MCF_DECLSPEC_GTHR_AUX_INLINE +__MCF_GTHR_AUX_INLINE void __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT; @@ -83,7 +83,7 @@ __MCF_gthr_thread_thunk_v2(_MCF_thread* __thrd) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_GTHR_AUX_INLINE +__MCF_GTHR_AUX_INLINE void __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT { diff --git a/src/mutex.c b/src/mutex.c index 75add00fc7..a0285794ed 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_MUTEX_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_MUTEX_INLINE __MCF_DLLEXPORT +#define __MCF_MUTEX_IMPORT __MCF_DLLEXPORT +#define __MCF_MUTEX_INLINE __MCF_DLLEXPORT #include "mutex.h" #include "xglobals.i" diff --git a/src/mutex.h b/src/mutex.h index 14c722601e..504417328f 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -9,9 +9,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_MUTEX_IMPORT -# define __MCF_DECLSPEC_MUTEX_IMPORT -# define __MCF_DECLSPEC_MUTEX_INLINE __MCF_GNU_INLINE +#ifndef __MCF_MUTEX_IMPORT +# define __MCF_MUTEX_IMPORT +# define __MCF_MUTEX_INLINE __MCF_GNU_INLINE #endif /* Define the mutex struct. @@ -44,7 +44,7 @@ struct __MCF_mutex /* Initializes a mutex dynamically. * Static ones should be initialized with `{0}`, like other structs. */ -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE void _MCF_mutex_init(_MCF_mutex* __mutex) __MCF_NOEXCEPT; @@ -61,22 +61,22 @@ _MCF_mutex_init(_MCF_mutex* __mutex) __MCF_NOEXCEPT; * * Returns 0 if the mutex has been locked by the caller, or -1 if the operation * has timed out. */ -__MCF_DECLSPEC_MUTEX_IMPORT +__MCF_MUTEX_IMPORT int _MCF_mutex_lock_slow(_MCF_mutex* __mutex, const int64_t* __timeout_opt) __MCF_NOEXCEPT; -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE int _MCF_mutex_lock(_MCF_mutex* __mutex, const int64_t* __timeout_opt) __MCF_NOEXCEPT; /* Releases a mutex. This function may be called by a different thread from * which locked the same mutex. If the mutex has not been locked, the behavior * is undefined. */ -__MCF_DECLSPEC_MUTEX_IMPORT +__MCF_MUTEX_IMPORT void _MCF_mutex_unlock_slow(_MCF_mutex* __mutex) __MCF_NOEXCEPT; -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE void _MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT; @@ -85,7 +85,7 @@ _MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE void _MCF_mutex_init(_MCF_mutex* __mutex) __MCF_NOEXCEPT { @@ -93,7 +93,7 @@ _MCF_mutex_init(_MCF_mutex* __mutex) __MCF_NOEXCEPT _MCF_atomic_store_pptr_rel(__mutex, &__temp); } -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE int _MCF_mutex_lock(_MCF_mutex* __mutex, const int64_t* __timeout_opt) __MCF_NOEXCEPT { @@ -110,7 +110,7 @@ _MCF_mutex_lock(_MCF_mutex* __mutex, const int64_t* __timeout_opt) __MCF_NOEXCEP return _MCF_mutex_lock_slow(__mutex, __timeout_opt); } -__MCF_DECLSPEC_MUTEX_INLINE +__MCF_MUTEX_INLINE void _MCF_mutex_unlock(_MCF_mutex* __mutex) __MCF_NOEXCEPT { diff --git a/src/once.c b/src/once.c index a0c86ac3ac..6d5efb123e 100644 --- a/src/once.c +++ b/src/once.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_ONCE_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_ONCE_INLINE __MCF_DLLEXPORT +#define __MCF_ONCE_IMPORT __MCF_DLLEXPORT +#define __MCF_ONCE_INLINE __MCF_DLLEXPORT #include "once.h" #include "xglobals.i" diff --git a/src/once.h b/src/once.h index d51783212e..ea5f1e35de 100644 --- a/src/once.h +++ b/src/once.h @@ -9,9 +9,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_ONCE_IMPORT -# define __MCF_DECLSPEC_ONCE_IMPORT -# define __MCF_DECLSPEC_ONCE_INLINE __MCF_GNU_INLINE +#ifndef __MCF_ONCE_IMPORT +# define __MCF_ONCE_IMPORT +# define __MCF_ONCE_INLINE __MCF_GNU_INLINE #endif /* Define the once flag struct. @@ -31,7 +31,7 @@ struct __MCF_once * Each once-initialization flag can be in any of the three states: UNLOCKED, * LOCKED and READY. An once-initialization flag is initialized to the UNLOCKED * state. */ -__MCF_DECLSPEC_ONCE_INLINE +__MCF_ONCE_INLINE void _MCF_once_init(_MCF_once* __once) __MCF_NOEXCEPT; @@ -52,11 +52,11 @@ _MCF_once_init(_MCF_once* __once) __MCF_NOEXCEPT; * thread releases the lock, or returns -1 if the operation has timed out. If * the once flag is already in the READY state, this function does nothing and * returns 0 immediately. */ -__MCF_DECLSPEC_ONCE_IMPORT +__MCF_ONCE_IMPORT int _MCF_once_wait_slow(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT; -__MCF_DECLSPEC_ONCE_INLINE +__MCF_ONCE_INLINE int _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -66,7 +66,7 @@ _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT; * This function changes it into the UNLOCKED state and wakes up the next * thread that is sleeping on this flag, whose call to `_MCF_once_wait()` will * return 1. */ -__MCF_DECLSPEC_ONCE_IMPORT +__MCF_ONCE_IMPORT void _MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT; @@ -75,7 +75,7 @@ _MCF_once_abort(_MCF_once* __once) __MCF_NOEXCEPT; * * This function changes it into the READY state and wakes up all threads that * are sleeping on this flag, whose calls to `_MCF_once_wait()` will return 0. */ -__MCF_DECLSPEC_ONCE_IMPORT +__MCF_ONCE_IMPORT void _MCF_once_release(_MCF_once* __once) __MCF_NOEXCEPT; @@ -84,7 +84,7 @@ _MCF_once_release(_MCF_once* __once) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_ONCE_INLINE +__MCF_ONCE_INLINE void _MCF_once_init(_MCF_once* __once) __MCF_NOEXCEPT { @@ -92,7 +92,7 @@ _MCF_once_init(_MCF_once* __once) __MCF_NOEXCEPT _MCF_atomic_store_pptr_rel(__once, &__temp); } -__MCF_DECLSPEC_ONCE_INLINE +__MCF_ONCE_INLINE int _MCF_once_wait(_MCF_once* __once, const int64_t* __timeout_opt) __MCF_NOEXCEPT { diff --git a/src/sem.c b/src/sem.c index a30b334451..b41d67ef80 100644 --- a/src/sem.c +++ b/src/sem.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_SEM_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_SEM_INLINE __MCF_DLLEXPORT +#define __MCF_SEM_IMPORT __MCF_DLLEXPORT +#define __MCF_SEM_INLINE __MCF_DLLEXPORT #include "sem.h" #include "xglobals.i" diff --git a/src/sem.h b/src/sem.h index 646243a5cd..d8280d997a 100644 --- a/src/sem.h +++ b/src/sem.h @@ -9,9 +9,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_SEM_IMPORT -# define __MCF_DECLSPEC_SEM_IMPORT -# define __MCF_DECLSPEC_SEM_INLINE __MCF_GNU_INLINE +#ifndef __MCF_SEM_IMPORT +# define __MCF_SEM_IMPORT +# define __MCF_SEM_INLINE __MCF_GNU_INLINE #endif /* Define the semaphore struct. @@ -37,7 +37,7 @@ struct __MCF_sem * * Returns 0 if the initialization is successful, or -1 in case of invalid * arguments. */ -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE int _MCF_sem_init(_MCF_sem* __sem, intptr_t __value_init) __MCF_NOEXCEPT; @@ -46,7 +46,7 @@ _MCF_sem_init(_MCF_sem* __sem, intptr_t __value_init) __MCF_NOEXCEPT; * Returns the current value as a signed integer. If the value is negative, its * absolute value denotes the number of threads that have been suspended on * this semaphore. */ -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE intptr_t _MCF_sem_get(const _MCF_sem* __sem) __MCF_NOEXCEPT; @@ -61,7 +61,7 @@ _MCF_sem_get(const _MCF_sem* __sem) __MCF_NOEXCEPT; * * Returns 0 if the value had been decremented and the calling thread has been * woken up by another thread, or -1 if the operation has timed out. */ -__MCF_DECLSPEC_SEM_IMPORT +__MCF_SEM_IMPORT int _MCF_sem_wait(_MCF_sem* __sem, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -71,11 +71,11 @@ _MCF_sem_wait(_MCF_sem* __sem, const int64_t* __timeout_opt) __MCF_NOEXCEPT; * * Returns 0 if the value has been updated successfully, or -1 in case of * invalid arguments, or -2 if the result would overflow. */ -__MCF_DECLSPEC_SEM_IMPORT +__MCF_SEM_IMPORT int _MCF_sem_signal_some(_MCF_sem* __sem, intptr_t __value_add) __MCF_NOEXCEPT; -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE int _MCF_sem_signal(_MCF_sem* __sem) __MCF_NOEXCEPT; @@ -84,7 +84,7 @@ _MCF_sem_signal(_MCF_sem* __sem) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE int _MCF_sem_init(_MCF_sem* __sem, intptr_t __value_init) __MCF_NOEXCEPT { @@ -96,7 +96,7 @@ _MCF_sem_init(_MCF_sem* __sem, intptr_t __value_init) __MCF_NOEXCEPT return 0; } -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE intptr_t _MCF_sem_get(const _MCF_sem* __sem) __MCF_NOEXCEPT { @@ -105,7 +105,7 @@ _MCF_sem_get(const _MCF_sem* __sem) __MCF_NOEXCEPT return __temp.__value; } -__MCF_DECLSPEC_SEM_INLINE +__MCF_SEM_INLINE int _MCF_sem_signal(_MCF_sem* __sem) __MCF_NOEXCEPT { diff --git a/src/thread.c b/src/thread.c index 8701bdd240..458fc69e5b 100644 --- a/src/thread.c +++ b/src/thread.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_THREAD_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_THREAD_INLINE __MCF_DLLEXPORT +#define __MCF_THREAD_IMPORT __MCF_DLLEXPORT +#define __MCF_THREAD_INLINE __MCF_DLLEXPORT #include "thread.h" #include "mutex.h" #include "cond.h" diff --git a/src/thread.h b/src/thread.h index 2f56906cec..3bf08ebebb 100644 --- a/src/thread.h +++ b/src/thread.h @@ -11,9 +11,9 @@ #include "atomic.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_THREAD_IMPORT -# define __MCF_DECLSPEC_THREAD_IMPORT -# define __MCF_DECLSPEC_THREAD_INLINE __MCF_GNU_INLINE +#ifndef __MCF_THREAD_IMPORT +# define __MCF_THREAD_IMPORT +# define __MCF_THREAD_INLINE __MCF_GNU_INLINE #endif /* Define the thread control struct. */ @@ -46,44 +46,44 @@ struct __MCF_thread * `_MCF_thread_drop_ref()` when it is no longer needed. If the thread cannot * be created, a null pointer is returned and an error code can be obtained * via `_MCF_get_win32_error()`. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT _MCF_thread* _MCF_thread_new(_MCF_thread_procedure* __proc, const void* __data_opt, size_t __size) __MCF_NOEXCEPT; /* Gets a pointer to user-defined data of a thread. */ -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_CXX(const) void* _MCF_thread_get_data(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Adds a reference count of a thread structure. This may be useful if you * wish to pass a pointer to other code. */ -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void _MCF_thread_add_ref(_MCF_thread* __thrd) __MCF_NOEXCEPT; /* Drops a reference count of a thread structure. An active thread owns a * reference count of itself and `_MCF_thread_new()` returns another one. When * the reference count is reduced to zero, the structure is deallocated. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT void _MCF_thread_drop_ref_nonnull(_MCF_thread* __thrd) __MCF_NOEXCEPT; -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void _MCF_thread_drop_ref(_MCF_thread* __thrd_opt) __MCF_NOEXCEPT; /* Gets the ID of a thread. */ -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) uint32_t _MCF_thread_get_tid(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Gets the handle of a thread. */ -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_HANDLE _MCF_thread_get_handle(const _MCF_thread* __thrd) __MCF_NOEXCEPT __attribute__((__pure__)); /* Exits from a thread. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT void _MCF_thread_exit(void) __MCF_NOEXCEPT __attribute__((__noreturn__)); @@ -97,7 +97,7 @@ _MCF_thread_exit(void) __MCF_NOEXCEPT __attribute__((__noreturn__)); * * Returns 0 if the thread has terminated, or -1 if the wait operation has * timed out. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT int _MCF_thread_wait(const _MCF_thread* __thrd_opt, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -105,17 +105,17 @@ _MCF_thread_wait(const _MCF_thread* __thrd_opt, const int64_t* __timeout_opt) __ * * IMPORTANT! This function is only meaningful for the main thread and threads * that were created by `_MCF_thread_new()`. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT _MCF_thread* _MCF_thread_self(void) __MCF_NOEXCEPT __attribute__((__const__)); /* Gets the thread ID of the current thread. */ -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE uint32_t _MCF_thread_self_tid(void) __MCF_NOEXCEPT __attribute__((__const__)); /* Gives up the current time slice. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT void _MCF_yield(void) __MCF_NOEXCEPT; @@ -128,7 +128,7 @@ _MCF_yield(void) __MCF_NOEXCEPT; * immediately. If it is null, the function sleeps indefinitely. * * Returns 0 if the operation has timed out, or -1 if an interrupt occurred. */ -__MCF_DECLSPEC_THREAD_IMPORT +__MCF_THREAD_IMPORT int _MCF_sleep(const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -137,7 +137,7 @@ _MCF_sleep(const int64_t* __timeout_opt) __MCF_NOEXCEPT; * * Returns the thread-local value if one has been set by the calling thread, or * a null pointer otherwise. No return value is reserved to indicate errors. */ -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void* _MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT __attribute__((__pure__)); @@ -145,7 +145,7 @@ _MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT __attribute__((__pure__)) * `_MCF_thread_new()`, or shall be the main thread. * * Returns 0 upon success and -1 upon failure. */ -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE int _MCF_tls_set(_MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT; @@ -154,7 +154,7 @@ _MCF_tls_set(_MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_CXX(const) void* _MCF_thread_get_data(const _MCF_thread* __thrd) __MCF_NOEXCEPT { @@ -171,7 +171,7 @@ _MCF_thread_get_data(_MCF_thread* __thrd) __MCF_NOEXCEPT } #endif /* __cplusplus */ -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void _MCF_thread_add_ref(_MCF_thread* __thrd) __MCF_NOEXCEPT { @@ -180,7 +180,7 @@ _MCF_thread_add_ref(_MCF_thread* __thrd) __MCF_NOEXCEPT __MCF_ASSERT(__old_ref > 0); } -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void _MCF_thread_drop_ref(_MCF_thread* __thrd_opt) __MCF_NOEXCEPT { @@ -188,21 +188,21 @@ _MCF_thread_drop_ref(_MCF_thread* __thrd_opt) __MCF_NOEXCEPT _MCF_thread_drop_ref_nonnull(__thrd_opt); } -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) uint32_t _MCF_thread_get_tid(const _MCF_thread* __thrd) __MCF_NOEXCEPT { return __thrd->__tid; } -__MCF_DECLSPEC_THREAD_INLINE __MCF_CXX11(constexpr) +__MCF_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_HANDLE _MCF_thread_get_handle(const _MCF_thread* __thrd) __MCF_NOEXCEPT { return __thrd->__handle; } -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE uint32_t _MCF_thread_self_tid(void) __MCF_NOEXCEPT { @@ -227,7 +227,7 @@ _MCF_thread_self_tid(void) __MCF_NOEXCEPT return __tid; } -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE void* _MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT { @@ -236,7 +236,7 @@ _MCF_tls_get(const _MCF_tls_key* __key) __MCF_NOEXCEPT : __MCF_tls_table_get(__self->__tls_table, __key); } -__MCF_DECLSPEC_THREAD_INLINE +__MCF_THREAD_INLINE int _MCF_tls_set(_MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT { diff --git a/src/tls.c b/src/tls.c index 1640946191..4a7e92b067 100644 --- a/src/tls.c +++ b/src/tls.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_TLS_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_TLS_INLINE __MCF_DLLEXPORT +#define __MCF_TLS_IMPORT __MCF_DLLEXPORT +#define __MCF_TLS_INLINE __MCF_DLLEXPORT #include "tls.h" #include "atomic.h" #include "xglobals.i" diff --git a/src/tls.h b/src/tls.h index b21817521b..458ce006ab 100644 --- a/src/tls.h +++ b/src/tls.h @@ -8,9 +8,9 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_TLS_IMPORT -# define __MCF_DECLSPEC_TLS_IMPORT -# define __MCF_DECLSPEC_TLS_INLINE __MCF_GNU_INLINE +#ifndef __MCF_TLS_IMPORT +# define __MCF_TLS_IMPORT +# define __MCF_TLS_INLINE __MCF_GNU_INLINE #endif /* Define the table structure that manages all thread-local objects. */ @@ -48,7 +48,7 @@ struct __MCF_tls_key * `_MCF_tls_key_delete()` when it is no longer needed. If the thread-local key * cannot be created, a null pointer is returned and an error code can be * obtained via `_MCF_get_win32_error()`. */ -__MCF_DECLSPEC_TLS_IMPORT +__MCF_TLS_IMPORT _MCF_tls_key* _MCF_tls_key_new(_MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; @@ -58,11 +58,11 @@ _MCF_tls_key_new(_MCF_tls_dtor* __dtor_opt) __MCF_NOEXCEPT; * the application's responsibility to ensure that all resources about values * that are attached to this key are deallocated. Passing a deleted key to * other functions results in undefined behavior. */ -__MCF_DECLSPEC_TLS_IMPORT +__MCF_TLS_IMPORT void _MCF_tls_key_delete_nonnull(_MCF_tls_key* __key) __MCF_NOEXCEPT; -__MCF_DECLSPEC_TLS_INLINE +__MCF_TLS_INLINE void _MCF_tls_key_delete(_MCF_tls_key* __key_opt) __MCF_NOEXCEPT; @@ -70,21 +70,21 @@ _MCF_tls_key_delete(_MCF_tls_key* __key_opt) __MCF_NOEXCEPT; * * Returns the thread-local value if one has been set, or a null pointer * otherwise. No return value is reserved to indicate errors. */ -__MCF_DECLSPEC_TLS_IMPORT +__MCF_TLS_IMPORT void* __MCF_tls_table_get(const __MCF_tls_table* __table, const _MCF_tls_key* __key) __MCF_NOEXCEPT __attribute__((__pure__)); /* Sets a value into the table. * * Returns 0 upon success and -1 upon failure. */ -__MCF_DECLSPEC_TLS_IMPORT +__MCF_TLS_IMPORT int __MCF_tls_table_set(__MCF_tls_table* __table, _MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT; /* Executes all destructors in the table, and frees dynamic storage if any. It * is declared here for the sake of completeness, and is not meant to be call * directly. */ -__MCF_DECLSPEC_TLS_IMPORT +__MCF_TLS_IMPORT void __MCF_tls_table_finalize(__MCF_tls_table* __table) __MCF_NOEXCEPT; @@ -93,7 +93,7 @@ __MCF_tls_table_finalize(__MCF_tls_table* __table) __MCF_NOEXCEPT; * matches the disposition of non-inline functions. Note that however, unlike C++ * inline functions, they have to have consistent inline specifiers throughout * this file. */ -__MCF_DECLSPEC_TLS_INLINE +__MCF_TLS_INLINE void _MCF_tls_key_delete(_MCF_tls_key* __key_opt) __MCF_NOEXCEPT { diff --git a/src/xglobals.c b/src/xglobals.c index 3fdc69d9d6..c5453fa9f8 100644 --- a/src/xglobals.c +++ b/src/xglobals.c @@ -3,8 +3,8 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_XGLOBALS_IMPORT __MCF_DLLEXPORT -#define __MCF_DECLSPEC_XGLOBALS_INLINE __MCF_DLLEXPORT +#define __MCF_XGLOBALS_IMPORT __MCF_DLLEXPORT +#define __MCF_XGLOBALS_INLINE __MCF_DLLEXPORT #include "xglobals.i" #include "thread.h" #include "mutex.h" diff --git a/src/xglobals.i b/src/xglobals.i index 807b20e023..623a0e25ac 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -27,9 +27,9 @@ extern "C" { # error Windows platforms are assumed to be little-endian. #endif -#ifndef __MCF_DECLSPEC_XGLOBALS_IMPORT -# define __MCF_DECLSPEC_XGLOBALS_IMPORT -# define __MCF_DECLSPEC_XGLOBALS_INLINE __MCF_GNU_INLINE +#ifndef __MCF_XGLOBALS_IMPORT +# define __MCF_XGLOBALS_IMPORT +# define __MCF_XGLOBALS_INLINE __MCF_GNU_INLINE #endif /* Declare global data. */ @@ -112,7 +112,7 @@ __MCF_WINAPI(NTSTATUS, NtWaitForKeyedEvent, HANDLE, PVOID, BOOLEAN, LARGE_INTEGE __MCF_WINAPI(NTSTATUS, NtReleaseKeyedEvent, HANDLE, PVOID, BOOLEAN, LARGE_INTEGER*); /* Declare helper functions here. */ -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT EXCEPTION_DISPOSITION __cdecl __MCF_seh_top(EXCEPTION_RECORD* __rec, PVOID __estab_frame, CONTEXT* __ctx, PVOID __disp_ctx) __MCF_NOEXCEPT; @@ -170,91 +170,91 @@ struct __MCF_winnt_timeout uint64_t __since; }; -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void __MCF_initialize_winnt_timeout_v2(__MCF_winnt_timeout* __to, const int64_t* __int64_opt) __MCF_NOEXCEPT; -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void __MCF_adjust_winnt_timeout_v2(__MCF_winnt_timeout* __to) __MCF_NOEXCEPT; /* Note this function is subject to tail-call optimization. */ -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT size_t __MCF_batch_release_common(const void* __key, size_t __count) __MCF_NOEXCEPT; /* Copy a block of memory forward, like `memcpy()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mcopy(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT; /* Copy a block of memory backward. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT; /* Fill a block of memory with the given byte, like `memset()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mfill(void* __dst, int __val, size_t __size) __MCF_NOEXCEPT; /* Fill a block of memory with zeroes, like `bzero()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT; /* Allocate a block of zeroed memory, like `calloc()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_malloc_0(size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __malloc__, __alloc_size__(1))); /* Re-allocate a block of memory, like `realloc()`. If the existent * block should be extended, vacuum bytes are filled with zeroes. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __alloc_size__(2))); /* Allocate a copy of a block of memory, like `malloc()` followed by * `memcpy()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT __attribute__((__warn_unused_result__, __alloc_size__(2))); /* Get the size of an allocated block, like `malloc_usable_size()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE size_t __MCF_msize(const void* __ptr) __MCF_NOEXCEPT __attribute__((__pure__)); /* Free a block of memory, like `free()`. */ -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void __MCF_mfree(void* __ptr_opt) __MCF_NOEXCEPT; /* These functions set the last error code and return the second argument. * They should be subject to tail-call optimization. */ -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT int __MCF_win32_error_i(DWORD __code, int __val) __MCF_NOEXCEPT; -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void* __MCF_win32_error_p(DWORD __code, void* __ptr) __MCF_NOEXCEPT; /* These functions are declared here for the sake of completeness, and are not * meant to be called directly. */ -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void __MCF_run_dtors_at_quick_exit(void) __MCF_NOEXCEPT; -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void __MCF_run_dtors_atexit(void) __MCF_NOEXCEPT; -__MCF_DECLSPEC_XGLOBALS_IMPORT +__MCF_XGLOBALS_IMPORT void __MCF_finalize_on_exit(void) __MCF_NOEXCEPT; @@ -302,7 +302,7 @@ __MCF_keyed_event_signal(const void* __key, const LARGE_INTEGER* __timeout) __MC : "memory") /* no semicolon */ #endif -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mcopy(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT @@ -319,7 +319,7 @@ __MCF_mcopy(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCEPT @@ -336,7 +336,7 @@ __MCF_mcopy_backward(void* __dst, const void* __src, size_t __size) __MCF_NOEXCE return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mfill(void* __dst, int __val, size_t __size) __MCF_NOEXCEPT @@ -351,7 +351,7 @@ __MCF_mfill(void* __dst, int __val, size_t __size) __MCF_NOEXCEPT return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __cdecl __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT @@ -366,7 +366,7 @@ __MCF_mzero(void* __dst, size_t __size) __MCF_NOEXCEPT return __dst; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_malloc_0(size_t __size) __MCF_NOEXCEPT { @@ -374,7 +374,7 @@ __MCF_malloc_0(size_t __size) __MCF_NOEXCEPT return __ptr; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT { @@ -382,7 +382,7 @@ __MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT return !__ptr ? NULL : (*__pptr = __ptr); } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void* __MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT { @@ -390,7 +390,7 @@ __MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT return !__ptr ? NULL : __MCF_mcopy(__ptr, __data, __size); } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE size_t __MCF_msize(const void* __ptr) __MCF_NOEXCEPT { @@ -399,7 +399,7 @@ __MCF_msize(const void* __ptr) __MCF_NOEXCEPT return __size; } -__MCF_DECLSPEC_XGLOBALS_INLINE +__MCF_XGLOBALS_INLINE void __MCF_mfree(void* __ptr_opt) __MCF_NOEXCEPT { From 754e1e15fdca780b69a0ea2ff75235edf52fa93c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 02:38:08 +0800 Subject: [PATCH 067/133] fwd: Rename `__MCF_STATIC_ASSERT` to `__MCF_STATIC_ASSERT_0` (cherry picked from commit 26716706c75fc6570f3c8be94d28c47c05f8e50f) Signed-off-by: LIU Hao --- src/event.h | 4 ++-- src/fwd.h | 10 +++++----- src/sem.h | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/event.h b/src/event.h index 7533fc1e4b..d8617fb41f 100644 --- a/src/event.h +++ b/src/event.h @@ -31,8 +31,8 @@ struct __MCF_event /* Define a macro for static initialization of events. The argument is the * initial value of the event. */ #define __MCF_EVENT_INIT(__value_init) \ - { __MCF_STATIC_ASSERT((__value_init) >= 0) + \ - __MCF_STATIC_ASSERT((__value_init) <= __MCF_EVENT_VALUE_MAX) + \ + { __MCF_STATIC_ASSERT_0((__value_init) >= 0) + \ + __MCF_STATIC_ASSERT_0((__value_init) <= __MCF_EVENT_VALUE_MAX) + \ (__value_init), 0, 0 } /* Initializes an event dynamically. The argument is the initial value of diff --git a/src/fwd.h b/src/fwd.h index 481628736b..e3214f3506 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -114,14 +114,14 @@ __MCF_C_DECLARATIONS_BEGIN # define __MCF_ALIAS(alias, target) static __typeof__(target)* const alias = (target) #endif -/* The `__MCF_STATIC_ASSERT()` macro is an expression that yields zero if it +/* The `__MCF_STATIC_ASSERT_0()` macro is an expression that yields zero if it * compiles anyway. Its argument must be a constant expression. */ #ifdef __cplusplus -extern "C++" template struct __MCF_static_assert; -extern "C++" template<> struct __MCF_static_assert { char __unused; }; -# define __MCF_STATIC_ASSERT(...) ((int) sizeof(::__MCF_static_assert<(__VA_ARGS__)>)-1) +extern "C++" template struct __MCF_static_assert; +extern "C++" template<> struct __MCF_static_assert { }; +# define __MCF_STATIC_ASSERT_0(...) (0 & (int) sizeof(::__MCF_static_assert<(__VA_ARGS__)>)) #else -# define __MCF_STATIC_ASSERT(...) ((int) sizeof(struct{char:1|-!(__VA_ARGS__);})-1) +# define __MCF_STATIC_ASSERT_0(...) (0 & (int) sizeof(struct{ int: 1|-!(__VA_ARGS__); })) #endif /* The `__MCF_ASSERT()` and `__MCF_CHECK()` macros perform run-time checks. If diff --git a/src/sem.h b/src/sem.h index d8280d997a..e753ef23ed 100644 --- a/src/sem.h +++ b/src/sem.h @@ -27,8 +27,8 @@ struct __MCF_sem /* Define a macro for static initialization of semaphores. The argument is the * initial value of the semaphore, which shall not be negative. */ #define __MCF_SEM_INIT(__value_init) \ - { __MCF_STATIC_ASSERT((__value_init) >= 0) + \ - __MCF_STATIC_ASSERT((__value_init) <= __MCF_SEM_VALUE_MAX) + \ + { __MCF_STATIC_ASSERT_0((__value_init) >= 0) + \ + __MCF_STATIC_ASSERT_0((__value_init) <= __MCF_SEM_VALUE_MAX) + \ (__value_init) } /* Initializes a semaphore dynamically. The argument is the initial value of From aa789b9d3720080506d9fff726fb2cdd8ec3d09b Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 02:36:44 +0800 Subject: [PATCH 068/133] fwd: Update `__MCF_STATIC_ASSERT()` (cherry picked from commit c12db271971209f81691d33719101d74d0a17fba) Signed-off-by: LIU Hao --- src/fwd.h | 11 ++-- test/c11_inline_alias.c | 126 ++++++++------------------------------- test/gthr_inline_alias.c | 71 +++++----------------- 3 files changed, 46 insertions(+), 162 deletions(-) diff --git a/src/fwd.h b/src/fwd.h index e3214f3506..9f4a0873a0 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -119,16 +119,19 @@ __MCF_C_DECLARATIONS_BEGIN #ifdef __cplusplus extern "C++" template struct __MCF_static_assert; extern "C++" template<> struct __MCF_static_assert { }; -# define __MCF_STATIC_ASSERT_0(...) (0 & (int) sizeof(::__MCF_static_assert<(__VA_ARGS__)>)) +# define __MCF_STATIC_ASSERT_T(...) ::__MCF_static_assert<(__VA_ARGS__)> #else -# define __MCF_STATIC_ASSERT_0(...) (0 & (int) sizeof(struct{ int: 1|-!(__VA_ARGS__); })) +# define __MCF_STATIC_ASSERT_T(...) struct { int: 1|-!(__VA_ARGS__); } #endif +#define __MCF_STATIC_ASSERT_0(...) (0 & (int) sizeof(__MCF_STATIC_ASSERT_T(__VA_ARGS__))) +#define __MCF_STATIC_ASSERT(...) ((void) sizeof(__MCF_STATIC_ASSERT_T(__VA_ARGS__))) + /* The `__MCF_ASSERT()` and `__MCF_CHECK()` macros perform run-time checks. If * an argument yields false, `__MCF_ASSERT()` results in undefined behavior, * and `__MCF_CHECK()` effects abnormal termination of the current program. */ -#define __MCF_ASSERT(...) ((__VA_ARGS__) ? (void) 0 : __MCF_UNREACHABLE) -#define __MCF_CHECK(...) ((__VA_ARGS__) ? (void) 0 : __MCF_runtime_failure(__FUNCTION__)) +#define __MCF_ASSERT(...) ((__VA_ARGS__) ? (void) 0 : __MCF_UNREACHABLE) +#define __MCF_CHECK(...) ((__VA_ARGS__) ? (void) 0 : __MCF_runtime_failure(__FUNCTION__)) /* Make some forward declarations. */ typedef struct __MCF_dtor_element __MCF_dtor_element; diff --git a/test/c11_inline_alias.c b/test/c11_inline_alias.c index 412a881696..0964bd6996 100644 --- a/test/c11_inline_alias.c +++ b/test/c11_inline_alias.c @@ -8,107 +8,31 @@ int main(void) { - volatile intptr_t mcfp, gthp; - - mcfp = (intptr_t) __MCF_c11_call_once; - gthp = (intptr_t) call_once; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_broadcast; - gthp = (intptr_t) cnd_broadcast; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_destroy; - gthp = (intptr_t) cnd_destroy; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_init; - gthp = (intptr_t) cnd_init; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_signal; - gthp = (intptr_t) cnd_signal; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_timedwait; - gthp = (intptr_t) cnd_timedwait; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_cnd_wait; - gthp = (intptr_t) cnd_wait; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_destroy; - gthp = (intptr_t) mtx_destroy; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_init; - gthp = (intptr_t) mtx_init; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_lock; - gthp = (intptr_t) mtx_lock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_timedlock; - gthp = (intptr_t) mtx_timedlock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_trylock; - gthp = (intptr_t) mtx_trylock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_mtx_unlock; - gthp = (intptr_t) mtx_unlock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_create; - gthp = (intptr_t) thrd_create; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_current; - gthp = (intptr_t) thrd_current; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_detach; - gthp = (intptr_t) thrd_detach; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_equal; - gthp = (intptr_t) thrd_equal; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_exit; - gthp = (intptr_t) thrd_exit; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_join; - gthp = (intptr_t) thrd_join; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_sleep; - gthp = (intptr_t) thrd_sleep; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_thrd_yield; - gthp = (intptr_t) thrd_yield; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_tss_create; - gthp = (intptr_t) tss_create; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_tss_delete; - gthp = (intptr_t) tss_delete; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_tss_get; - gthp = (intptr_t) tss_get; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_c11_tss_set; - gthp = (intptr_t) tss_set; - assert(mcfp == gthp); + __MCF_STATIC_ASSERT(__MCF_c11_call_once == call_once); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_broadcast == cnd_broadcast); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_destroy == cnd_destroy); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_init == cnd_init); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_signal == cnd_signal); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_timedwait == cnd_timedwait); + __MCF_STATIC_ASSERT(__MCF_c11_cnd_wait == cnd_wait); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_destroy == mtx_destroy); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_init == mtx_init); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_lock == mtx_lock); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_timedlock == mtx_timedlock); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_trylock == mtx_trylock); + __MCF_STATIC_ASSERT(__MCF_c11_mtx_unlock == mtx_unlock); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_create == thrd_create); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_current == thrd_current); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_detach == thrd_detach); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_equal == thrd_equal); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_exit == thrd_exit); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_join == thrd_join); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_sleep == thrd_sleep); + __MCF_STATIC_ASSERT(__MCF_c11_thrd_yield == thrd_yield); + __MCF_STATIC_ASSERT(__MCF_c11_tss_create == tss_create); + __MCF_STATIC_ASSERT(__MCF_c11_tss_delete == tss_delete); + __MCF_STATIC_ASSERT(__MCF_c11_tss_get == tss_get); + __MCF_STATIC_ASSERT(__MCF_c11_tss_set == tss_set); return 0; } diff --git a/test/gthr_inline_alias.c b/test/gthr_inline_alias.c index 8db62ead6b..d88386449e 100644 --- a/test/gthr_inline_alias.c +++ b/test/gthr_inline_alias.c @@ -8,63 +8,20 @@ int main(void) { - volatile intptr_t mcfp, gthp; - - mcfp = (intptr_t) __MCF_gthr_active_p; - gthp = (intptr_t) __gthread_active_p; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_getspecific; - gthp = (intptr_t) __gthread_getspecific; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_key_create; - gthp = (intptr_t) __gthread_key_create; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_key_delete; - gthp = (intptr_t) __gthread_key_delete; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_mutex_destroy; - gthp = (intptr_t) __gthread_mutex_destroy; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_mutex_lock; - gthp = (intptr_t) __gthread_mutex_lock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_mutex_trylock; - gthp = (intptr_t) __gthread_mutex_trylock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_mutex_unlock; - gthp = (intptr_t) __gthread_mutex_unlock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_once; - gthp = (intptr_t) __gthread_once; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_recursive_mutex_destroy; - gthp = (intptr_t) __gthread_recursive_mutex_destroy; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_recursive_mutex_lock; - gthp = (intptr_t) __gthread_recursive_mutex_lock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_recursive_mutex_trylock; - gthp = (intptr_t) __gthread_recursive_mutex_trylock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_recursive_mutex_unlock; - gthp = (intptr_t) __gthread_recursive_mutex_unlock; - assert(mcfp == gthp); - - mcfp = (intptr_t) __MCF_gthr_setspecific; - gthp = (intptr_t) __gthread_setspecific; - assert(mcfp == gthp); + __MCF_STATIC_ASSERT(__MCF_gthr_active_p == __gthread_active_p); + __MCF_STATIC_ASSERT(__MCF_gthr_getspecific == __gthread_getspecific); + __MCF_STATIC_ASSERT(__MCF_gthr_key_create == __gthread_key_create); + __MCF_STATIC_ASSERT(__MCF_gthr_key_delete == __gthread_key_delete); + __MCF_STATIC_ASSERT(__MCF_gthr_mutex_destroy == __gthread_mutex_destroy); + __MCF_STATIC_ASSERT(__MCF_gthr_mutex_lock == __gthread_mutex_lock); + __MCF_STATIC_ASSERT(__MCF_gthr_mutex_trylock == __gthread_mutex_trylock); + __MCF_STATIC_ASSERT(__MCF_gthr_mutex_unlock == __gthread_mutex_unlock); + __MCF_STATIC_ASSERT(__MCF_gthr_once == __gthread_once); + __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_destroy == __gthread_recursive_mutex_destroy); + __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_lock == __gthread_recursive_mutex_lock); + __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_trylock == __gthread_recursive_mutex_trylock); + __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_unlock == __gthread_recursive_mutex_unlock); + __MCF_STATIC_ASSERT(__MCF_gthr_setspecific == __gthread_setspecific); return 0; } From 5005251653b33359a2a4ee660afe75f3867b26e1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:24:24 +0800 Subject: [PATCH 069/133] ci: Add checks for static libraries (cherry picked from commit ff532d60df9b312154d77dfd632a571330ee2740) Signed-off-by: LIU Hao --- .appveyor.yml | 8 ++++++++ ci/build.sh | 21 ++------------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9b52e07975..7eae40f046 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -5,8 +5,16 @@ environment: matrix: - PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin CXX: x86_64-w64-mingw32-g++ + CONFIGURE_OPTIONS: --disable-static + - PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin + CXX: x86_64-w64-mingw32-g++ + CONFIGURE_OPTIONS: --disable-shared + - PATH: C:\msys64\mingw32\bin;C:\msys64\usr\bin + CXX: i686-w64-mingw32-g++ + CONFIGURE_OPTIONS: --disable-static - PATH: C:\msys64\mingw32\bin;C:\msys64\usr\bin CXX: i686-w64-mingw32-g++ + CONFIGURE_OPTIONS: --disable-shared install: - cmd: pacman -S --noconfirm autoconf automake libtool make mingw-w64-{x86_64,i686}-gcc diff --git a/ci/build.sh b/ci/build.sh index 303228ed8f..43a6151c82 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -4,23 +4,6 @@ export CC=${CC:-"gcc"} export CCFLAGS='-O2 -g0' -_fail=1 - -while test $# -gt 0 -do - case $1 in - --disable-make-check ) - _fail=0 - shift 1 - ;; - - * ) - echo "WARNING: unknown option -- '$1'" >&2 - shift 1 - ;; - esac -done - # build ${CC} --version mkdir -p m4 @@ -28,11 +11,11 @@ autoreconf -ifv cd $(mktemp -d) trap 'rm -rf ~+ || true' EXIT -~-/configure --disable-silent-rules --enable-debug-checks --disable-static +~-/configure --disable-silent-rules --enable-debug-checks ${CONFIGURE_OPTIONS} # test if ! make -j$(nproc) distcheck then cat ./test-suite.log - exit ${_fail} + exit 1 fi From 90ff223f338c62ef401393473d3be9d3e3314ea3 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:26:14 +0800 Subject: [PATCH 070/133] ci: Add checks for static libraries (cherry picked from commit bbd4b2bde5a34708465d43732e35e31da2e9d637) Signed-off-by: LIU Hao --- .appveyor.yml | 16 ++++++++-------- ci/build.sh | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 7eae40f046..ac24260e91 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,17 +4,17 @@ image: environment: matrix: - PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin - CXX: x86_64-w64-mingw32-g++ - CONFIGURE_OPTIONS: --disable-static + CONFIGURE_HOST: x86_64-w64-mingw32 + CONFIGURE_OPTS: --disable-static - PATH: C:\msys64\mingw64\bin;C:\msys64\usr\bin - CXX: x86_64-w64-mingw32-g++ - CONFIGURE_OPTIONS: --disable-shared + CONFIGURE_HOST: x86_64-w64-mingw32 + CONFIGURE_OPTS: --disable-shared - PATH: C:\msys64\mingw32\bin;C:\msys64\usr\bin - CXX: i686-w64-mingw32-g++ - CONFIGURE_OPTIONS: --disable-static + CONFIGURE_HOST: i686-w64-mingw32 + CONFIGURE_OPTS: --disable-static - PATH: C:\msys64\mingw32\bin;C:\msys64\usr\bin - CXX: i686-w64-mingw32-g++ - CONFIGURE_OPTIONS: --disable-shared + CONFIGURE_HOST: i686-w64-mingw32 + CONFIGURE_OPTS: --disable-shared install: - cmd: pacman -S --noconfirm autoconf automake libtool make mingw-w64-{x86_64,i686}-gcc diff --git a/ci/build.sh b/ci/build.sh index 43a6151c82..a882456d5b 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -11,7 +11,7 @@ autoreconf -ifv cd $(mktemp -d) trap 'rm -rf ~+ || true' EXIT -~-/configure --disable-silent-rules --enable-debug-checks ${CONFIGURE_OPTIONS} +~-/configure --disable-silent-rules --enable-debug-checks --{build,host}=${CONFIGURE_HOST} ${CONFIGURE_OPTS} # test if ! make -j$(nproc) distcheck From 805318397302780cdb032272e989363a221e3741 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:33:07 +0800 Subject: [PATCH 071/133] ci: Fix a typo (cherry picked from commit 4626e72d8ec2995aed3dd3c6a09af807cac6e584) Signed-off-by: LIU Hao --- ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build.sh b/ci/build.sh index a882456d5b..4be7c563bc 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -2,7 +2,7 @@ # setup export CC=${CC:-"gcc"} -export CCFLAGS='-O2 -g0' +export CFLAGS='-O2 -g0' # build ${CC} --version From f9b5fc1b51cd6202d8a39def31e98a9bdb36a43e Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:37:03 +0800 Subject: [PATCH 072/133] ci: Do `printenv` before building (cherry picked from commit bf85318312ae72e2dcff153762e470a5b85647aa) Signed-off-by: LIU Hao --- ci/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/build.sh b/ci/build.sh index 4be7c563bc..21d54341bb 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -5,6 +5,7 @@ export CC=${CC:-"gcc"} export CFLAGS='-O2 -g0' # build +printenv ${CC} --version mkdir -p m4 autoreconf -ifv From 5379b29cf767892395c5470b5e805e89f3392b01 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:48:26 +0800 Subject: [PATCH 073/133] ci: Use `DISTCHECK_CONFIGURE_FLAGS` (cherry picked from commit 29ecbabc41ab112a56aef61fb60d10cedce82201) Signed-off-by: LIU Hao --- ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build.sh b/ci/build.sh index 21d54341bb..23e8e20e14 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -15,7 +15,7 @@ trap 'rm -rf ~+ || true' EXIT ~-/configure --disable-silent-rules --enable-debug-checks --{build,host}=${CONFIGURE_HOST} ${CONFIGURE_OPTS} # test -if ! make -j$(nproc) distcheck +if ! make -j$(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS=${CONFIGURE_OPTS} then cat ./test-suite.log exit 1 From 9dba4476728915a4c376e8425597563e1c888889 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 22:52:07 +0800 Subject: [PATCH 074/133] Revert "ci: Do `printenv` before building" This reverts commit bf85318312ae72e2dcff153762e470a5b85647aa. (cherry picked from commit 37ff3825fb0d89e3e40a0f2b04b9b379d8936128) Signed-off-by: LIU Hao --- ci/build.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/build.sh b/ci/build.sh index 23e8e20e14..fc3b0ecbe8 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -5,7 +5,6 @@ export CC=${CC:-"gcc"} export CFLAGS='-O2 -g0' # build -printenv ${CC} --version mkdir -p m4 autoreconf -ifv From 4b5b3a2d614cb54713e5631c98968500286da87b Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 30 Oct 2022 23:31:55 +0800 Subject: [PATCH 075/133] gthr: Fix parameter name (cherry picked from commit e8fb31d55883268d5dedfe38684d56a89ee6c017) Signed-off-by: LIU Hao --- src/gthr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gthr.h b/src/gthr.h index 913fb1ef47..106a3f24a1 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -152,7 +152,7 @@ __MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __mtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); From 37dc84103319ecc90b6eda72739259a18dde4d7b Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 1 Nov 2022 22:19:53 +0800 Subject: [PATCH 076/133] once,mutex,cond,event: Reorder macros (cherry picked from commit a0a259205193c8fcfd3c0b9c58d5520cbdbfa6fe) Signed-off-by: LIU Hao --- src/cond.h | 2 +- src/event.h | 2 +- src/mutex.h | 6 +++--- src/once.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cond.h b/src/cond.h index 57f00d6e58..c7d6b511fb 100644 --- a/src/cond.h +++ b/src/cond.h @@ -20,8 +20,8 @@ struct __MCF_cond { uintptr_t __reserved : 9; - uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ #define __MCF_COND_NSLEEP_M (__UINTPTR_MAX__ >> 9) + uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ }; /* Initializes a condition variable dynamically. diff --git a/src/event.h b/src/event.h index d8617fb41f..9b04b030c2 100644 --- a/src/event.h +++ b/src/event.h @@ -21,8 +21,8 @@ struct __MCF_event uintptr_t __value : 8; uintptr_t __reserved : 1; - uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ #define __MCF_EVENT_NSLEEP_M (__UINTPTR_MAX__ >> 9) + uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ }; /* This is the maximum value of an event. */ diff --git a/src/mutex.h b/src/mutex.h index 504417328f..9071f6ced7 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -20,14 +20,14 @@ struct __MCF_mutex { uintptr_t __locked : 1; - uintptr_t __sp_mask : 4; /* mask of spinning threads; 1b/thread */ #define __MCF_MUTEX_SP_MASK_M 15U + uintptr_t __sp_mask : 4; /* mask of spinning threads; 1b/thread */ - uintptr_t __sp_nfail : 4; /* number of timeouts after spinning */ #define __MCF_MUTEX_SP_NFAIL_M 15U + uintptr_t __sp_nfail : 4; /* number of timeouts after spinning */ - uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ #define __MCF_MUTEX_NSLEEP_M (__UINTPTR_MAX__ >> 9) + uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ }; /* If the spinning failure counter has reached this number, newcomers will not diff --git a/src/once.h b/src/once.h index ea5f1e35de..5fecf830c4 100644 --- a/src/once.h +++ b/src/once.h @@ -21,8 +21,8 @@ struct __MCF_once uintptr_t __ready : 8; /* this conforms to the Itanium C++ ABI */ uintptr_t __locked : 1; - uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ #define __MCF_ONCE_NSLEEP_M (__UINTPTR_MAX__ >> 9) + uintptr_t __nsleep : __MCF_PTR_BITS - 9; /* number of sleeping threads */ }; /* Initializes a once-initialization flag dynamically. From 3cd18d2b5c58e7c4fcda568a0f408e776b0c58e3 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 2 Nov 2022 01:34:57 +0800 Subject: [PATCH 077/133] version,tls: Fix comments (cherry picked from commit 66cec39ad75ec5c9ea5a37d9a70c28f6f6a2948a) Signed-off-by: LIU Hao --- src/tls.h | 2 +- src/version.h.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tls.h b/src/tls.h index 458ce006ab..4dbc412588 100644 --- a/src/tls.h +++ b/src/tls.h @@ -82,7 +82,7 @@ int __MCF_tls_table_set(__MCF_tls_table* __table, _MCF_tls_key* __key, const void* __value_opt) __MCF_NOEXCEPT; /* Executes all destructors in the table, and frees dynamic storage if any. It - * is declared here for the sake of completeness, and is not meant to be call + * is declared here for the sake of completeness, and is not meant to be called * directly. */ __MCF_TLS_IMPORT void diff --git a/src/version.h.in b/src/version.h.in index 059f65e842..8f343ea4b0 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -9,4 +9,4 @@ #define _MCF_ABI_VERSION_MINOR @abi_minor@ #define _MCF_ABI_VERSION_STRING "@abi_major@.@abi_minor@-@abi_suffix@" -#endif +#endif /* __MCFGTHREAD_VERSION_ */ From f4b08dd02ea1ad667bb86581ec4fd96194493248 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 3 Nov 2022 23:48:21 +0800 Subject: [PATCH 078/133] dtor_queue,gthr_aux: Fix macro names (cherry picked from commit 6a5009eafa7595d2957822360f3fdd63a07d41fa) Signed-off-by: LIU Hao --- src/dtor_queue.c | 2 +- src/dtor_queue.h | 12 ++++++------ src/gthr_aux.c | 2 +- src/gthr_aux.h | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/dtor_queue.c b/src/dtor_queue.c index f906be7b4c..0863e471f1 100644 --- a/src/dtor_queue.c +++ b/src/dtor_queue.c @@ -3,7 +3,7 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_DTOR_QUEUE __MCF_DLLEXPORT +#define __MCF_DTOR_QUEUE_IMPORT __MCF_DLLEXPORT #define __MCF_DTOR_QUEUE_INLINE __MCF_DLLEXPORT #include "dtor_queue.h" #include "mutex.h" diff --git a/src/dtor_queue.h b/src/dtor_queue.h index 6c719a913c..830846cfe1 100644 --- a/src/dtor_queue.h +++ b/src/dtor_queue.h @@ -8,8 +8,8 @@ #include "fwd.h" __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_DTOR_QUEUE -# define __MCF_DECLSPEC_DTOR_QUEUE +#ifndef __MCF_DTOR_QUEUE_IMPORT +# define __MCF_DTOR_QUEUE_IMPORT # define __MCF_DTOR_QUEUE_INLINE __MCF_GNU_INLINE #endif @@ -35,7 +35,7 @@ struct __MCF_dtor_queue * ABI for details about DSO handles. * * Returns 0 if an element has been pushed, or -1 if out of memory. */ -__MCF_DECLSPEC_DTOR_QUEUE +__MCF_DTOR_QUEUE_IMPORT int __MCF_dtor_queue_push(__MCF_dtor_queue* __queue, const __MCF_dtor_element* __elem) __MCF_NOEXCEPT; @@ -45,7 +45,7 @@ __MCF_dtor_queue_push(__MCF_dtor_queue* __queue, const __MCF_dtor_element* __ele * DSO handles. * * Returns 0 if an element has been popped, or -1 if the queue is empty. */ -__MCF_DECLSPEC_DTOR_QUEUE +__MCF_DTOR_QUEUE_IMPORT int __MCF_dtor_queue_pop(__MCF_dtor_element* __elem, __MCF_dtor_queue* __queue, void* __dso) __MCF_NOEXCEPT; @@ -54,7 +54,7 @@ __MCF_dtor_queue_pop(__MCF_dtor_element* __elem, __MCF_dtor_queue* __queue, void * details about DSO handles. * * Returns the number of elements that have been removed. */ -__MCF_DECLSPEC_DTOR_QUEUE +__MCF_DTOR_QUEUE_IMPORT size_t __MCF_dtor_queue_remove(__MCF_dtor_queue* __queue, void* __dso) __MCF_NOEXCEPT; @@ -62,7 +62,7 @@ __MCF_dtor_queue_remove(__MCF_dtor_queue* __queue, void* __dso) __MCF_NOEXCEPT; * null, then all elements are considered matches. This function is used to * implement `__cxa_finalize()`. Refer to the Itanium C++ ABI for details about * DSO handles. */ -__MCF_DECLSPEC_DTOR_QUEUE +__MCF_DTOR_QUEUE_IMPORT void __MCF_dtor_queue_finalize(__MCF_dtor_queue* __queue, _MCF_mutex* __mutex_opt, void* __dso) __MCF_NOEXCEPT; diff --git a/src/gthr_aux.c b/src/gthr_aux.c index dd23748718..c52be77a54 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -3,7 +3,7 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DECLSPEC_GTHR_AUX __MCF_DLLEXPORT +#define __MCF_GTHR_AUX_IMPORT __MCF_DLLEXPORT #define __MCF_GTHR_AUX_INLINE __MCF_DLLEXPORT #include "gthr_aux.h" diff --git a/src/gthr_aux.h b/src/gthr_aux.h index 1dbf34d282..e2034cf6a9 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -13,8 +13,8 @@ #include /* struct timespec */ __MCF_C_DECLARATIONS_BEGIN -#ifndef __MCF_DECLSPEC_GTHR_AUX -# define __MCF_DECLSPEC_GTHR_AUX +#ifndef __MCF_GTHR_AUX_IMPORT +# define __MCF_GTHR_AUX_IMPORT # define __MCF_GTHR_AUX_INLINE __MCF_GNU_INLINE #endif @@ -49,32 +49,32 @@ __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT; /* This is an auxiliary function for converting a `struct timespec` to the * number of milliseconds since the Unix epoch, with boundary checking. */ -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT int64_t __MCF_gthr_timeout_from_timespec(const struct timespec* __abs_time) __MCF_NOEXCEPT __attribute__((__pure__)); /* These are auxiliary functions for condition variables. The argument is a * pointer to a plain `_MCF_mutex`. */ -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT intptr_t __MCF_gthr_mutex_unlock_callback(intptr_t __arg) __MCF_NOEXCEPT; -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT void __MCF_gthr_mutex_relock_callback(intptr_t __arg, intptr_t __unlocked) __MCF_NOEXCEPT; /* These are auxiliary functions for condition variables. The argument is a * pointer to a `__MCF_gthr_rc_mutex`. */ -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT intptr_t __MCF_gthr_recursive_mutex_unlock_callback(intptr_t __arg) __MCF_NOEXCEPT; -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT void __MCF_gthr_recursive_mutex_relock_callback(intptr_t __arg, intptr_t __unlocked) __MCF_NOEXCEPT; /* This is the actual thread function for a gthread. */ -__MCF_DECLSPEC_GTHR_AUX +__MCF_GTHR_AUX_IMPORT void __MCF_gthr_thread_thunk_v2(_MCF_thread* __thrd) __MCF_NOEXCEPT; From 6db15e7dfad2521adc4d9d6840da67e3331f8ca6 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 3 Nov 2022 23:48:21 +0800 Subject: [PATCH 079/133] dtor_queue,gthr_aux: Fix spacing (cherry picked from commit 52cd56311c8aa9ddbe989b1afd132b3e2d458144) Signed-off-by: LIU Hao --- src/dtor_queue.c | 2 +- src/gthr_aux.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dtor_queue.c b/src/dtor_queue.c index 0863e471f1..7f1113b73a 100644 --- a/src/dtor_queue.c +++ b/src/dtor_queue.c @@ -3,7 +3,7 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_DTOR_QUEUE_IMPORT __MCF_DLLEXPORT +#define __MCF_DTOR_QUEUE_IMPORT __MCF_DLLEXPORT #define __MCF_DTOR_QUEUE_INLINE __MCF_DLLEXPORT #include "dtor_queue.h" #include "mutex.h" diff --git a/src/gthr_aux.c b/src/gthr_aux.c index c52be77a54..f3dda5b94c 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -3,7 +3,7 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "precompiled.i" -#define __MCF_GTHR_AUX_IMPORT __MCF_DLLEXPORT +#define __MCF_GTHR_AUX_IMPORT __MCF_DLLEXPORT #define __MCF_GTHR_AUX_INLINE __MCF_DLLEXPORT #include "gthr_aux.h" From 8cf61ad8f075a8d3b808f170c997ee3298c891b8 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 4 Nov 2022 16:45:20 +0800 Subject: [PATCH 080/133] libcxx,ci: Fix 'check_includes.sh' (cherry picked from commit 4dcc6def5aa53046d3282cd686c05089a56c48f5) Signed-off-by: LIU Hao --- ci/check_includes.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/check_includes.sh b/ci/check_includes.sh index 9bad1b5cda..03728ad170 100755 --- a/ci/check_includes.sh +++ b/ci/check_includes.sh @@ -3,7 +3,7 @@ # setup export CC=${CC:-"gcc"} export CXX=${CXX:-"g++"} -export CPPFLAGS="-D_WIN32_WINNT=0x0601 -Wall -Wextra" +export CPPFLAGS="-D_WIN32_WINNT=0x0601 -Wall -Wextra "${CPPFLAGS} for _file in $(find -L "src" -name "*.h") do @@ -20,17 +20,17 @@ done for _file in $(find -L "src" -name "*.h") do echo "Checking header as C++11: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++11 -Wpedantic -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++11 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.h") do echo "Checking header as C++14: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++14 -Wpedantic -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++14 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.c") do echo "Checking source as C99: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c -std=c99 -Wpedantic -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c -std=c99 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done From d0165d42c8480ac15e2dce2b3749b9a1b2f8d7a0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 5 Nov 2022 18:00:19 +0800 Subject: [PATCH 081/133] ci: Update 'check_includes.sh' Do tell headers from source files, and remove the unused `CXX` variable. (cherry picked from commit 5e61052ba94c0e89e3cd4e9094c1220e7f25f053) Signed-off-by: LIU Hao --- ci/check_includes.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ci/check_includes.sh b/ci/check_includes.sh index 03728ad170..30c0eb1fe5 100755 --- a/ci/check_includes.sh +++ b/ci/check_includes.sh @@ -2,31 +2,30 @@ # setup export CC=${CC:-"gcc"} -export CXX=${CXX:-"g++"} export CPPFLAGS="-D_WIN32_WINNT=0x0601 -Wall -Wextra "${CPPFLAGS} for _file in $(find -L "src" -name "*.h") do echo "Checking header as C89: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c -std=c89 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c-header -std=c89 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.h") do echo "Checking header as C++98: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++98 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++98 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.h") do echo "Checking header as C++11: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++11 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++11 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.h") do echo "Checking header as C++14: ${_cmd} \"${_file}\"" - ${CC} ${CPPFLAGS} ${CFLAGS} -x c++ -std=c++14 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} + ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++14 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done for _file in $(find -L "src" -name "*.c") From 948a1645ec019029e35f045d167beb88c3b25ff3 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 5 Nov 2022 21:46:12 +0800 Subject: [PATCH 082/133] xglobals: Remove parameter names from declarations (cherry picked from commit b328364ef1759748104b9a21b96dd8052291d4d0) Signed-off-by: LIU Hao --- src/xglobals.i | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xglobals.i b/src/xglobals.i index 623a0e25ac..d4b31e9706 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -92,7 +92,7 @@ __MCF_WINAPI(void, ExitThread, DWORD) __attribute__((__noreturn__)); __MCF_WINAPI(BOOL, SwitchToThread, void); __MCF_WINAPI(BOOL, TerminateProcess, HANDLE, UINT); -typedef BOOL __stdcall HANDLER_ROUTINE(DWORD CtrlType); +typedef BOOL __stdcall HANDLER_ROUTINE(DWORD); __MCF_WINAPI(BOOL, SetConsoleCtrlHandler, HANDLER_ROUTINE*, BOOL); /* Declare NTDLL (driver) APIs here. */ From d66e23c31b36406ba41ec2aa1a23da6efc598207 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 5 Nov 2022 23:34:38 +0800 Subject: [PATCH 083/133] thread: Fix comments (cherry picked from commit 08fc449433b80c0d51443de3ce564814e8ca3078) Signed-off-by: LIU Hao --- src/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.h b/src/thread.h index 3bf08ebebb..4a01c85c76 100644 --- a/src/thread.h +++ b/src/thread.h @@ -24,7 +24,7 @@ struct __MCF_thread __MCF_HANDLE __handle; /* win32 thread handle */ _MCF_thread_procedure* __proc; /* user-defined thread procedure */ - void* __data_ptr; /* pointer to user-defined data. */ + void* __data_ptr; /* pointer to user-defined data */ __MCF_dtor_queue __atexit_queue[1]; /* for `__cxa_thread_atexit()` */ __MCF_tls_table __tls_table[1]; /* for `_MCF_tls_get()` and `_MCF_tls_set()` */ From 7b89b1f83d836815c0cb5a92aad96ff636fb8507 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 7 Nov 2022 15:23:25 +0800 Subject: [PATCH 084/133] test: Backport tests from master Signed-off-by: LIU Hao (cherry picked from commit 11b00bb1880afc0aca6fad4708e09425c809f016) Signed-off-by: LIU Hao --- test/c11_inline_alias.c | 130 +++++++++++++++++++++++++++++++-------- test/gthr_inline_alias.c | 71 ++++++++++++++++----- 2 files changed, 162 insertions(+), 39 deletions(-) diff --git a/test/c11_inline_alias.c b/test/c11_inline_alias.c index 0964bd6996..be9be0d656 100644 --- a/test/c11_inline_alias.c +++ b/test/c11_inline_alias.c @@ -8,31 +8,111 @@ int main(void) { - __MCF_STATIC_ASSERT(__MCF_c11_call_once == call_once); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_broadcast == cnd_broadcast); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_destroy == cnd_destroy); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_init == cnd_init); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_signal == cnd_signal); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_timedwait == cnd_timedwait); - __MCF_STATIC_ASSERT(__MCF_c11_cnd_wait == cnd_wait); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_destroy == mtx_destroy); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_init == mtx_init); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_lock == mtx_lock); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_timedlock == mtx_timedlock); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_trylock == mtx_trylock); - __MCF_STATIC_ASSERT(__MCF_c11_mtx_unlock == mtx_unlock); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_create == thrd_create); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_current == thrd_current); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_detach == thrd_detach); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_equal == thrd_equal); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_exit == thrd_exit); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_join == thrd_join); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_sleep == thrd_sleep); - __MCF_STATIC_ASSERT(__MCF_c11_thrd_yield == thrd_yield); - __MCF_STATIC_ASSERT(__MCF_c11_tss_create == tss_create); - __MCF_STATIC_ASSERT(__MCF_c11_tss_delete == tss_delete); - __MCF_STATIC_ASSERT(__MCF_c11_tss_get == tss_get); - __MCF_STATIC_ASSERT(__MCF_c11_tss_set == tss_set); +// FIXME: We need to figure out how to simulate this first... +// See https://github.com/lhmouse/mcfgthread/issues/73. +return 77; + + volatile intptr_t mcfp, gthp; + + mcfp = (intptr_t) __MCF_c11_call_once; + gthp = (intptr_t) call_once; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_broadcast; + gthp = (intptr_t) cnd_broadcast; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_destroy; + gthp = (intptr_t) cnd_destroy; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_init; + gthp = (intptr_t) cnd_init; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_signal; + gthp = (intptr_t) cnd_signal; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_timedwait; + gthp = (intptr_t) cnd_timedwait; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_cnd_wait; + gthp = (intptr_t) cnd_wait; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_destroy; + gthp = (intptr_t) mtx_destroy; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_init; + gthp = (intptr_t) mtx_init; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_lock; + gthp = (intptr_t) mtx_lock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_timedlock; + gthp = (intptr_t) mtx_timedlock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_trylock; + gthp = (intptr_t) mtx_trylock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_mtx_unlock; + gthp = (intptr_t) mtx_unlock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_create; + gthp = (intptr_t) thrd_create; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_current; + gthp = (intptr_t) thrd_current; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_detach; + gthp = (intptr_t) thrd_detach; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_equal; + gthp = (intptr_t) thrd_equal; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_exit; + gthp = (intptr_t) thrd_exit; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_join; + gthp = (intptr_t) thrd_join; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_sleep; + gthp = (intptr_t) thrd_sleep; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_thrd_yield; + gthp = (intptr_t) thrd_yield; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_tss_create; + gthp = (intptr_t) tss_create; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_tss_delete; + gthp = (intptr_t) tss_delete; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_tss_get; + gthp = (intptr_t) tss_get; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_c11_tss_set; + gthp = (intptr_t) tss_set; + assert(mcfp == gthp); return 0; } diff --git a/test/gthr_inline_alias.c b/test/gthr_inline_alias.c index d88386449e..8db62ead6b 100644 --- a/test/gthr_inline_alias.c +++ b/test/gthr_inline_alias.c @@ -8,20 +8,63 @@ int main(void) { - __MCF_STATIC_ASSERT(__MCF_gthr_active_p == __gthread_active_p); - __MCF_STATIC_ASSERT(__MCF_gthr_getspecific == __gthread_getspecific); - __MCF_STATIC_ASSERT(__MCF_gthr_key_create == __gthread_key_create); - __MCF_STATIC_ASSERT(__MCF_gthr_key_delete == __gthread_key_delete); - __MCF_STATIC_ASSERT(__MCF_gthr_mutex_destroy == __gthread_mutex_destroy); - __MCF_STATIC_ASSERT(__MCF_gthr_mutex_lock == __gthread_mutex_lock); - __MCF_STATIC_ASSERT(__MCF_gthr_mutex_trylock == __gthread_mutex_trylock); - __MCF_STATIC_ASSERT(__MCF_gthr_mutex_unlock == __gthread_mutex_unlock); - __MCF_STATIC_ASSERT(__MCF_gthr_once == __gthread_once); - __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_destroy == __gthread_recursive_mutex_destroy); - __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_lock == __gthread_recursive_mutex_lock); - __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_trylock == __gthread_recursive_mutex_trylock); - __MCF_STATIC_ASSERT(__MCF_gthr_recursive_mutex_unlock == __gthread_recursive_mutex_unlock); - __MCF_STATIC_ASSERT(__MCF_gthr_setspecific == __gthread_setspecific); + volatile intptr_t mcfp, gthp; + + mcfp = (intptr_t) __MCF_gthr_active_p; + gthp = (intptr_t) __gthread_active_p; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_getspecific; + gthp = (intptr_t) __gthread_getspecific; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_key_create; + gthp = (intptr_t) __gthread_key_create; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_key_delete; + gthp = (intptr_t) __gthread_key_delete; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_mutex_destroy; + gthp = (intptr_t) __gthread_mutex_destroy; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_mutex_lock; + gthp = (intptr_t) __gthread_mutex_lock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_mutex_trylock; + gthp = (intptr_t) __gthread_mutex_trylock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_mutex_unlock; + gthp = (intptr_t) __gthread_mutex_unlock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_once; + gthp = (intptr_t) __gthread_once; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_recursive_mutex_destroy; + gthp = (intptr_t) __gthread_recursive_mutex_destroy; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_recursive_mutex_lock; + gthp = (intptr_t) __gthread_recursive_mutex_lock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_recursive_mutex_trylock; + gthp = (intptr_t) __gthread_recursive_mutex_trylock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_recursive_mutex_unlock; + gthp = (intptr_t) __gthread_recursive_mutex_unlock; + assert(mcfp == gthp); + + mcfp = (intptr_t) __MCF_gthr_setspecific; + gthp = (intptr_t) __gthread_setspecific; + assert(mcfp == gthp); return 0; } From a3d9d1ab3a92301bbe3e22c3c535d58cd51f98ed Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 7 Nov 2022 15:40:14 +0800 Subject: [PATCH 085/133] xglobals: Fix use of `__MCF_SEH_I386_NODE_NAME` (cherry picked from commit 0f92815971caba0aa05622252dc9bcab2e560af0) Signed-off-by: LIU Hao --- src/xglobals.i | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/xglobals.i b/src/xglobals.i index d4b31e9706..21d04479f4 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -141,7 +141,8 @@ __MCF_seh_i386_cleanup(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT __asm__ volatile ("{ movl %0, %%fs:0 | mov fs:[0], %0 }" : : "r"(__seh_node->__next)); } -# define __MCF_SEH_I386_NODE_NX(n) __MCF_seh_i386_node_##n +# define __MCF_SEH_I386_NODE_NY(n) __MCF_seh_i386_node_##n +# define __MCF_SEH_I386_NODE_NX(n) __MCF_SEH_I386_NODE_NY(n) # define __MCF_SEH_I386_NODE_NAME __MCF_SEH_I386_NODE_NX(__LINE__) # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ From b2da386818f418a6bdb0d23fe1c95eb3882dc323 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 22 Oct 2022 02:07:44 +0800 Subject: [PATCH 086/133] xglobals: Add alias `(null)` back (cherry picked from commit b6b397a34eef7912be32bae0c5a369b009eb743f) Signed-off-by: LIU Hao --- src/xglobals.i | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index 21d04479f4..04562d0dd2 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -119,6 +119,8 @@ __MCF_seh_top(EXCEPTION_RECORD* __rec, PVOID __estab_frame, CONTEXT* __ctx, PVOI #if defined(__i386__) /* On x86, SEH is stack-based. */ +typedef struct __MCF_seh_i386_node __MCF_seh_i386_node; + struct __MCF_seh_i386_node { DWORD __next; @@ -127,7 +129,7 @@ struct __MCF_seh_i386_node __MCF_ALWAYS_INLINE void -__MCF_seh_i386_install(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT +__MCF_seh_i386_install(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT { __asm__ volatile ("{ movl %%fs:0, %0 | mov %0, fs:[0] }" : "=r"(__seh_node->__next)); __seh_node->__filter = (DWORD) __MCF_seh_top; @@ -136,7 +138,7 @@ __MCF_seh_i386_install(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT __MCF_ALWAYS_INLINE void -__MCF_seh_i386_cleanup(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT +__MCF_seh_i386_cleanup(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT { __asm__ volatile ("{ movl %0, %%fs:0 | mov fs:[0], %0 }" : : "r"(__seh_node->__next)); } @@ -146,7 +148,7 @@ __MCF_seh_i386_cleanup(struct __MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT # define __MCF_SEH_I386_NODE_NAME __MCF_SEH_I386_NODE_NX(__LINE__) # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - struct __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME \ + __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME \ __attribute__((__cleanup__(__MCF_seh_i386_cleanup))); \ __MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME) /* no semicolon */ #else From 0449ccd1a0a10c320c844e47897b43a2c897c9b5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 11:50:06 +0800 Subject: [PATCH 087/133] xglobals: Sqaush `__MCF_SEH_DEFINE_TERMINATE_FILTER` into a single definition (cherry picked from commit 0003025a6eeed71f66647b38cff74c57c8f4f421) Signed-off-by: LIU Hao --- src/xglobals.i | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index 04562d0dd2..347958f63d 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -128,12 +128,13 @@ struct __MCF_seh_i386_node }; __MCF_ALWAYS_INLINE -void +__MCF_seh_i386_node* __MCF_seh_i386_install(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT { __asm__ volatile ("{ movl %%fs:0, %0 | mov %0, fs:[0] }" : "=r"(__seh_node->__next)); __seh_node->__filter = (DWORD) __MCF_seh_top; __asm__ volatile ("{ movl %0, %%fs:0 | mov fs:[0], %0 }" : : "r"(__seh_node)); + return __seh_node; } __MCF_ALWAYS_INLINE @@ -149,8 +150,8 @@ __MCF_seh_i386_cleanup(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME \ - __attribute__((__cleanup__(__MCF_seh_i386_cleanup))); \ - __MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME) /* no semicolon */ + __attribute__((__cleanup__(__MCF_seh_i386_cleanup))) \ + = *__MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME) /* no semicolon */ #else /* Otherwise, SEH is table-based. */ # ifdef __arm__ From f94425fd3a70c94c1eb59813fb20d8b75e29c37c Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 11:51:36 +0800 Subject: [PATCH 088/133] xglobals: Rename some macros (cherry picked from commit add240d1d138db992a704e974e87927e00ff9723) Signed-off-by: LIU Hao --- src/xglobals.i | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index 347958f63d..abeb9b1f15 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -146,12 +146,12 @@ __MCF_seh_i386_cleanup(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT # define __MCF_SEH_I386_NODE_NY(n) __MCF_seh_i386_node_##n # define __MCF_SEH_I386_NODE_NX(n) __MCF_SEH_I386_NODE_NY(n) -# define __MCF_SEH_I386_NODE_NAME __MCF_SEH_I386_NODE_NX(__LINE__) +# define __MCF_SEH_I386_NODE_NAME_HERE __MCF_SEH_I386_NODE_NX(__LINE__) # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME \ + __MCF_seh_i386_node __MCF_SEH_I386_NODE_NAME_HERE \ __attribute__((__cleanup__(__MCF_seh_i386_cleanup))) \ - = *__MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME) /* no semicolon */ + = *__MCF_seh_i386_install(&__MCF_SEH_I386_NODE_NAME_HERE) /* no semicolon */ #else /* Otherwise, SEH is table-based. */ # ifdef __arm__ From e7e78494cbf5a2137217528534b84379de708210 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 16:42:03 +0800 Subject: [PATCH 089/133] xglobals: Reformat `__MCF_SEH_DEFINE_TERMINATE_FILTER` (cherry picked from commit ad60be30274f5f20f31407e6780f1df479570efc) Signed-off-by: LIU Hao --- src/xglobals.i | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index abeb9b1f15..6bf657b1f9 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -161,8 +161,8 @@ __MCF_seh_i386_cleanup(__MCF_seh_i386_node* __seh_node) __MCF_NOEXCEPT # endif # define __MCF_SEH_DEFINE_TERMINATE_FILTER \ - __asm__ volatile (".seh_handler __MCF_seh_top, " \ - __MCF_SEH_FLAG_PREFIX "except") /* no semicolon */ + __asm__ volatile (".seh_handler " \ + " __MCF_seh_top, " __MCF_SEH_FLAG_PREFIX "except") /* no semicolon */ #endif /* This structure contains timeout values that will be passed to NT syscalls. */ From 82b75b5d75d99c6745fdef9bb80d742de2406c20 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 22:51:18 +0800 Subject: [PATCH 090/133] fwd: Add an alias for `struct ::timespec` (cherry picked from commit cbbe488fdd48f8fba819f28db68e7285b03a2977) Signed-off-by: LIU Hao --- src/c11.c | 4 ++-- src/c11.h | 10 +++++----- src/fwd.h | 1 + src/gthr.h | 2 +- src/gthr_aux.c | 2 +- src/gthr_aux.h | 4 ++-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/c11.c b/src/c11.c index 453d96d60a..be47cb0755 100644 --- a/src/c11.c +++ b/src/c11.c @@ -20,7 +20,7 @@ __MCF_c11_thread_thunk_v2(_MCF_thread* thrd) __MCF_DLLEXPORT int -__MCF_c11_thrd_sleep(const struct timespec* dur, struct timespec* rem_opt) +__MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) { double value = 0.0009999; value += (double) dur->tv_nsec * 0.000001; @@ -47,7 +47,7 @@ __MCF_c11_thrd_sleep(const struct timespec* dur, struct timespec* rem_opt) rem_opt->tv_nsec = (long) ((value - (double) rem_opt->tv_sec) * 1000000000); } else if(rem_opt) - *rem_opt = (struct timespec) __MCF_0_INIT; + *rem_opt = (__MCF_timespec) __MCF_0_INIT; /* Return 0 in case of timeouts, and -1 in case of interrupts. */ return err; diff --git a/src/c11.h b/src/c11.h index f1e6c8270f..dd50e2c55b 100644 --- a/src/c11.h +++ b/src/c11.h @@ -124,7 +124,7 @@ __MCF_ALIAS(cnd_signal, __MCF_c11_cnd_signal); /* 7.26.3.5 The cnd_timedwait function */ __MCF_C11_INLINE int -__MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; +__MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT; #ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(cnd_timedwait, __MCF_c11_cnd_timedwait); @@ -169,7 +169,7 @@ __MCF_ALIAS(mtx_lock, __MCF_c11_mtx_lock); /* 7.26.4.4 The mtx_timedlock function */ __MCF_C11_INLINE int -__MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT; +__MCF_c11_mtx_timedlock(mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT; #ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(mtx_timedlock, __MCF_c11_mtx_timedlock); @@ -250,7 +250,7 @@ __MCF_ALIAS(thrd_join, __MCF_c11_thrd_join); /* 7.26.5.7 The thrd_sleep function */ __MCF_C11_IMPORT int -__MCF_c11_thrd_sleep(const struct timespec* __dur, struct timespec* __rem_opt) __MCF_NOEXCEPT; +__MCF_c11_thrd_sleep(const __MCF_timespec* __dur, __MCF_timespec* __rem_opt) __MCF_NOEXCEPT; #ifndef __MCF_C11_NO_ALIASES __MCF_ALIAS(thrd_sleep, __MCF_c11_thrd_sleep); @@ -354,7 +354,7 @@ __MCF_c11_cnd_signal(cnd_t* __cond) __MCF_NOEXCEPT __MCF_C11_INLINE int -__MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT +__MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__ts); int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, &__timeout); @@ -432,7 +432,7 @@ __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT __MCF_C11_INLINE int -__MCF_c11_mtx_timedlock(mtx_t* __mtx, const struct timespec* __ts) __MCF_NOEXCEPT +__MCF_c11_mtx_timedlock(mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT { int64_t __timeout; int __err; diff --git a/src/fwd.h b/src/fwd.h index 9f4a0873a0..21f96f1dc2 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -148,6 +148,7 @@ typedef struct __MCF_event _MCF_event; typedef struct __MCF_thread _MCF_thread; typedef struct __MCF_tls_key _MCF_tls_key; +typedef struct timespec __MCF_timespec; typedef void* __MCF_HANDLE; /* See `_MCF_cond_wait()` for details about these callbacks. */ diff --git a/src/gthr.h b/src/gthr.h index 106a3f24a1..2879c142c2 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -21,7 +21,7 @@ __MCF_C_DECLARATIONS_BEGIN /* Define gthread types. These usually map to our APIs directly, except * the recursive mutex. */ -typedef struct timespec __gthread_time_t; +typedef __MCF_timespec __gthread_time_t; typedef _MCF_thread* __gthread_t; typedef _MCF_tls_key* __gthread_key_t; diff --git a/src/gthr_aux.c b/src/gthr_aux.c index f3dda5b94c..bdb8b4a3ef 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -9,7 +9,7 @@ __MCF_DLLEXPORT int64_t -__MCF_gthr_timeout_from_timespec(const struct timespec* abs_time) +__MCF_gthr_timeout_from_timespec(const __MCF_timespec* abs_time) { double value = 0.0009999; value += (double) abs_time->tv_nsec * 0.000001; diff --git a/src/gthr_aux.h b/src/gthr_aux.h index e2034cf6a9..12b0c3daa6 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -47,11 +47,11 @@ __MCF_GTHR_AUX_INLINE void __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT; -/* This is an auxiliary function for converting a `struct timespec` to the +/* This is an auxiliary function for converting a `__MCF_timespec` to the * number of milliseconds since the Unix epoch, with boundary checking. */ __MCF_GTHR_AUX_IMPORT int64_t -__MCF_gthr_timeout_from_timespec(const struct timespec* __abs_time) __MCF_NOEXCEPT __attribute__((__pure__)); +__MCF_gthr_timeout_from_timespec(const __MCF_timespec* __abs_time) __MCF_NOEXCEPT __attribute__((__pure__)); /* These are auxiliary functions for condition variables. The argument is a * pointer to a plain `_MCF_mutex`. */ From e08f0a98cdefb0cb06fcc516c6c455321bab2c8a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 23:01:25 +0800 Subject: [PATCH 091/133] xglobals: Add `__MCF_close_handle()` for simplicity (cherry picked from commit f33b8cdc13e607014f09959a63267b1388eff157) Signed-off-by: LIU Hao --- src/thread.c | 3 +-- src/xglobals.i | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/thread.c b/src/thread.c index 458fc69e5b..5ded6cf1c9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -83,8 +83,7 @@ _MCF_thread_drop_ref_nonnull(_MCF_thread* thrd) if(thrd == &__MCF_main_thread) return; - NTSTATUS status = NtClose(thrd->__handle); - __MCF_ASSERT(NT_SUCCESS(status)); + __MCF_close_handle(thrd->__handle); __MCF_mfree(thrd); } diff --git a/src/xglobals.i b/src/xglobals.i index 6bf657b1f9..aaeb07516b 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -285,6 +285,14 @@ __MCF_keyed_event_signal(const void* __key, const LARGE_INTEGER* __timeout) __MC return __status; } +__MCF_ALWAYS_INLINE +void +__MCF_close_handle(__MCF_HANDLE __handle) __MCF_NOEXCEPT + { + NTSTATUS __status = NtClose(__handle); + __MCF_ASSERT(NT_SUCCESS(__status)); + } + #if defined(__i386__) || defined(__amd64__) /* Define macros for string operations for reducing code size. */ # define __MCF_X86_REP_STOSB(di, cx, ax) \ From 7bded2f2a835b7ad4311f0bda92360f737a91500 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 23:04:53 +0800 Subject: [PATCH 092/133] xglobals: Add `__MCF_ASSERT_NT()` macro (cherry picked from commit 5388e3973ecf578036cbad67a25d1c7f8be6927e) Signed-off-by: LIU Hao --- src/thread.c | 2 +- src/xglobals.i | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/thread.c b/src/thread.c index 5ded6cf1c9..706c949a1b 100644 --- a/src/thread.c +++ b/src/thread.c @@ -106,7 +106,7 @@ _MCF_thread_wait(const _MCF_thread* thrd_opt, const int64_t* timeout_opt) __MCF_initialize_winnt_timeout_v2(&nt_timeout, timeout_opt); NTSTATUS status = NtWaitForSingleObject(thrd_opt->__handle, false, nt_timeout.__li); - __MCF_ASSERT(NT_SUCCESS(status)); + __MCF_ASSERT_NT(status); return (status != STATUS_WAIT_0) ? -1 : 0; } diff --git a/src/xglobals.i b/src/xglobals.i index aaeb07516b..eefe92d396 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -57,7 +57,8 @@ extern BYTE __MCF_mutex_spin_field[2048]; #define GetCurrentProcess() ((HANDLE) -1) #define GetCurrentThread() ((HANDLE) -2) -#define __MCF_CHECK_NT(...) __MCF_CHECK(NT_SUCCESS(__VA_ARGS__)) +#define __MCF_ASSERT_NT(...) __MCF_ASSERT(NT_SUCCESS(__VA_ARGS__)) +#define __MCF_CHECK_NT(...) __MCF_CHECK(NT_SUCCESS(__VA_ARGS__)) #define __MCF_WINAPI(RETURN, function, ...) \ RETURN __stdcall function(__VA_ARGS__) __attribute__((__dllimport__, __nothrow__)) @@ -272,7 +273,7 @@ NTSTATUS __MCF_keyed_event_wait(const void* __key, const LARGE_INTEGER* __timeout) __MCF_NOEXCEPT { NTSTATUS __status = NtWaitForKeyedEvent(NULL, (PVOID) __key, 0, (LARGE_INTEGER*) __timeout); - __MCF_ASSERT(NT_SUCCESS(__status)); + __MCF_ASSERT_NT(__status); return __status; } @@ -281,7 +282,7 @@ NTSTATUS __MCF_keyed_event_signal(const void* __key, const LARGE_INTEGER* __timeout) __MCF_NOEXCEPT { NTSTATUS __status = NtReleaseKeyedEvent(NULL, (PVOID) __key, 0, (LARGE_INTEGER*) __timeout); - __MCF_ASSERT(NT_SUCCESS(__status)); + __MCF_ASSERT_NT(__status); return __status; } @@ -290,7 +291,7 @@ void __MCF_close_handle(__MCF_HANDLE __handle) __MCF_NOEXCEPT { NTSTATUS __status = NtClose(__handle); - __MCF_ASSERT(NT_SUCCESS(__status)); + __MCF_ASSERT_NT(__status); } #if defined(__i386__) || defined(__amd64__) From cc78890d3aed10c803fe83527b62aeee15fd6488 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 23:14:16 +0800 Subject: [PATCH 093/133] doc: Hard-wrap lines in LICENSE.TXT (cherry picked from commit 132f69ede963cd2de081eb40c3bfcbdc865bb04d) Signed-off-by: LIU Hao --- LICENSE.TXT | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/LICENSE.TXT b/LICENSE.TXT index 658daa6223..a4072f5de4 100644 --- a/LICENSE.TXT +++ b/LICENSE.TXT @@ -1,25 +1,25 @@ -Files that are conventionally called 'headers', whose names shall end with -the extended regular expression `\.[hci](pp)?`, are placed into the public -domain, without any warranty. The other files are licensed under LGPL. This -guarantees most developers enough freedom to do whatever they want with -these headers. +Files that are conventionally called 'headers', whose names shall end +with the extended regular expression `\.[hci](pp)?`, are placed into the +public domain, without any warranty. The other files are licensed under +LGPL. This guarantees most developers enough freedom to do whatever they +want with these headers. -============================================================================ +======================================================================== -MCF Gthread is free software: you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) -any later version. +MCF Gthread is free software: you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or (at +your option) any later version. -MCF Gthread is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License -for more details. +MCF Gthread is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with MCF Gthread. If not, see . -============================================================================ +======================================================================== GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 From 00012d2642f3596932d0da527d325429623b0ec4 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 23:25:21 +0800 Subject: [PATCH 094/133] Update README.md (cherry picked from commit bf22f852a3a19b3f2d1dcdf5bfb673482dcec819) Signed-off-by: LIU Hao --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92109c0b59..1ac35727b4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ make -j$(nproc) # Notes -In order for `__cxa_atexit()` (and the non-standard `__cxa_at_quick_exit()`) to conform to the Itanium C++ ABI, it is required 1) for a process to call `__cxa_finalize(NULL)` when exiting, and 2) for a DLL to call `__cxa_finalize(&__dso_handle)` when it is unloaded dynamically. This requires [hacking the CRT](https://github.com/lhmouse/MINGW-packages/blob/master/mingw-w64-crt-git/9000-crt-Remove-stuff-that-has-been-provided-by-mcfgthrea.patch). If you don't have the modified CRT, you may still get standard compliance by 1) calling `__MCF_exit()` instead of `exit()` from your program, and 2) calling `__cxa_finalize(&__dso_handle)` followed by `fflush(NULL)` upon receipt of `DLL_PROCESS_DETACH` in your `DllMain()`. +In order for `__cxa_atexit()` (and the non-standard `__cxa_at_quick_exit()`) to conform to the Itanium C++ ABI, it is required 1) for a process to call `__cxa_finalize(NULL)` when exiting, and 2) for a DLL to call `__cxa_finalize(&__dso_handle)` when it is unloaded dynamically. This requires [hacking the CRT](https://github.com/lhmouse/MINGW-packages/blob/0274a6e7e0da258cf5e32efe6e4427454741fa32/mingw-w64-crt-git/9003-crt-Implement-standard-conforming-termination-suppor.patch). If you don't have the modified CRT, you may still get standard compliance by 1) calling `__MCF_exit()` instead of `exit()` from your program, and 2) calling `__cxa_finalize(&__dso_handle)` followed by `fflush(NULL)` upon receipt of `DLL_PROCESS_DETACH` in your `DllMain()`. This project is developed and tested on x86 and x64 and hasn't been tested on other CPU architectures. From 04b9ed31311b6294d08253244d5f35664fc2d463 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 8 Nov 2022 23:59:16 +0800 Subject: [PATCH 095/133] version: Remove an unused `#include` (cherry picked from commit 04ea510e686c9fea4f1dfc61708c44626fdabac4) Signed-off-by: LIU Hao --- src/version.rc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/version.rc b/src/version.rc index 7ff1181553..35898b2fe2 100644 --- a/src/version.rc +++ b/src/version.rc @@ -3,7 +3,6 @@ * Copyleft 2022, LH_Mouse. All wrongs reserved. */ #include "version.h" -#include "config.h" #include VS_VERSION_INFO VERSIONINFO From 63a83a711295e3c32b6919cbe947e6566bde2ca0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 9 Nov 2022 22:40:05 +0800 Subject: [PATCH 096/133] c11: Add a type alias for `struct __MCF_c11_mutex` (cherry picked from commit faaad22d8bc50ff707f877c992a2662513bea179) Signed-off-by: LIU Hao (cherry picked from commit 5b04dfe816ca18ec2970589ead0633ba5cf95224) Signed-off-by: LIU Hao --- src/c11.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/c11.h b/src/c11.h index dd50e2c55b..5d58a1bcb0 100644 --- a/src/c11.h +++ b/src/c11.h @@ -24,6 +24,7 @@ __MCF_C_DECLARATIONS_BEGIN /* Define types. These usually map to our APIs directly, except * the mutex. */ +typedef struct __MCF_c11_mutex __MCF_c11_mutex; typedef struct __MCF_c11_thread_record __MCF_c11_thread_record; typedef int __MCF_c11_thread_procedure(void* __arg); @@ -50,7 +51,7 @@ typedef _MCF_tls_dtor* tss_dtor_t; typedef _MCF_once once_flag; typedef _MCF_cond cnd_t; -typedef struct __MCF_c11_mutex mtx_t; +typedef __MCF_c11_mutex mtx_t; /* This is the actual thread function for a C11 thread. */ __MCF_C11_IMPORT From 69b92374d9ab5b5de4bf0ad37c5f0edd4eca2448 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 9 Nov 2022 22:43:19 +0800 Subject: [PATCH 097/133] c11,gthr: Rename parameters --- src/c11.h | 20 ++++++------- src/gthr.h | 48 +++++++++++++++--------------- src/gthr_aux.h | 40 ++++++++++++------------- test/c11_cnd_consumers.c | 12 ++++---- test/c11_cnd_consumers_recursive.c | 18 +++++------ test/c11_mtx_nonrecursive.c | 4 +-- test/c11_mtx_timeout.c | 2 +- 7 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/c11.h b/src/c11.h index 5d58a1bcb0..fb2704c0b5 100644 --- a/src/c11.h +++ b/src/c11.h @@ -31,7 +31,7 @@ typedef int __MCF_c11_thread_procedure(void* __arg); struct __MCF_c11_mutex { uint8_t __type; /* bit mask of `__MCF_mtx_type` */ - __MCF_gthr_rc_mutex __rc_mtx[1]; + __MCF_gthr_rc_mutex __rc_mutex[1]; }; struct __MCF_c11_thread_record @@ -358,7 +358,7 @@ int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__ts); - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, &__timeout); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mutex, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -366,7 +366,7 @@ __MCF_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT { - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, NULL); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mutex, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -393,7 +393,7 @@ __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT case mtx_timed | mtx_recursive: /* Initialize an unowned mutex. */ __mtx->__type = (uint8_t) __type; - __MCF_gthr_rc_mutex_init(__mtx->__rc_mtx); + __MCF_gthr_rc_mutex_init(__mtx->__rc_mutex); return thrd_success; } } @@ -403,14 +403,14 @@ int __MCF_c11_mtx_check_recursion(mtx_t* __mtx) __MCF_NOEXCEPT { /* Check for recursion. */ - int __err = __MCF_gthr_rc_mutex_recurse(__mtx->__rc_mtx); + int __err = __MCF_gthr_rc_mutex_recurse(__mtx->__rc_mutex); if(__err != 0) return thrd_busy; /* If recursion has happened but the mutex is not recursive, undo the * operation, and fail. */ if(!(__mtx->__type & mtx_recursive)) { - __mtx->__rc_mtx[0].__depth --; + __mtx->__rc_mutex[0].__depth --; return thrd_error; } @@ -426,7 +426,7 @@ __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT if(__err != thrd_busy) return __err; - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, NULL); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -446,7 +446,7 @@ __MCF_c11_mtx_timedlock(mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT return __err; __timeout = __MCF_gthr_timeout_from_timespec(__ts); - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -462,7 +462,7 @@ __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT return __err; __timeout = 0; - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, &__timeout); return (__err != 0) ? thrd_busy : thrd_success; } @@ -470,7 +470,7 @@ __MCF_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_release(__mtx->__rc_mtx); + __MCF_gthr_rc_mutex_release(__mtx->__rc_mutex); return 0; } diff --git a/src/gthr.h b/src/gthr.h index 2879c142c2..1b2d1550cb 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -152,7 +152,7 @@ __MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); @@ -161,7 +161,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); /* Destroys a recursive mutex. This function does nothing. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); @@ -170,7 +170,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destro /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); @@ -180,7 +180,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); * `pthread_mutex_trylock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); @@ -190,7 +190,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_tryloc * `pthread_mutex_timedlock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmutex, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); @@ -199,7 +199,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_time /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); @@ -237,7 +237,7 @@ __MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; +__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); @@ -443,66 +443,66 @@ __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_init(__rmtx); + __MCF_gthr_rc_mutex_init(__rmutex); return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { - (void) __rmtx; + (void) __rmutex; return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { - int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); + int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); if(__err == 0) return 0; - __err = __MCF_gthr_rc_mutex_wait(__rmtx, NULL); + __err = __MCF_gthr_rc_mutex_wait(__rmutex, NULL); __MCF_ASSERT(__err == 0); return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { int64_t __timeout; - int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); + int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); if(__err == 0) return 0; __timeout = 0; - __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__rmutex, &__timeout); return __err; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmutex, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT { int64_t __timeout; - int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); + int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); if(__err == 0) return 0; __timeout = __MCF_gthr_timeout_from_timespec(__abs_time); - __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__rmutex, &__timeout); return __err; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_release(__rmtx); + __MCF_gthr_rc_mutex_release(__rmutex); return 0; } @@ -533,9 +533,9 @@ __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_N __MCF_GTHR_INLINE int -__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT { - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __rmtx, NULL); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __rmutex, NULL); __MCF_ASSERT(__err == 0); return 0; } diff --git a/src/gthr_aux.h b/src/gthr_aux.h index 12b0c3daa6..b2bffc7691 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -93,57 +93,57 @@ __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT __MCF_ALWAYS_INLINE void -__MCF_gthr_rc_mutex_init(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_init(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT { - __rmtx->__owner[0] = 0; - __rmtx->__depth = 0; - _MCF_mutex_init(__rmtx->__mutex); + __rmutex->__owner[0] = 0; + __rmutex->__depth = 0; + _MCF_mutex_init(__rmutex->__mutex); } __MCF_ALWAYS_INLINE int -__MCF_gthr_rc_mutex_recurse(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_recurse(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT { /* Check whether the mutex has already been owned. */ - if(_MCF_atomic_load_32_rlx(__rmtx->__owner) != (int32_t) _MCF_thread_self_tid()) + if(_MCF_atomic_load_32_rlx(__rmutex->__owner) != (int32_t) _MCF_thread_self_tid()) return -1; /* Increment the recursion count. */ - __MCF_ASSERT(__rmtx->__depth < __INT32_MAX__); - __rmtx->__depth ++; + __MCF_ASSERT(__rmutex->__depth < __INT32_MAX__); + __rmutex->__depth ++; return 0; } __MCF_ALWAYS_INLINE int -__MCF_gthr_rc_mutex_wait(__MCF_gthr_rc_mutex* __rmtx, const int64_t* __timeout_opt) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_wait(__MCF_gthr_rc_mutex* __rmutex, const int64_t* __timeout_opt) __MCF_NOEXCEPT { /* Attempt to take ownership. */ - int __err = _MCF_mutex_lock(__rmtx->__mutex, __timeout_opt); + int __err = _MCF_mutex_lock(__rmutex->__mutex, __timeout_opt); if(__err != 0) return __err; /* The calling thread owns the mutex now. */ - __MCF_ASSERT(__rmtx->__owner[0] == 0); - _MCF_atomic_store_32_rlx(__rmtx->__owner, (int32_t) _MCF_thread_self_tid()); - __MCF_ASSERT(__rmtx->__depth == 0); - __rmtx->__depth = 1; + __MCF_ASSERT(__rmutex->__owner[0] == 0); + _MCF_atomic_store_32_rlx(__rmutex->__owner, (int32_t) _MCF_thread_self_tid()); + __MCF_ASSERT(__rmutex->__depth == 0); + __rmutex->__depth = 1; return 0; } __MCF_ALWAYS_INLINE void -__MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT { /* Reduce a level of recursion. */ - __MCF_ASSERT(__rmtx->__depth > 0); - __rmtx->__depth --; - if(__rmtx->__depth != 0) + __MCF_ASSERT(__rmutex->__depth > 0); + __rmutex->__depth --; + if(__rmutex->__depth != 0) return; /* Give up ownership now. */ - _MCF_atomic_store_32_rlx(__rmtx->__owner, 0); - _MCF_mutex_unlock(__rmtx->__mutex); + _MCF_atomic_store_32_rlx(__rmutex->__owner, 0); + _MCF_mutex_unlock(__rmutex->__mutex); } __MCF_C_DECLARATIONS_END diff --git a/test/c11_cnd_consumers.c b/test/c11_cnd_consumers.c index a952c77c65..72a91d172d 100644 --- a/test/c11_cnd_consumers.c +++ b/test/c11_cnd_consumers.c @@ -29,8 +29,8 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx[0].__depth == 1); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__depth == 1); } /* Consume it */ @@ -82,8 +82,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx[0].__depth == 1); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__depth == 1); } /* Produce one */ @@ -97,8 +97,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mtx[0].__depth == 1); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__depth == 1); } /* Inform end of input */ diff --git a/test/c11_cnd_consumers_recursive.c b/test/c11_cnd_consumers_recursive.c index d044f56fcf..899ccb48ef 100644 --- a/test/c11_cnd_consumers_recursive.c +++ b/test/c11_cnd_consumers_recursive.c @@ -33,9 +33,9 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__mutex[0].__locked); - assert(mutex.__rc_mtx[0].__depth == 3); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__mutex[0].__locked); + assert(mutex.__rc_mutex[0].__depth == 3); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); } /* Consume it */ @@ -95,9 +95,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__mutex[0].__locked); - assert(mutex.__rc_mtx[0].__depth == 3); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__mutex[0].__locked); + assert(mutex.__rc_mutex[0].__depth == 3); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); } /* Produce one */ @@ -111,9 +111,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mtx[0].__mutex[0].__locked); - assert(mutex.__rc_mtx[0].__depth == 3); - assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mutex[0].__mutex[0].__locked); + assert(mutex.__rc_mutex[0].__depth == 3); + assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); } /* Inform end of input */ diff --git a/test/c11_mtx_nonrecursive.c b/test/c11_mtx_nonrecursive.c index 3265540e48..d0375a0beb 100644 --- a/test/c11_mtx_nonrecursive.c +++ b/test/c11_mtx_nonrecursive.c @@ -20,11 +20,11 @@ main(void) r = mtx_trylock(&mutex); assert(r == thrd_success); - mutex.__rc_mtx[0].__owner[0] = 42; /* don't expose the deadlock */ + mutex.__rc_mutex[0].__owner[0] = 42; /* don't expose the deadlock */ r = mtx_trylock(&mutex); assert(r == thrd_busy); - mutex.__rc_mtx[0].__owner[0] = _MCF_thread_self_tid(); + mutex.__rc_mutex[0].__owner[0] = _MCF_thread_self_tid(); r = mtx_unlock(&mutex); assert(r == thrd_success); diff --git a/test/c11_mtx_timeout.c b/test/c11_mtx_timeout.c index 2be1ae084b..8c20e97d56 100644 --- a/test/c11_mtx_timeout.c +++ b/test/c11_mtx_timeout.c @@ -35,7 +35,7 @@ main(void) now = _MCF_perf_counter(); timeout.tv_sec = time(NULL) + 1; timeout.tv_nsec = 100000000; - mutex.__rc_mtx[0].__owner[0] = 42; + mutex.__rc_mutex[0].__owner[0] = 42; r = mtx_timedlock(&mutex, &timeout); assert(r == thrd_timedout); delta = _MCF_perf_counter() - now; From 73f598bf261a429331ba25e51d824f6c906f3399 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 10 Nov 2022 11:02:05 +0800 Subject: [PATCH 098/133] c11: Tidy `thrd_sleep()` a little (cherry picked from commit c2a3d2f7481398a10f05cf0021b896cf3fc3dbf9) Signed-off-by: LIU Hao --- src/c11.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/c11.c b/src/c11.c index be47cb0755..6cda2d5942 100644 --- a/src/c11.c +++ b/src/c11.c @@ -37,18 +37,17 @@ __MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) int64_t timeout = (int64_t) value; int err = _MCF_sleep(&timeout); - if(err && rem_opt) { - /* Calculate the remaining time if the operation was interrupted. */ - value -= _MCF_hires_utc_now(); - value = __builtin_fmax(value, 0); - - value *= 0.001; - rem_opt->tv_sec = (time_t) value; - rem_opt->tv_nsec = (long) ((value - (double) rem_opt->tv_sec) * 1000000000); - } - else if(rem_opt) + if(rem_opt) { *rem_opt = (__MCF_timespec) __MCF_0_INIT; + if(err) { + /* Calculate the remaining time if the operation was interrupted. */ + double rem = __builtin_fmax(value - _MCF_hires_utc_now(), 0) * 0.001; + rem_opt->tv_sec = (time_t) rem; + rem_opt->tv_nsec = (long) ((rem - (double) rem_opt->tv_sec) * 1000000000); + } + } + /* Return 0 in case of timeouts, and -1 in case of interrupts. */ return err; } From 3295544618cdcb707715ebc36b36bf60e09858d0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 10 Nov 2022 11:08:47 +0800 Subject: [PATCH 099/133] c11: Rename a local variable (cherry picked from commit 99ebf110e6ca1d531055d636b636b4d92b3178ec) Signed-off-by: LIU Hao --- src/c11.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/c11.c b/src/c11.c index 6cda2d5942..dd6427e6d5 100644 --- a/src/c11.c +++ b/src/c11.c @@ -22,19 +22,19 @@ __MCF_DLLEXPORT int __MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) { - double value = 0.0009999; - value += (double) dur->tv_nsec * 0.000001; - value += (double) dur->tv_sec * 1000; + double end_time = 0.0009999; + end_time += (double) dur->tv_nsec * 0.000001; + end_time += (double) dur->tv_sec * 1000; /* The C11 standard says this should be measured by the system clock. * Don't look at me. It was not I who wrote the standard. */ - value += _MCF_hires_utc_now(); + end_time += _MCF_hires_utc_now(); /* Clamp the timestamp. */ - value = __builtin_fmax(value, 0); - value = __builtin_fmin(value, 0x1p63 - 0x1p10); + end_time = __builtin_fmax(end_time, 0); + end_time = __builtin_fmin(end_time, 0x1p63 - 0x1p10); - int64_t timeout = (int64_t) value; + int64_t timeout = (int64_t) end_time; int err = _MCF_sleep(&timeout); if(rem_opt) { @@ -42,7 +42,7 @@ __MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) if(err) { /* Calculate the remaining time if the operation was interrupted. */ - double rem = __builtin_fmax(value - _MCF_hires_utc_now(), 0) * 0.001; + double rem = __builtin_fmax(end_time - _MCF_hires_utc_now(), 0) * 0.001; rem_opt->tv_sec = (time_t) rem; rem_opt->tv_nsec = (long) ((rem - (double) rem_opt->tv_sec) * 1000000000); } From 04f57af2c2966f941819dd9cfe4afc1491e5f8c1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 11 Nov 2022 10:47:28 +0800 Subject: [PATCH 100/133] doc: Add '.editorconfig' (cherry picked from commit d8cced147dc18e0da80559514871550eda8e826f) Signed-off-by: LIU Hao --- .editorconfig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..e00fd9b0e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +charset = utf-8 +trim_trailing_whitespace = true + +[Makefile*] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false From 2420f335429f0ac7a38771352908d94640e2cea0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 16 Nov 2022 13:42:46 +0800 Subject: [PATCH 101/133] thread: Report `ERROR_ARITHMETIC_OVERFLOW` if the size is too large ... instead of `ERROR_NOT_ENOUGH_MEMORY`. (cherry picked from commit 0e11527c6848a4857c764548d75ab4f77673fc10) Signed-off-by: LIU Hao --- src/thread.c | 4 ++-- test/thread_overlarge.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/thread.c b/src/thread.c index 706c949a1b..6abb20dcd3 100644 --- a/src/thread.c +++ b/src/thread.c @@ -41,8 +41,8 @@ _MCF_thread_new(_MCF_thread_procedure* proc, const void* data_opt, size_t size) if(!proc) return __MCF_win32_error_p(ERROR_INVALID_PARAMETER, NULL); - if(size > PTRDIFF_MAX - 0x100000) /* max offsettable memory - 1 MiB */ - return __MCF_win32_error_p(ERROR_NOT_ENOUGH_MEMORY, NULL); + if(size >= 0x7FF00000U) + return __MCF_win32_error_p(ERROR_ARITHMETIC_OVERFLOW, NULL); /* Allocate and initialize the thread control structure. */ _MCF_thread* thrd = __MCF_malloc_0(sizeof(_MCF_thread) + size); diff --git a/test/thread_overlarge.c b/test/thread_overlarge.c index 74a8a12031..629eaa56e5 100644 --- a/test/thread_overlarge.c +++ b/test/thread_overlarge.c @@ -18,5 +18,5 @@ int main(void) { assert(_MCF_thread_new(thread_proc, NULL, PTRDIFF_MAX) == NULL); - assert(GetLastError() == ERROR_NOT_ENOUGH_MEMORY); + assert(GetLastError() == ERROR_ARITHMETIC_OVERFLOW); } From dabe4bdcbbe68bcfc989be6e4e20f4e5e43f7191 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 16 Nov 2022 17:26:15 +0800 Subject: [PATCH 102/133] thread: Fix alignment of user-defined data on 32-bit builds Signed-off-by: LIU Hao (cherry picked from commit 8869dbfe44e07e048d7dca8892b7190b0a77fd60) Signed-off-by: LIU Hao --- src/thread.c | 11 +++++++++-- src/thread.h | 9 ++++++--- test/Makefile.inc.am | 1 + test/thread_new_alignment.c | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 test/thread_new_alignment.c diff --git a/src/thread.c b/src/thread.c index 6abb20dcd3..b8151b75a0 100644 --- a/src/thread.c +++ b/src/thread.c @@ -45,16 +45,23 @@ _MCF_thread_new(_MCF_thread_procedure* proc, const void* data_opt, size_t size) return __MCF_win32_error_p(ERROR_ARITHMETIC_OVERFLOW, NULL); /* Allocate and initialize the thread control structure. */ - _MCF_thread* thrd = __MCF_malloc_0(sizeof(_MCF_thread) + size); + uint32_t align_fixup = 0; + if(__MCF_THREAD_DATA_ALIGNMENT > MEMORY_ALLOCATION_ALIGNMENT) + align_fixup = __MCF_THREAD_DATA_ALIGNMENT - MEMORY_ALLOCATION_ALIGNMENT; + + _MCF_thread* thrd = __MCF_malloc_0(sizeof(_MCF_thread) + size + align_fixup); if(!thrd) return __MCF_win32_error_p(ERROR_NOT_ENOUGH_MEMORY, NULL); _MCF_atomic_store_32_rlx(thrd->__nref, 2); thrd->__proc = proc; + thrd->__data_ptr = thrd->__data_storage; + if(align_fixup != 0) + thrd->__data_ptr = (char*) ((uintptr_t) (thrd->__data_ptr - 1) | (__MCF_THREAD_DATA_ALIGNMENT - 1)) + 1; if(data_opt) - __MCF_mcopy(thrd->__data_storage, data_opt, size); + __MCF_mcopy(thrd->__data_ptr, data_opt, size); /* Create the thread now. */ DWORD tid; diff --git a/src/thread.h b/src/thread.h index 4a01c85c76..175208b993 100644 --- a/src/thread.h +++ b/src/thread.h @@ -32,9 +32,12 @@ struct __MCF_thread /* `__data_ptr` shall always point to `__data_storage` below. The space * preceding it is reserved for future use. It is not safe to assume the * offset of `__data_storage` to be a constant. */ - __extension__ char __data_storage[0] __MCF_ALIGN(16); + __extension__ char __data_storage[0]; }; +/* This is the default alignment for user-defined data. */ +#define __MCF_THREAD_DATA_ALIGNMENT 16U + /* Creates a thread. The `__nref` member is initialized to 2, because a running * thread holds a reference to itself. * @@ -158,7 +161,7 @@ __MCF_THREAD_INLINE __MCF_CXX11(constexpr) __MCF_CXX(const) void* _MCF_thread_get_data(const _MCF_thread* __thrd) __MCF_NOEXCEPT { - return __builtin_assume_aligned(__thrd->__data_ptr, __alignof__(__thrd->__data_storage)); + return __builtin_assume_aligned(__thrd->__data_ptr, __MCF_THREAD_DATA_ALIGNMENT); } #ifdef __cplusplus @@ -167,7 +170,7 @@ inline __MCF_CXX11(constexpr) void* _MCF_thread_get_data(_MCF_thread* __thrd) __MCF_NOEXCEPT { - return __builtin_assume_aligned(__thrd->__data_ptr, __alignof__(__thrd->__data_storage)); + return __builtin_assume_aligned(__thrd->__data_ptr, __MCF_THREAD_DATA_ALIGNMENT); } #endif /* __cplusplus */ diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index 68f8246a4c..afe6455fae 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -33,6 +33,7 @@ check_PROGRAMS += \ %reldir%/tls_dtor_ignored_on_quick_exit.test \ %reldir%/tls_dtor_ignored_on__Exit.test \ %reldir%/thread_self_id.test \ + %reldir%/thread_new_alignment.test \ %reldir%/thread_overlarge.test \ %reldir%/thread_x87_precision.test \ %reldir%/gthr_c89_pedantic.test \ diff --git a/test/thread_new_alignment.c b/test/thread_new_alignment.c new file mode 100644 index 0000000000..a7d130c338 --- /dev/null +++ b/test/thread_new_alignment.c @@ -0,0 +1,35 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../src/thread.h" +#include +#include +#include + +static +void +thread_proc(_MCF_thread* self) + { + void* data = _MCF_thread_get_data(self); + assert((uintptr_t) data % __MCF_THREAD_DATA_ALIGNMENT == 0); + assert(RtlCompareMemory(data, "hello", 5) == 5); // all equal + + printf("thread %d quitting\n", self->__tid); + } + +int +main(void) + { + for(size_t i = 0; i < 1000; ++i) { + // leak this + void* ptr = HeapAlloc(GetProcessHeap(), 0, i); + (void) ptr; + + _MCF_thread* thrd = _MCF_thread_new(thread_proc, "hello", 5); + assert(thrd); + + _MCF_thread_wait(thrd, NULL); + _MCF_thread_drop_ref(thrd); + } + } From 0eaebd8a7a77919a998d5a645143c04bee838a27 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 16 Nov 2022 17:54:22 +0800 Subject: [PATCH 103/133] fwd: Remove `__MCF_ALIGN` --- src/fwd.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fwd.h b/src/fwd.h index 21f96f1dc2..b6b0e4ff0f 100644 --- a/src/fwd.h +++ b/src/fwd.h @@ -67,7 +67,6 @@ # #endif /* __cplusplus */ -#define __MCF_ALIGN(...) __attribute__((__aligned__(__VA_ARGS__))) #define __MCF_PTR_BITS (__SIZEOF_POINTER__ * __CHAR_BIT__) #define __MCF_0_INIT {__MCF_C(0)} #define __MCF_SX(...) #__VA_ARGS__ From 0f39a4d5195b211d0ddab75665281c1ce012b8df Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 16 Nov 2022 20:50:29 +0800 Subject: [PATCH 104/133] ci: Disable optimization (cherry picked from commit b2e24c8a8c5917ab5d58f8c7f55cfe8b76850f63) Signed-off-by: LIU Hao (cherry picked from commit fbb99571888c7c3e6de09db1b819409d9d86d19b) Signed-off-by: LIU Hao --- ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build.sh b/ci/build.sh index fc3b0ecbe8..1b9d22016d 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -2,7 +2,7 @@ # setup export CC=${CC:-"gcc"} -export CFLAGS='-O2 -g0' +export CFLAGS='-O0 -g0' # build ${CC} --version From d542f7ae83b53ef34c294f1c758a875845c2f956 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 16 Nov 2022 20:50:29 +0800 Subject: [PATCH 105/133] thread: Fix alignment of user data (cherry picked from commit 9a2461d0432ff589910a3680a11748bce49aa91b) Signed-off-by: LIU Hao (cherry picked from commit 6a792eb71fcf1550bfb498733da72c180c4a4235) Signed-off-by: LIU Hao --- src/thread.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/thread.h b/src/thread.h index 175208b993..1917d41cff 100644 --- a/src/thread.h +++ b/src/thread.h @@ -32,11 +32,9 @@ struct __MCF_thread /* `__data_ptr` shall always point to `__data_storage` below. The space * preceding it is reserved for future use. It is not safe to assume the * offset of `__data_storage` to be a constant. */ - __extension__ char __data_storage[0]; - }; - -/* This is the default alignment for user-defined data. */ #define __MCF_THREAD_DATA_ALIGNMENT 16U + __extension__ char __data_storage[0] __attribute__((__aligned__(__MCF_THREAD_DATA_ALIGNMENT))); + }; /* Creates a thread. The `__nref` member is initialized to 2, because a running * thread holds a reference to itself. From a1db3cfc834d45d2130bee333fa042ba926e6eb7 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 18 Nov 2022 17:33:30 +0800 Subject: [PATCH 106/133] test: Update 'tls_many.c' (cherry picked from commit 86c86bf07603cde89218ad7a32a15e674254ecd5) Signed-off-by: LIU Hao --- test/tls_many.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/tls_many.c b/test/tls_many.c index c5ea7fd464..aa95aa2164 100644 --- a/test/tls_many.c +++ b/test/tls_many.c @@ -9,22 +9,36 @@ int main(void) { #define NKEYS 1000U +#define NVALS 10000U _MCF_tls_key* keys[NKEYS]; + for(size_t k = 0; k != NKEYS; ++k) { keys[k] = _MCF_tls_key_new(NULL); assert(keys[k]); } -#define NVALS 10000U + for(size_t k = 0; k != NKEYS; ++k) { + void* p = _MCF_tls_get(keys[k]); + assert(p == NULL); + + for(size_t v = 0; v != NVALS; ++v) { + int r = _MCF_tls_set(keys[k], (void*) (v + k)); + assert(r == 0); + + p = _MCF_tls_get(keys[k]); + assert(p == (void*) (v + k)); + } + } + for(size_t v = 0; v != NVALS; ++v) { for(size_t k = 0; k != NKEYS; ++k) { - int r = _MCF_tls_set(keys[k], (void*) v); + int r = _MCF_tls_set(keys[k], (void*) (v + k)); assert(r == 0); } for(size_t k = 0; k != NKEYS; ++k) { - size_t p = (size_t) _MCF_tls_get(keys[k]); - assert(p == v); + void* p = _MCF_tls_get(keys[k]); + assert(p == (void*) (v + k)); } } } From f1dfbd7899cc0c6476bc0bf8d727ba85cf4d8f8d Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 21 Nov 2022 15:29:46 +0800 Subject: [PATCH 107/133] xglobals: Reformat two lines that have side effects (cherry picked from commit bf1a14d43aee611844d7908652756f5419a1cfc5) Signed-off-by: LIU Hao --- src/xglobals.i | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/xglobals.i b/src/xglobals.i index eefe92d396..be2ae8602f 100644 --- a/src/xglobals.i +++ b/src/xglobals.i @@ -392,7 +392,8 @@ void* __MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT { void* __ptr = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *__pptr, __size); - return !__ptr ? NULL : (*__pptr = __ptr); + return !__ptr ? NULL + : (*__pptr = __ptr); } __MCF_XGLOBALS_INLINE @@ -400,7 +401,8 @@ void* __MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT { void* __ptr = HeapAlloc(GetProcessHeap(), 0, __size); - return !__ptr ? NULL : __MCF_mcopy(__ptr, __data, __size); + return !__ptr ? NULL + : __MCF_mcopy(__ptr, __data, __size); } __MCF_XGLOBALS_INLINE From 6c2b58158e1af5ffbd5e3f4136afd16c31e29318 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 22 Nov 2022 10:24:30 +0800 Subject: [PATCH 108/133] c11,gthr,libcxx: Don't make the current thread non-joinable if it is passed to join functions The call will fail, so no state shall be updated. (cherry picked from commit e51a1724d303c816ad5fd200ba5b3c6863bf544d) Signed-off-by: LIU Hao --- src/c11.h | 13 ++++++------- src/gthr.h | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/c11.h b/src/c11.h index fb2704c0b5..fc17d13418 100644 --- a/src/c11.h +++ b/src/c11.h @@ -534,13 +534,12 @@ __MCF_c11_thrd_exit(int __result) __MCF_NOEXCEPT /* As there is no type information, we examine the thread procedure to * ensure we don't mistake a thread of a wrong type. */ __MCF_c11_thread_record* __rec = NULL; - _MCF_thread* __self = _MCF_thread_self(); - if(__self && (__self->__proc == __MCF_c11_thread_thunk_v2)) - __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__self); - if(__rec) + if(__self && (__self->__proc == __MCF_c11_thread_thunk_v2)) { + __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__self); __rec->__result = __result; + } /* Exit, even in the case of a foreign thread. Unlike `ExitThread()`, if * the last thread exits, the current process exits with zero. */ @@ -554,6 +553,9 @@ __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT __MCF_c11_thread_record* __rec; int __err; + if(__thrd == _MCF_thread_self()) + return thrd_error; + /* As there is no type information, we examine the thread procedure to * ensure we don't mistake a thread of a wrong type. */ if(__thrd->__proc != __MCF_c11_thread_thunk_v2) @@ -565,9 +567,6 @@ __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT return thrd_error; /* Wait for it. */ - if(__thrd == _MCF_thread_self()) - return thrd_error; - __err = _MCF_thread_wait(__thrd, NULL); __MCF_ASSERT(__err == 0); diff --git a/src/gthr.h b/src/gthr.h index 1b2d1550cb..542d9132e2 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -588,6 +588,9 @@ __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT __MCF_gthr_thread_record* __rec; int __err; + if(__thrd == _MCF_thread_self()) + return -2; + /* As there is no type information, we examine the thread procedure to * ensure we don't mistake a thread of a wrong type. */ if(__thrd->__proc != __MCF_gthr_thread_thunk_v2) @@ -596,12 +599,9 @@ __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT /* Fail if the thread has already been detached. */ __rec = (__MCF_gthr_thread_record*) _MCF_thread_get_data(__thrd); if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) - return -1; + return -3; /* Wait for it. */ - if(__thrd == _MCF_thread_self()) - return -2; - __err = _MCF_thread_wait(__thrd, NULL); __MCF_ASSERT(__err == 0); From b46ca41db2363686cfcae2df8fd252f6eb9bd6e7 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 22 Nov 2022 10:41:42 +0800 Subject: [PATCH 109/133] mutex: Replace CMPXCHG in spin loops with MOV + XCHG According to Intel docs, the CMPXCHG instruction is an unconditional read-write operation. Generally we should avoid the write, so perform a MOV before that. (cherry picked from commit 39d3901d6bb10d686023492c37fbdb7b2e1d23f3) Signed-off-by: LIU Hao --- src/mutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mutex.c b/src/mutex.c index a0285794ed..2772661957 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -75,6 +75,7 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) uint32_t my_mask = (uint32_t) old.__sp_mask ^ new.__sp_mask; if(my_mask != 0) { __MCF_ASSERT((my_mask & (my_mask - 1U)) == 0); + register BYTE* my_spin_byte = do_spin_byte_ptr(mutex, my_mask); /* Calculate the spin count for this loop. */ register int spin = (int) (__MCF_MUTEX_SP_NFAIL_THRESHOLD - old.__sp_nfail); @@ -86,8 +87,7 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) YieldProcessor(); /* Wait for my turn. */ - BYTE cmp = 1; - if(!_MCF_atomic_cmpxchg_weak_8_rlx(do_spin_byte_ptr(mutex, my_mask), &cmp, 0)) + if(!(_MCF_atomic_load_8_rlx(my_spin_byte) && _MCF_atomic_xchg_8_rlx(my_spin_byte, 0))) continue; /* If this mutex has not been locked, lock it and decrement the From ff0df85116776fd9bec8a3160b16347d5e48c8ab Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 22 Nov 2022 14:51:31 +0800 Subject: [PATCH 110/133] Revert "mutex: Replace CMPXCHG in spin loops with MOV + XCHG" This reverts commit b46ca41db2363686cfcae2df8fd252f6eb9bd6e7. --- src/mutex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mutex.c b/src/mutex.c index 2772661957..a0285794ed 100644 --- a/src/mutex.c +++ b/src/mutex.c @@ -75,7 +75,6 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) uint32_t my_mask = (uint32_t) old.__sp_mask ^ new.__sp_mask; if(my_mask != 0) { __MCF_ASSERT((my_mask & (my_mask - 1U)) == 0); - register BYTE* my_spin_byte = do_spin_byte_ptr(mutex, my_mask); /* Calculate the spin count for this loop. */ register int spin = (int) (__MCF_MUTEX_SP_NFAIL_THRESHOLD - old.__sp_nfail); @@ -87,7 +86,8 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) YieldProcessor(); /* Wait for my turn. */ - if(!(_MCF_atomic_load_8_rlx(my_spin_byte) && _MCF_atomic_xchg_8_rlx(my_spin_byte, 0))) + BYTE cmp = 1; + if(!_MCF_atomic_cmpxchg_weak_8_rlx(do_spin_byte_ptr(mutex, my_mask), &cmp, 0)) continue; /* If this mutex has not been locked, lock it and decrement the From 410d5514ed84a24888cad46dd5c7725cabf58fe0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 22 Nov 2022 15:01:57 +0800 Subject: [PATCH 111/133] c11: Reformat `__MCF_c11_thrd_exit()` (cherry picked from commit ac7e12796e47d28b7f2720bf040f98a2ec88400d) Signed-off-by: LIU Hao --- src/c11.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/c11.h b/src/c11.h index fc17d13418..94bf05cc4d 100644 --- a/src/c11.h +++ b/src/c11.h @@ -531,18 +531,22 @@ __MCF_C11_INLINE void __MCF_c11_thrd_exit(int __result) __MCF_NOEXCEPT { - /* As there is no type information, we examine the thread procedure to - * ensure we don't mistake a thread of a wrong type. */ - __MCF_c11_thread_record* __rec = NULL; + __MCF_c11_thread_record* __rec; _MCF_thread* __self = _MCF_thread_self(); - if(__self && (__self->__proc == __MCF_c11_thread_thunk_v2)) { - __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__self); - __rec->__result = __result; - } + if(!__self) + _MCF_thread_exit(); - /* Exit, even in the case of a foreign thread. Unlike `ExitThread()`, if - * the last thread exits, the current process exits with zero. */ + /* As there is no type information, we examine the thread procedure to + * ensure we don't mistake a thread of a wrong type. The current thread + * shall terminate even if it is foreign. Unlike `ExitThread()`, if the + * last thread exits, the current process exits with zero. */ + if(__self->__proc != __MCF_c11_thread_thunk_v2) + _MCF_thread_exit(); + + /* Set the exit status and exit. */ + __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__self); + __rec->__result = __result; _MCF_thread_exit(); } From 10d78b01c0f66661d3e74c5a75314ab36a5d86e1 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 22 Nov 2022 15:04:29 +0800 Subject: [PATCH 112/133] c11,gthr,libcxx: Reformat join and detach functions (cherry picked from commit 5641e1619c6be94bcdf64af688e59a9756ffd1c0) Signed-off-by: LIU Hao --- src/c11.h | 13 +++++++------ src/gthr.h | 7 ++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/c11.h b/src/c11.h index 94bf05cc4d..3cfd7d7132 100644 --- a/src/c11.h +++ b/src/c11.h @@ -510,8 +510,9 @@ __MCF_c11_thrd_detach(thrd_t __thrd) __MCF_NOEXCEPT if(__thrd->__proc != __MCF_c11_thread_thunk_v2) return thrd_error; - /* Fail if the thread has already been detached. */ __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__thrd); + + /* Fail if the thread has already been detached. */ if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return thrd_error; @@ -539,12 +540,12 @@ __MCF_c11_thrd_exit(int __result) __MCF_NOEXCEPT /* As there is no type information, we examine the thread procedure to * ensure we don't mistake a thread of a wrong type. The current thread - * shall terminate even if it is foreign. Unlike `ExitThread()`, if the - * last thread exits, the current process exits with zero. */ + * shall terminate even if it is foreign. */ if(__self->__proc != __MCF_c11_thread_thunk_v2) _MCF_thread_exit(); - /* Set the exit status and exit. */ + /* Set the exit status and exit. Unlike `ExitThread()`, if the last + * thread exits, the current process exits with zero. */ __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__self); __rec->__result = __result; _MCF_thread_exit(); @@ -565,12 +566,12 @@ __MCF_c11_thrd_join(thrd_t __thrd, int* __resp_opt) __MCF_NOEXCEPT if(__thrd->__proc != __MCF_c11_thread_thunk_v2) return thrd_error; - /* Fail if the thread has already been detached. */ __rec = (__MCF_c11_thread_record*) _MCF_thread_get_data(__thrd); + + /* Fail if the thread has already been detached. */ if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return thrd_error; - /* Wait for it. */ __err = _MCF_thread_wait(__thrd, NULL); __MCF_ASSERT(__err == 0); diff --git a/src/gthr.h b/src/gthr.h index 542d9132e2..770e596faa 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -596,12 +596,12 @@ __MCF_gthr_join_v2(__gthread_t __thrd, void** __resp_opt) __MCF_NOEXCEPT if(__thrd->__proc != __MCF_gthr_thread_thunk_v2) return -1; - /* Fail if the thread has already been detached. */ __rec = (__MCF_gthr_thread_record*) _MCF_thread_get_data(__thrd); + + /* Fail if the thread has already been detached. */ if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return -3; - /* Wait for it. */ __err = _MCF_thread_wait(__thrd, NULL); __MCF_ASSERT(__err == 0); @@ -624,8 +624,9 @@ __MCF_gthr_detach_v2(__gthread_t __thrd) __MCF_NOEXCEPT if(__thrd->__proc != __MCF_gthr_thread_thunk_v2) return -1; - /* Fail if the thread has already been detached. */ __rec = (__MCF_gthr_thread_record*) _MCF_thread_get_data(__thrd); + + /* Fail if the thread has already been detached. */ if(_MCF_atomic_xchg_8_rlx(__rec->__joinable, 0) == 0) return -1; From 4fb860fdb49634a9bfb7fbb3bbffffd71fd4d145 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 29 Nov 2022 00:12:22 +0800 Subject: [PATCH 113/133] *: Normalize naming: `mutex` => `mtx`, `cond` => `cnd` --- src/c11.h | 20 ++++++------- src/gthr.h | 48 +++++++++++++++--------------- src/gthr_aux.h | 40 ++++++++++++------------- test/c11_cnd_consumers.c | 12 ++++---- test/c11_cnd_consumers_recursive.c | 18 +++++------ test/c11_mtx_nonrecursive.c | 4 +-- test/c11_mtx_timeout.c | 2 +- 7 files changed, 72 insertions(+), 72 deletions(-) diff --git a/src/c11.h b/src/c11.h index 3cfd7d7132..881e1cf6d5 100644 --- a/src/c11.h +++ b/src/c11.h @@ -31,7 +31,7 @@ typedef int __MCF_c11_thread_procedure(void* __arg); struct __MCF_c11_mutex { uint8_t __type; /* bit mask of `__MCF_mtx_type` */ - __MCF_gthr_rc_mutex __rc_mutex[1]; + __MCF_gthr_rc_mutex __rc_mtx[1]; }; struct __MCF_c11_thread_record @@ -358,7 +358,7 @@ int __MCF_c11_cnd_timedwait(cnd_t* __cond, mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT { int64_t __timeout = __MCF_gthr_timeout_from_timespec(__ts); - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mutex, &__timeout); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -366,7 +366,7 @@ __MCF_C11_INLINE int __MCF_c11_cnd_wait(cnd_t* __cond, mtx_t* __mtx) __MCF_NOEXCEPT { - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mutex, NULL); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __mtx->__rc_mtx, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -393,7 +393,7 @@ __MCF_c11_mtx_init(mtx_t* __mtx, int __type) __MCF_NOEXCEPT case mtx_timed | mtx_recursive: /* Initialize an unowned mutex. */ __mtx->__type = (uint8_t) __type; - __MCF_gthr_rc_mutex_init(__mtx->__rc_mutex); + __MCF_gthr_rc_mutex_init(__mtx->__rc_mtx); return thrd_success; } } @@ -403,14 +403,14 @@ int __MCF_c11_mtx_check_recursion(mtx_t* __mtx) __MCF_NOEXCEPT { /* Check for recursion. */ - int __err = __MCF_gthr_rc_mutex_recurse(__mtx->__rc_mutex); + int __err = __MCF_gthr_rc_mutex_recurse(__mtx->__rc_mtx); if(__err != 0) return thrd_busy; /* If recursion has happened but the mutex is not recursive, undo the * operation, and fail. */ if(!(__mtx->__type & mtx_recursive)) { - __mtx->__rc_mutex[0].__depth --; + __mtx->__rc_mtx[0].__depth --; return thrd_error; } @@ -426,7 +426,7 @@ __MCF_c11_mtx_lock(mtx_t* __mtx) __MCF_NOEXCEPT if(__err != thrd_busy) return __err; - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, NULL); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, NULL); __MCF_ASSERT(__err == 0); return thrd_success; } @@ -446,7 +446,7 @@ __MCF_c11_mtx_timedlock(mtx_t* __mtx, const __MCF_timespec* __ts) __MCF_NOEXCEPT return __err; __timeout = __MCF_gthr_timeout_from_timespec(__ts); - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_timedout : thrd_success; } @@ -462,7 +462,7 @@ __MCF_c11_mtx_trylock(mtx_t* __mtx) __MCF_NOEXCEPT return __err; __timeout = 0; - __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mutex, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__mtx->__rc_mtx, &__timeout); return (__err != 0) ? thrd_busy : thrd_success; } @@ -470,7 +470,7 @@ __MCF_C11_INLINE int __MCF_c11_mtx_unlock(mtx_t* __mtx) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_release(__mtx->__rc_mutex); + __MCF_gthr_rc_mutex_release(__mtx->__rc_mtx); return 0; } diff --git a/src/gthr.h b/src/gthr.h index 770e596faa..80f1cc21bf 100644 --- a/src/gthr.h +++ b/src/gthr.h @@ -152,7 +152,7 @@ __MCF_ALIAS(__gthread_mutex_unlock, __MCF_gthr_mutex_unlock); /* Initializes a recursive mutex, like `pthread_mutex_init()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); @@ -161,7 +161,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_init, __MCF_gthr_recursive_mutex_init); /* Destroys a recursive mutex. This function does nothing. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destroy); @@ -170,7 +170,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_destroy, __MCF_gthr_recursive_mutex_destro /* Locks a recursive mutex, like `pthread_mutex_lock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); @@ -180,7 +180,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_lock, __MCF_gthr_recursive_mutex_lock); * `pthread_mutex_trylock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_trylock); @@ -190,7 +190,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_trylock, __MCF_gthr_recursive_mutex_tryloc * `pthread_mutex_timedlock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmutex, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_timedlock); @@ -199,7 +199,7 @@ __MCF_ALIAS(__gthread_recursive_mutex_timedlock, __MCF_gthr_recursive_mutex_time /* Unlocks a recursive mutex, like `pthread_mutex_unlock()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_recursive_mutex_unlock, __MCF_gthr_recursive_mutex_unlock); @@ -237,7 +237,7 @@ __MCF_ALIAS(__gthread_cond_wait, __MCF_gthr_cond_wait); /* Waits for a condition variable, like `pthread_cond_wait()`. */ __MCF_GTHR_INLINE int -__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT; +__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT; #ifndef __MCF_GTHR_NO_ALIASES __MCF_ALIAS(__gthread_cond_wait_recursive, __MCF_gthr_cond_wait_recursive); @@ -443,66 +443,66 @@ __MCF_gthr_mutex_unlock(__gthread_mutex_t* __mtx) __MCF_NOEXCEPT __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_init(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_init(__rmutex); + __MCF_gthr_rc_mutex_init(__rmtx); return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_destroy(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { - (void) __rmutex; + (void) __rmtx; return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_lock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { - int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); + int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); if(__err == 0) return 0; - __err = __MCF_gthr_rc_mutex_wait(__rmutex, NULL); + __err = __MCF_gthr_rc_mutex_wait(__rmtx, NULL); __MCF_ASSERT(__err == 0); return 0; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_trylock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { int64_t __timeout; - int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); + int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); if(__err == 0) return 0; __timeout = 0; - __err = __MCF_gthr_rc_mutex_wait(__rmutex, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); return __err; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmutex, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_timedlock(__gthread_recursive_mutex_t* __rmtx, const __gthread_time_t* __abs_time) __MCF_NOEXCEPT { int64_t __timeout; - int __err = __MCF_gthr_rc_mutex_recurse(__rmutex); + int __err = __MCF_gthr_rc_mutex_recurse(__rmtx); if(__err == 0) return 0; __timeout = __MCF_gthr_timeout_from_timespec(__abs_time); - __err = __MCF_gthr_rc_mutex_wait(__rmutex, &__timeout); + __err = __MCF_gthr_rc_mutex_wait(__rmtx, &__timeout); return __err; } __MCF_GTHR_INLINE int -__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_recursive_mutex_unlock(__gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { - __MCF_gthr_rc_mutex_release(__rmutex); + __MCF_gthr_rc_mutex_release(__rmtx); return 0; } @@ -533,9 +533,9 @@ __MCF_gthr_cond_wait(__gthread_cond_t* __cond, __gthread_mutex_t* __mtx) __MCF_N __MCF_GTHR_INLINE int -__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_cond_wait_recursive(__gthread_cond_t* __cond, __gthread_recursive_mutex_t* __rmtx) __MCF_NOEXCEPT { - int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __rmutex, NULL); + int __err = _MCF_cond_wait(__cond, __MCF_gthr_recursive_mutex_unlock_callback, __MCF_gthr_recursive_mutex_relock_callback, (intptr_t) __rmtx, NULL); __MCF_ASSERT(__err == 0); return 0; } diff --git a/src/gthr_aux.h b/src/gthr_aux.h index b2bffc7691..12b0c3daa6 100644 --- a/src/gthr_aux.h +++ b/src/gthr_aux.h @@ -93,57 +93,57 @@ __MCF_gthr_unonce(_MCF_once** __oncep) __MCF_NOEXCEPT __MCF_ALWAYS_INLINE void -__MCF_gthr_rc_mutex_init(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_init(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT { - __rmutex->__owner[0] = 0; - __rmutex->__depth = 0; - _MCF_mutex_init(__rmutex->__mutex); + __rmtx->__owner[0] = 0; + __rmtx->__depth = 0; + _MCF_mutex_init(__rmtx->__mutex); } __MCF_ALWAYS_INLINE int -__MCF_gthr_rc_mutex_recurse(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_recurse(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT { /* Check whether the mutex has already been owned. */ - if(_MCF_atomic_load_32_rlx(__rmutex->__owner) != (int32_t) _MCF_thread_self_tid()) + if(_MCF_atomic_load_32_rlx(__rmtx->__owner) != (int32_t) _MCF_thread_self_tid()) return -1; /* Increment the recursion count. */ - __MCF_ASSERT(__rmutex->__depth < __INT32_MAX__); - __rmutex->__depth ++; + __MCF_ASSERT(__rmtx->__depth < __INT32_MAX__); + __rmtx->__depth ++; return 0; } __MCF_ALWAYS_INLINE int -__MCF_gthr_rc_mutex_wait(__MCF_gthr_rc_mutex* __rmutex, const int64_t* __timeout_opt) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_wait(__MCF_gthr_rc_mutex* __rmtx, const int64_t* __timeout_opt) __MCF_NOEXCEPT { /* Attempt to take ownership. */ - int __err = _MCF_mutex_lock(__rmutex->__mutex, __timeout_opt); + int __err = _MCF_mutex_lock(__rmtx->__mutex, __timeout_opt); if(__err != 0) return __err; /* The calling thread owns the mutex now. */ - __MCF_ASSERT(__rmutex->__owner[0] == 0); - _MCF_atomic_store_32_rlx(__rmutex->__owner, (int32_t) _MCF_thread_self_tid()); - __MCF_ASSERT(__rmutex->__depth == 0); - __rmutex->__depth = 1; + __MCF_ASSERT(__rmtx->__owner[0] == 0); + _MCF_atomic_store_32_rlx(__rmtx->__owner, (int32_t) _MCF_thread_self_tid()); + __MCF_ASSERT(__rmtx->__depth == 0); + __rmtx->__depth = 1; return 0; } __MCF_ALWAYS_INLINE void -__MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmutex) __MCF_NOEXCEPT +__MCF_gthr_rc_mutex_release(__MCF_gthr_rc_mutex* __rmtx) __MCF_NOEXCEPT { /* Reduce a level of recursion. */ - __MCF_ASSERT(__rmutex->__depth > 0); - __rmutex->__depth --; - if(__rmutex->__depth != 0) + __MCF_ASSERT(__rmtx->__depth > 0); + __rmtx->__depth --; + if(__rmtx->__depth != 0) return; /* Give up ownership now. */ - _MCF_atomic_store_32_rlx(__rmutex->__owner, 0); - _MCF_mutex_unlock(__rmutex->__mutex); + _MCF_atomic_store_32_rlx(__rmtx->__owner, 0); + _MCF_mutex_unlock(__rmtx->__mutex); } __MCF_C_DECLARATIONS_END diff --git a/test/c11_cnd_consumers.c b/test/c11_cnd_consumers.c index 72a91d172d..a952c77c65 100644 --- a/test/c11_cnd_consumers.c +++ b/test/c11_cnd_consumers.c @@ -29,8 +29,8 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mutex[0].__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Consume it */ @@ -82,8 +82,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mutex[0].__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Produce one */ @@ -97,8 +97,8 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); - assert(mutex.__rc_mutex[0].__depth == 1); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__depth == 1); } /* Inform end of input */ diff --git a/test/c11_cnd_consumers_recursive.c b/test/c11_cnd_consumers_recursive.c index 899ccb48ef..d044f56fcf 100644 --- a/test/c11_cnd_consumers_recursive.c +++ b/test/c11_cnd_consumers_recursive.c @@ -33,9 +33,9 @@ thread_proc(void* param) while(value == 0) { err = cnd_wait(&cond_produced, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__mutex[0].__locked); - assert(mutex.__rc_mutex[0].__depth == 3); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Consume it */ @@ -95,9 +95,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__mutex[0].__locked); - assert(mutex.__rc_mutex[0].__depth == 3); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Produce one */ @@ -111,9 +111,9 @@ main(void) while(value != 0) { err = cnd_wait(&cond_consumed, &mutex); assert(err == thrd_success); - assert(mutex.__rc_mutex[0].__mutex[0].__locked); - assert(mutex.__rc_mutex[0].__depth == 3); - assert(mutex.__rc_mutex[0].__owner[0] == _MCF_thread_self_tid()); + assert(mutex.__rc_mtx[0].__mutex[0].__locked); + assert(mutex.__rc_mtx[0].__depth == 3); + assert(mutex.__rc_mtx[0].__owner[0] == _MCF_thread_self_tid()); } /* Inform end of input */ diff --git a/test/c11_mtx_nonrecursive.c b/test/c11_mtx_nonrecursive.c index d0375a0beb..3265540e48 100644 --- a/test/c11_mtx_nonrecursive.c +++ b/test/c11_mtx_nonrecursive.c @@ -20,11 +20,11 @@ main(void) r = mtx_trylock(&mutex); assert(r == thrd_success); - mutex.__rc_mutex[0].__owner[0] = 42; /* don't expose the deadlock */ + mutex.__rc_mtx[0].__owner[0] = 42; /* don't expose the deadlock */ r = mtx_trylock(&mutex); assert(r == thrd_busy); - mutex.__rc_mutex[0].__owner[0] = _MCF_thread_self_tid(); + mutex.__rc_mtx[0].__owner[0] = _MCF_thread_self_tid(); r = mtx_unlock(&mutex); assert(r == thrd_success); diff --git a/test/c11_mtx_timeout.c b/test/c11_mtx_timeout.c index 8c20e97d56..2be1ae084b 100644 --- a/test/c11_mtx_timeout.c +++ b/test/c11_mtx_timeout.c @@ -35,7 +35,7 @@ main(void) now = _MCF_perf_counter(); timeout.tv_sec = time(NULL) + 1; timeout.tv_nsec = 100000000; - mutex.__rc_mutex[0].__owner[0] = 42; + mutex.__rc_mtx[0].__owner[0] = 42; r = mtx_timedlock(&mutex, &timeout); assert(r == thrd_timedout); delta = _MCF_perf_counter() - now; From 0baa9cb804d6798f2863a4bc09fa2e3ffa0f6051 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 29 Nov 2022 15:43:26 +0800 Subject: [PATCH 114/133] event: Make `_MCF_event_await_change()` return the current value if it does not time out (cherry picked from commit 87dbe09a3df661f2fc8803a7274f916ffe935d6c) Signed-off-by: LIU Hao --- src/event.c | 2 +- src/event.h | 10 +++++----- test/event_timeout.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/event.c b/src/event.c index 3510be97a8..a159fa85e1 100644 --- a/src/event.c +++ b/src/event.c @@ -24,7 +24,7 @@ _MCF_event_await_change_slow(_MCF_event* event, int undesired, const int64_t* ti _MCF_atomic_load_pptr_acq(&old, event); do { if(old.__value != (uint8_t) undesired) - return 0; + return old.__value; new = old; new.__nsleep = (old.__nsleep + 1U) & __MCF_EVENT_NSLEEP_M; diff --git a/src/event.h b/src/event.h index 9b04b030c2..83d308f245 100644 --- a/src/event.h +++ b/src/event.h @@ -50,7 +50,7 @@ __MCF_EVENT_INLINE uint8_t _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT; -/* Wait for an event until it does NOT contain an undesired value. +/* Waits for an event until it does NOT contain an undesired value. * * If the `__timeout_opt` argument points to a positive integer, it denotes the * expiration time in number of milliseconds since 1970-01-01T00:00:00Z. If it @@ -59,11 +59,11 @@ _MCF_event_get(const _MCF_event* __event) __MCF_NOEXCEPT; * without waiting. If it is null, the function waits indefinitely. * * If this event contains the undesired value, this function blocks until - * some other value has been stored. Otherwise, this function returns 0 + * some other value has been stored. Otherwise, this function returns its value * immediately. * - * Returns 0 if the value does not equal the lowest byte of `__undesired`, or - * -1 if the operation has timed out, or -2 in case of invalid arguments. */ + * Returns a desired value which never equals the lowest byte of `__undesired`, + * or -1 if the operation has timed out, or -2 in case of invalid arguments. */ __MCF_EVENT_IMPORT int _MCF_event_await_change_slow(_MCF_event* __event, int __undesired, const int64_t* __timeout_opt) __MCF_NOEXCEPT; @@ -124,7 +124,7 @@ _MCF_event_await_change(_MCF_event* __event, int __undesired, const int64_t* __t /* Check whether the event does not contain the undesired value. If so, * don't block at all. */ if(__old.__value != (uint8_t) __undesired) - return 0; + return __old.__value; if(__timeout_opt && (*__timeout_opt == 0)) return -1; diff --git a/test/event_timeout.c b/test/event_timeout.c index 3faaf127fd..eee5fea1a6 100644 --- a/test/event_timeout.c +++ b/test/event_timeout.c @@ -23,14 +23,14 @@ main(void) now = _MCF_perf_counter(); r = _MCF_event_await_change(&event, 52, (const int64_t[]){ _MCF_utc_now() + 1100 }); /* absolute */ - assert(r == 0); + assert(r == 42); delta = _MCF_perf_counter() - now; printf("delta = %.6f\n", delta); assert(delta <= 100); now = _MCF_perf_counter(); r = _MCF_event_await_change(&event, __MCF_EVENT_VALUE_MAX, (const int64_t[]){ _MCF_utc_now() + 1100 }); /* absolute */ - assert(r == 0); + assert(r == 42); delta = _MCF_perf_counter() - now; printf("delta = %.6f\n", delta); assert(delta <= 100); From 3997fc465382288b427272c8512cbc61d8f1a2b0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 30 Nov 2022 10:45:26 +0800 Subject: [PATCH 115/133] c11,gthr: Ensure timeouts are rounded up (cherry picked from commit 23d36034973d0f048f885c2e83799d050eb27b0b) Signed-off-by: LIU Hao --- src/c11.c | 2 +- src/gthr_aux.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c11.c b/src/c11.c index dd6427e6d5..07e85ffc50 100644 --- a/src/c11.c +++ b/src/c11.c @@ -22,7 +22,7 @@ __MCF_DLLEXPORT int __MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) { - double end_time = 0.0009999; + double end_time = 0.9999999; end_time += (double) dur->tv_nsec * 0.000001; end_time += (double) dur->tv_sec * 1000; diff --git a/src/gthr_aux.c b/src/gthr_aux.c index bdb8b4a3ef..15c3c8ca44 100644 --- a/src/gthr_aux.c +++ b/src/gthr_aux.c @@ -11,7 +11,7 @@ __MCF_DLLEXPORT int64_t __MCF_gthr_timeout_from_timespec(const __MCF_timespec* abs_time) { - double value = 0.0009999; + double value = 0.9999999; value += (double) abs_time->tv_nsec * 0.000001; value += (double) abs_time->tv_sec * 1000; From 78815d34a9db89e930b3ef3aae550ca2cc33d771 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 1 Dec 2022 22:39:02 +0800 Subject: [PATCH 116/133] build: Fix invocation of `AC_CONFIG_FILES` (cherry picked from commit 55e9c067de5da0c30cb2634594734d5c319912ab) Signed-off-by: LIU Hao --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 2fdfceebf4..6dff2f9476 100644 --- a/configure.ac +++ b/configure.ac @@ -33,5 +33,5 @@ AC_SUBST([abi_major]) AC_SUBST([abi_minor]) AC_SUBST([abi_suffix]) -AC_CONFIG_FILES([Makefile] [src/version.h]) +AC_CONFIG_FILES([Makefile src/version.h]) AC_OUTPUT From f3f30f5f723dc38cc98cb059f9a46b2eadb8dd34 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 4 Dec 2022 00:06:34 +0800 Subject: [PATCH 117/133] ci: Update build.sh (cherry picked from commit b65a3156c867f1a88af0399c92c1b57faae7c8a7) Signed-off-by: LIU Hao --- ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/build.sh b/ci/build.sh index 1b9d22016d..d2b39b175a 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -16,6 +16,6 @@ trap 'rm -rf ~+ || true' EXIT # test if ! make -j$(nproc) distcheck DISTCHECK_CONFIGURE_FLAGS=${CONFIGURE_OPTS} then - cat ./test-suite.log + find . -name 'test-suite.log' -exec cat '{}' ';' exit 1 fi From 83b05ec6029b4c292fa965a4047d9942023688f2 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 4 Dec 2022 00:48:23 +0800 Subject: [PATCH 118/133] ci/appveyor: Remove pre-installed dependencies (cherry picked from commit 0be7cee73cd0b662bd57d50c087ade4c6fe6ec60) Signed-off-by: LIU Hao --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index ac24260e91..d5f168bdfc 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -17,7 +17,7 @@ environment: CONFIGURE_OPTS: --disable-shared install: - - cmd: pacman -S --noconfirm autoconf automake libtool make mingw-w64-{x86_64,i686}-gcc + - cmd: pacman -S --noconfirm autoconf automake libtool build: parallel: true From 3eeeed4ee7694cdcdaa2c5410a16257f968a553f Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sun, 11 Dec 2022 23:20:56 +0800 Subject: [PATCH 119/133] build: Move `src` to `mcfgthread` and use `nobase_include_HEADERS` Signed-off-by: LIU Hao (cherry picked from commit 2d585f80dbf71cfba2ffe7a4219dc82f1fa9336b) Signed-off-by: LIU Hao (cherry picked from commit 355afa8b3990d1eb67b1a284ffa35cdcbc47dbbb) Signed-off-by: LIU Hao --- .gitignore | 4 ++-- Makefile.am | 8 ++++---- ci/check_includes.sh | 11 ++++++----- configure.ac | 4 ++-- {src => mcfgthread}/Makefile.inc.am | 19 +++++++++++-------- {src => mcfgthread}/atomic.h | 0 {src => mcfgthread}/c11.c | 0 {src => mcfgthread}/c11.h | 0 {src => mcfgthread}/clock.c | 0 {src => mcfgthread}/clock.h | 0 {src => mcfgthread}/cond.c | 0 {src => mcfgthread}/cond.h | 0 {src => mcfgthread}/cxa.c | 0 {src => mcfgthread}/cxa.h | 0 {src => mcfgthread}/dtor_queue.c | 0 {src => mcfgthread}/dtor_queue.h | 0 {src => mcfgthread}/event.c | 0 {src => mcfgthread}/event.h | 0 {src => mcfgthread}/exit.c | 0 {src => mcfgthread}/exit.h | 0 {src => mcfgthread}/fwd.c | 0 {src => mcfgthread}/fwd.h | 0 {src => mcfgthread}/gthr.c | 0 {src => mcfgthread}/gthr.h | 0 {src => mcfgthread}/gthr_aux.c | 0 {src => mcfgthread}/gthr_aux.h | 0 {src => mcfgthread}/memcmp.c | 0 {src => mcfgthread}/memcpy.c | 0 {src => mcfgthread}/memmove.c | 0 {src => mcfgthread}/memset.c | 0 {src => mcfgthread}/mutex.c | 0 {src => mcfgthread}/mutex.h | 0 {src => mcfgthread}/once.c | 0 {src => mcfgthread}/once.h | 0 {src => mcfgthread}/precompiled.i | 0 {src => mcfgthread}/sem.c | 0 {src => mcfgthread}/sem.h | 0 {src => mcfgthread}/thread.c | 0 {src => mcfgthread}/thread.h | 0 {src => mcfgthread}/tls.c | 0 {src => mcfgthread}/tls.h | 0 {src => mcfgthread}/version.h.in | 0 {src => mcfgthread}/version.rc | 0 {src => mcfgthread}/xglobals.c | 0 {src => mcfgthread}/xglobals.i | 0 test/at_quick_exit_ignored_on__Exit.c | 4 ++-- test/at_quick_exit_ignored_on_exit.c | 4 ++-- test/at_quick_exit_order.c | 4 ++-- test/atexit_ignored_on__Exit.c | 4 ++-- test/atexit_ignored_on_quick_exit.c | 4 ++-- test/atexit_order.c | 4 ++-- test/atexit_thread_self.c | 4 ++-- test/c11_c89_pedantic.c | 2 +- test/c11_call_once.c | 4 ++-- test/c11_cnd_consumers.c | 2 +- test/c11_cnd_consumers_recursive.c | 2 +- test/c11_cnd_timeout.c | 4 ++-- test/c11_inline_alias.c | 2 +- test/c11_mtx.c | 4 ++-- test/c11_mtx_nonrecursive.c | 4 ++-- test/c11_mtx_recursive.c | 4 ++-- test/c11_mtx_recursive_timeout.c | 4 ++-- test/c11_mtx_recursive_trylock.c | 4 ++-- test/c11_mtx_timeout.c | 4 ++-- test/c11_mtx_timeout_unsupported.c | 4 ++-- test/c11_mtx_trylock.c | 4 ++-- test/c11_thrd_equal.c | 2 +- test/c11_thrd_return.c | 2 +- test/c11_thrd_sleep.c | 4 ++-- test/c11_tss_deleted_key.c | 4 ++-- test/c11_tss_dtor.c | 4 ++-- test/c11_tss_many.c | 2 +- test/c11_tss_set.c | 2 +- test/clock.c | 2 +- test/cond_timeout.c | 4 ++-- test/cxa_atexit_all.c | 2 +- test/cxa_atexit_dso.c | 2 +- test/cxa_thread_atexit.c | 4 ++-- test/cxa_thread_atexit_exit.c | 4 ++-- test/dtor_queue_all.c | 2 +- test/dtor_queue_dso.c | 2 +- test/dtor_queue_remove.c | 2 +- test/event_init.c | 4 ++-- test/event_timeout.c | 4 ++-- test/event_value.c | 4 ++-- test/gthr_c89_pedantic.c | 2 +- test/gthr_cond_consumers.c | 2 +- test/gthr_cond_consumers_recursive.c | 2 +- test/gthr_cond_timeout.c | 4 ++-- test/gthr_equal.c | 2 +- test/gthr_inline_alias.c | 2 +- test/gthr_mutex.c | 4 ++-- test/gthr_mutex_nonrecursive.c | 4 ++-- test/gthr_mutex_timeout.c | 4 ++-- test/gthr_mutex_trylock.c | 4 ++-- test/gthr_once.c | 4 ++-- test/gthr_rc_mutex.c | 4 ++-- test/gthr_rc_mutex_timeout.c | 4 ++-- test/gthr_rc_mutex_trylock.c | 4 ++-- test/gthr_thread_return.c | 2 +- test/gthr_tls_deleted_key.c | 4 ++-- test/gthr_tls_dtor.c | 4 ++-- test/gthr_tls_many.c | 2 +- test/gthr_tls_set.c | 2 +- test/memory.c | 2 +- test/mutex.c | 6 +++--- test/mutex_spin_fail.c | 2 +- test/mutex_spin_mask.c | 2 +- test/mutex_timeout.c | 4 ++-- test/mutex_zero_timeout.c | 6 +++--- test/once_abort.c | 4 ++-- test/once_release.c | 4 ++-- test/once_timeout.c | 4 ++-- test/once_zero_timeout.c | 4 ++-- test/sem_init.c | 4 ++-- test/sem_timeout.c | 4 ++-- test/sem_value.c | 4 ++-- test/thread_new_alignment.c | 2 +- test/thread_overlarge.c | 2 +- test/thread_self_id.c | 2 +- test/thread_x87_precision.c | 2 +- test/tls_deleted_key.c | 4 ++-- test/tls_dtor.c | 4 ++-- test/tls_dtor_ignored_on__Exit.c | 4 ++-- test/tls_dtor_ignored_on_exit.c | 4 ++-- test/tls_dtor_ignored_on_quick_exit.c | 4 ++-- test/tls_dtor_thread_exit.c | 4 ++-- test/tls_many.c | 2 +- test/tls_set.c | 2 +- 129 files changed, 164 insertions(+), 160 deletions(-) rename {src => mcfgthread}/Makefile.inc.am (85%) rename {src => mcfgthread}/atomic.h (100%) rename {src => mcfgthread}/c11.c (100%) rename {src => mcfgthread}/c11.h (100%) rename {src => mcfgthread}/clock.c (100%) rename {src => mcfgthread}/clock.h (100%) rename {src => mcfgthread}/cond.c (100%) rename {src => mcfgthread}/cond.h (100%) rename {src => mcfgthread}/cxa.c (100%) rename {src => mcfgthread}/cxa.h (100%) rename {src => mcfgthread}/dtor_queue.c (100%) rename {src => mcfgthread}/dtor_queue.h (100%) rename {src => mcfgthread}/event.c (100%) rename {src => mcfgthread}/event.h (100%) rename {src => mcfgthread}/exit.c (100%) rename {src => mcfgthread}/exit.h (100%) rename {src => mcfgthread}/fwd.c (100%) rename {src => mcfgthread}/fwd.h (100%) rename {src => mcfgthread}/gthr.c (100%) rename {src => mcfgthread}/gthr.h (100%) rename {src => mcfgthread}/gthr_aux.c (100%) rename {src => mcfgthread}/gthr_aux.h (100%) rename {src => mcfgthread}/memcmp.c (100%) rename {src => mcfgthread}/memcpy.c (100%) rename {src => mcfgthread}/memmove.c (100%) rename {src => mcfgthread}/memset.c (100%) rename {src => mcfgthread}/mutex.c (100%) rename {src => mcfgthread}/mutex.h (100%) rename {src => mcfgthread}/once.c (100%) rename {src => mcfgthread}/once.h (100%) rename {src => mcfgthread}/precompiled.i (100%) rename {src => mcfgthread}/sem.c (100%) rename {src => mcfgthread}/sem.h (100%) rename {src => mcfgthread}/thread.c (100%) rename {src => mcfgthread}/thread.h (100%) rename {src => mcfgthread}/tls.c (100%) rename {src => mcfgthread}/tls.h (100%) rename {src => mcfgthread}/version.h.in (100%) rename {src => mcfgthread}/version.rc (100%) rename {src => mcfgthread}/xglobals.c (100%) rename {src => mcfgthread}/xglobals.i (100%) diff --git a/.gitignore b/.gitignore index 87f70c0b24..93b9cbce7d 100644 --- a/.gitignore +++ b/.gitignore @@ -24,8 +24,8 @@ /config.status /libtool /stamp-h1 -/src/version.h -/src/precompiled.x* +/mcfgthread/version.h +/mcfgthread/precompiled.x* /lib/ /bin/ diff --git a/Makefile.am b/Makefile.am index 380ac6bb20..892eab122e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 END = ## Compiler options -AM_CPPFLAGS = -pipe -Wall -Wextra -Isrc \ +AM_CPPFLAGS = -pipe -Wall -Wextra -Imcfgthread \ -U_FORTIFY_SOURCE -D_WIN32_WINNT=0x0601 -D_POSIX_C_SOURCE=200809 \ -f{strict-{aliasing,overflow},merge-all-constants,fast-math} \ -fno-{stack-protector,align-{functions,jumps,loops},ident} \ @@ -17,7 +17,7 @@ AM_CFLAGS = -std=c99 \ -Werror={strict-prototypes,int-conversion} \ -Werror=implicit-{function-declaration,int} -AM_RCFLAGS = -Isrc -c65001 +AM_RCFLAGS = -Imcfgthread -c65001 AM_DEFAULT_SOURCE_EXT = .c SUFFIXES = .rc .def @@ -27,7 +27,7 @@ LDADD = lib/libmcfgthread.la noinst_LIBRARIES = noinst_LTLIBRARIES = -include_HEADERS = +nobase_include_HEADERS = lib_LIBRARIES = lib_LTLIBRARIES = bin_PROGRAMS = @@ -43,7 +43,7 @@ EXTRA_DIST = TESTS = ${check_PROGRAMS} ## Programs and libraries -include src/Makefile.inc.am +include mcfgthread/Makefile.inc.am ## Tests include test/Makefile.inc.am diff --git a/ci/check_includes.sh b/ci/check_includes.sh index 30c0eb1fe5..186d3d9831 100755 --- a/ci/check_includes.sh +++ b/ci/check_includes.sh @@ -4,31 +4,32 @@ export CC=${CC:-"gcc"} export CPPFLAGS="-D_WIN32_WINNT=0x0601 -Wall -Wextra "${CPPFLAGS} -for _file in $(find -L "src" -name "*.h") +for _file in $(find -L "mcfgthread" -name "*.h") do echo "Checking header as C89: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c-header -std=c89 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "src" -name "*.h") +for _file in $(find -L "mcfgthread" -name "*.h") do echo "Checking header as C++98: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++98 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "src" -name "*.h") +for _file in $(find -L "mcfgthread" -name "*.h") +>>>>>>> 2d585f8 (build: Move `src` to `mcfgthread` and use `nobase_include_HEADERS`) do echo "Checking header as C++11: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++11 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "src" -name "*.h") +for _file in $(find -L "mcfgthread" -name "*.h") do echo "Checking header as C++14: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++14 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "src" -name "*.c") +for _file in $(find -L "mcfgthread" -name "*.c") do echo "Checking source as C99: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c -std=c99 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} diff --git a/configure.ac b/configure.ac index 6dff2f9476..7c47feae67 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ ## AC_INIT(package, version, [bug-report], [tarname], [url]) AC_INIT([mcfgthread], [master], [lh_mouse@126.com], [mcfgthread], [https://github.com/lhmouse/mcfgthread]) AC_LANG([C]) -AC_CONFIG_SRCDIR([src/gthr.c]) +AC_CONFIG_SRCDIR([mcfgthread/gthr.c]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) @@ -33,5 +33,5 @@ AC_SUBST([abi_major]) AC_SUBST([abi_minor]) AC_SUBST([abi_suffix]) -AC_CONFIG_FILES([Makefile src/version.h]) +AC_CONFIG_FILES([Makefile mcfgthread/version.h]) AC_OUTPUT diff --git a/src/Makefile.inc.am b/mcfgthread/Makefile.inc.am similarity index 85% rename from src/Makefile.inc.am rename to mcfgthread/Makefile.inc.am index 94a7b03b70..af4d8c0c8f 100644 --- a/src/Makefile.inc.am +++ b/mcfgthread/Makefile.inc.am @@ -1,5 +1,6 @@ -include_mcfgthreaddir = ${includedir}/mcfgthread -include_mcfgthread_HEADERS = \ +lib_LTLIBRARIES += lib/libmcfgthread.la + +nobase_include_HEADERS += \ %reldir%/version.h \ %reldir%/atomic.h \ %reldir%/fwd.h \ @@ -19,7 +20,6 @@ include_mcfgthread_HEADERS = \ %reldir%/c11.h \ ${END} -lib_LTLIBRARIES += lib/libmcfgthread.la lib_libmcfgthread_la_SOURCES = \ %reldir%/version.h.in \ %reldir%/precompiled.i \ @@ -47,9 +47,6 @@ lib_libmcfgthread_la_SOURCES = \ %reldir%/c11.c \ ${END} -.rc.lo: - ${AM_V_GEN}${LIBTOOL} ${AM_V_lt} --tag=RC --mode=compile ${RC} ${DEFAULT_INCLUDES} ${AM_RCFLAGS} ${RCFLAGS} $< -o $@ - lib_libmcfgthread_la_CFLAGS = \ ${AM_CFLAGS} -nostdlib -f{freestanding,asynchronous-unwind-tables} @@ -71,10 +68,16 @@ endif && rm -rf $@.gch \ && mkdir $@.gch \ && . $@.lo \ - && (test "$${pic_object}" == none || mv -f %reldir%/$${pic_object} $@.gch/pic) \ - && (test "$${non_pic_object}" == none || mv -f %reldir%/$${non_pic_object} $@.gch/non_pic) \ + && (test "$${pic_object}" == none || \ + mv -f %reldir%/$${pic_object} $@.gch/pic) \ + && (test "$${non_pic_object}" == none || \ + mv -f %reldir%/$${non_pic_object} $@.gch/non_pic) \ && rm -f $@.lo \ && echo '#error PCH unusable' > $@ clean-local: -rm -rf %reldir%/precompiled.x* + +.rc.lo: + ${AM_V_GEN}${LIBTOOL} ${AM_V_lt} --tag=RC --mode=compile ${RC} \ + ${DEFAULT_INCLUDES} ${AM_RCFLAGS} ${RCFLAGS} $< -o $@ diff --git a/src/atomic.h b/mcfgthread/atomic.h similarity index 100% rename from src/atomic.h rename to mcfgthread/atomic.h diff --git a/src/c11.c b/mcfgthread/c11.c similarity index 100% rename from src/c11.c rename to mcfgthread/c11.c diff --git a/src/c11.h b/mcfgthread/c11.h similarity index 100% rename from src/c11.h rename to mcfgthread/c11.h diff --git a/src/clock.c b/mcfgthread/clock.c similarity index 100% rename from src/clock.c rename to mcfgthread/clock.c diff --git a/src/clock.h b/mcfgthread/clock.h similarity index 100% rename from src/clock.h rename to mcfgthread/clock.h diff --git a/src/cond.c b/mcfgthread/cond.c similarity index 100% rename from src/cond.c rename to mcfgthread/cond.c diff --git a/src/cond.h b/mcfgthread/cond.h similarity index 100% rename from src/cond.h rename to mcfgthread/cond.h diff --git a/src/cxa.c b/mcfgthread/cxa.c similarity index 100% rename from src/cxa.c rename to mcfgthread/cxa.c diff --git a/src/cxa.h b/mcfgthread/cxa.h similarity index 100% rename from src/cxa.h rename to mcfgthread/cxa.h diff --git a/src/dtor_queue.c b/mcfgthread/dtor_queue.c similarity index 100% rename from src/dtor_queue.c rename to mcfgthread/dtor_queue.c diff --git a/src/dtor_queue.h b/mcfgthread/dtor_queue.h similarity index 100% rename from src/dtor_queue.h rename to mcfgthread/dtor_queue.h diff --git a/src/event.c b/mcfgthread/event.c similarity index 100% rename from src/event.c rename to mcfgthread/event.c diff --git a/src/event.h b/mcfgthread/event.h similarity index 100% rename from src/event.h rename to mcfgthread/event.h diff --git a/src/exit.c b/mcfgthread/exit.c similarity index 100% rename from src/exit.c rename to mcfgthread/exit.c diff --git a/src/exit.h b/mcfgthread/exit.h similarity index 100% rename from src/exit.h rename to mcfgthread/exit.h diff --git a/src/fwd.c b/mcfgthread/fwd.c similarity index 100% rename from src/fwd.c rename to mcfgthread/fwd.c diff --git a/src/fwd.h b/mcfgthread/fwd.h similarity index 100% rename from src/fwd.h rename to mcfgthread/fwd.h diff --git a/src/gthr.c b/mcfgthread/gthr.c similarity index 100% rename from src/gthr.c rename to mcfgthread/gthr.c diff --git a/src/gthr.h b/mcfgthread/gthr.h similarity index 100% rename from src/gthr.h rename to mcfgthread/gthr.h diff --git a/src/gthr_aux.c b/mcfgthread/gthr_aux.c similarity index 100% rename from src/gthr_aux.c rename to mcfgthread/gthr_aux.c diff --git a/src/gthr_aux.h b/mcfgthread/gthr_aux.h similarity index 100% rename from src/gthr_aux.h rename to mcfgthread/gthr_aux.h diff --git a/src/memcmp.c b/mcfgthread/memcmp.c similarity index 100% rename from src/memcmp.c rename to mcfgthread/memcmp.c diff --git a/src/memcpy.c b/mcfgthread/memcpy.c similarity index 100% rename from src/memcpy.c rename to mcfgthread/memcpy.c diff --git a/src/memmove.c b/mcfgthread/memmove.c similarity index 100% rename from src/memmove.c rename to mcfgthread/memmove.c diff --git a/src/memset.c b/mcfgthread/memset.c similarity index 100% rename from src/memset.c rename to mcfgthread/memset.c diff --git a/src/mutex.c b/mcfgthread/mutex.c similarity index 100% rename from src/mutex.c rename to mcfgthread/mutex.c diff --git a/src/mutex.h b/mcfgthread/mutex.h similarity index 100% rename from src/mutex.h rename to mcfgthread/mutex.h diff --git a/src/once.c b/mcfgthread/once.c similarity index 100% rename from src/once.c rename to mcfgthread/once.c diff --git a/src/once.h b/mcfgthread/once.h similarity index 100% rename from src/once.h rename to mcfgthread/once.h diff --git a/src/precompiled.i b/mcfgthread/precompiled.i similarity index 100% rename from src/precompiled.i rename to mcfgthread/precompiled.i diff --git a/src/sem.c b/mcfgthread/sem.c similarity index 100% rename from src/sem.c rename to mcfgthread/sem.c diff --git a/src/sem.h b/mcfgthread/sem.h similarity index 100% rename from src/sem.h rename to mcfgthread/sem.h diff --git a/src/thread.c b/mcfgthread/thread.c similarity index 100% rename from src/thread.c rename to mcfgthread/thread.c diff --git a/src/thread.h b/mcfgthread/thread.h similarity index 100% rename from src/thread.h rename to mcfgthread/thread.h diff --git a/src/tls.c b/mcfgthread/tls.c similarity index 100% rename from src/tls.c rename to mcfgthread/tls.c diff --git a/src/tls.h b/mcfgthread/tls.h similarity index 100% rename from src/tls.h rename to mcfgthread/tls.h diff --git a/src/version.h.in b/mcfgthread/version.h.in similarity index 100% rename from src/version.h.in rename to mcfgthread/version.h.in diff --git a/src/version.rc b/mcfgthread/version.rc similarity index 100% rename from src/version.rc rename to mcfgthread/version.rc diff --git a/src/xglobals.c b/mcfgthread/xglobals.c similarity index 100% rename from src/xglobals.c rename to mcfgthread/xglobals.c diff --git a/src/xglobals.i b/mcfgthread/xglobals.i similarity index 100% rename from src/xglobals.i rename to mcfgthread/xglobals.i diff --git a/test/at_quick_exit_ignored_on__Exit.c b/test/at_quick_exit_ignored_on__Exit.c index f164d4f52b..d159327487 100644 --- a/test/at_quick_exit_ignored_on__Exit.c +++ b/test/at_quick_exit_ignored_on__Exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/at_quick_exit_ignored_on_exit.c b/test/at_quick_exit_ignored_on_exit.c index 087aaa5e23..6983434ead 100644 --- a/test/at_quick_exit_ignored_on_exit.c +++ b/test/at_quick_exit_ignored_on_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/at_quick_exit_order.c b/test/at_quick_exit_order.c index 4a52399083..d0fdcc7074 100644 --- a/test/at_quick_exit_order.c +++ b/test/at_quick_exit_order.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/atexit_ignored_on__Exit.c b/test/atexit_ignored_on__Exit.c index dc887727b7..a734e6e175 100644 --- a/test/atexit_ignored_on__Exit.c +++ b/test/atexit_ignored_on__Exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/atexit_ignored_on_quick_exit.c b/test/atexit_ignored_on_quick_exit.c index 085f33c2b7..1441955739 100644 --- a/test/atexit_ignored_on_quick_exit.c +++ b/test/atexit_ignored_on_quick_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/atexit_order.c b/test/atexit_order.c index e24ae216a5..a84e898401 100644 --- a/test/atexit_order.c +++ b/test/atexit_order.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/atexit_thread_self.c b/test/atexit_thread_self.c index db1eaab673..582727d4c8 100644 --- a/test/atexit_thread_self.c +++ b/test/atexit_thread_self.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/thread.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/c11_c89_pedantic.c b/test/c11_c89_pedantic.c index 8438aabbed..7e2e62881e 100644 --- a/test/c11_c89_pedantic.c +++ b/test/c11_c89_pedantic.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) # error Please compile this file as C89. diff --git a/test/c11_call_once.c b/test/c11_call_once.c index 970d389dcf..e929b4a643 100644 --- a/test/c11_call_once.c +++ b/test/c11_call_once.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_cnd_consumers.c b/test/c11_cnd_consumers.c index a952c77c65..b9ff9e3726 100644 --- a/test/c11_cnd_consumers.c +++ b/test/c11_cnd_consumers.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include #include diff --git a/test/c11_cnd_consumers_recursive.c b/test/c11_cnd_consumers_recursive.c index d044f56fcf..f1d554844f 100644 --- a/test/c11_cnd_consumers_recursive.c +++ b/test/c11_cnd_consumers_recursive.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include #include diff --git a/test/c11_cnd_timeout.c b/test/c11_cnd_timeout.c index a1dca39edf..31239b69c2 100644 --- a/test/c11_cnd_timeout.c +++ b/test/c11_cnd_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_inline_alias.c b/test/c11_inline_alias.c index be9be0d656..c435795e0f 100644 --- a/test/c11_inline_alias.c +++ b/test/c11_inline_alias.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include int diff --git a/test/c11_mtx.c b/test/c11_mtx.c index e99a0cda04..9f23afd373 100644 --- a/test/c11_mtx.c +++ b/test/c11_mtx.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_mtx_nonrecursive.c b/test/c11_mtx_nonrecursive.c index 3265540e48..e181f0b54a 100644 --- a/test/c11_mtx_nonrecursive.c +++ b/test/c11_mtx_nonrecursive.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_mtx_recursive.c b/test/c11_mtx_recursive.c index 96d1053312..1dc2048895 100644 --- a/test/c11_mtx_recursive.c +++ b/test/c11_mtx_recursive.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_mtx_recursive_timeout.c b/test/c11_mtx_recursive_timeout.c index 3cf2a24499..e4076347e7 100644 --- a/test/c11_mtx_recursive_timeout.c +++ b/test/c11_mtx_recursive_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_mtx_recursive_trylock.c b/test/c11_mtx_recursive_trylock.c index 1896f8f883..765b608bd1 100644 --- a/test/c11_mtx_recursive_trylock.c +++ b/test/c11_mtx_recursive_trylock.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_mtx_timeout.c b/test/c11_mtx_timeout.c index 2be1ae084b..71ca9641a6 100644 --- a/test/c11_mtx_timeout.c +++ b/test/c11_mtx_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_mtx_timeout_unsupported.c b/test/c11_mtx_timeout_unsupported.c index cddc3957c1..8f2bf07aba 100644 --- a/test/c11_mtx_timeout_unsupported.c +++ b/test/c11_mtx_timeout_unsupported.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_mtx_trylock.c b/test/c11_mtx_trylock.c index bf9d949ef7..c046556fc7 100644 --- a/test/c11_mtx_trylock.c +++ b/test/c11_mtx_trylock.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_thrd_equal.c b/test/c11_thrd_equal.c index afad3e242a..f5790cd2b9 100644 --- a/test/c11_thrd_equal.c +++ b/test/c11_thrd_equal.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include #include diff --git a/test/c11_thrd_return.c b/test/c11_thrd_return.c index 8882411339..47d3a40023 100644 --- a/test/c11_thrd_return.c +++ b/test/c11_thrd_return.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include #include diff --git a/test/c11_thrd_sleep.c b/test/c11_thrd_sleep.c index c5260493ee..7649ebaf28 100644 --- a/test/c11_thrd_sleep.c +++ b/test/c11_thrd_sleep.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/clock.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/c11_tss_deleted_key.c b/test/c11_tss_deleted_key.c index 855176ff2d..9d61e57d88 100644 --- a/test/c11_tss_deleted_key.c +++ b/test/c11_tss_deleted_key.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_tss_dtor.c b/test/c11_tss_dtor.c index ab1f72e1a6..cea2aa0c6c 100644 --- a/test/c11_tss_dtor.c +++ b/test/c11_tss_dtor.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" -#include "../src/sem.h" +#include "../mcfgthread/c11.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/c11_tss_many.c b/test/c11_tss_many.c index cdf876e1d7..f48c463619 100644 --- a/test/c11_tss_many.c +++ b/test/c11_tss_many.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include int diff --git a/test/c11_tss_set.c b/test/c11_tss_set.c index ff3e3679d5..316e176e14 100644 --- a/test/c11_tss_set.c +++ b/test/c11_tss_set.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/c11.h" +#include "../mcfgthread/c11.h" #include #include diff --git a/test/clock.c b/test/clock.c index a5afa1100e..a1b588cd22 100644 --- a/test/clock.c +++ b/test/clock.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/clock.h" +#include "../mcfgthread/clock.h" #include #include #include diff --git a/test/cond_timeout.c b/test/cond_timeout.c index d01c846437..ec7f3b7596 100644 --- a/test/cond_timeout.c +++ b/test/cond_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cond.h" -#include "../src/clock.h" +#include "../mcfgthread/cond.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/cxa_atexit_all.c b/test/cxa_atexit_all.c index 6d098fd7ab..dea3e1f956 100644 --- a/test/cxa_atexit_all.c +++ b/test/cxa_atexit_all.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" +#include "../mcfgthread/cxa.h" #include #include #include diff --git a/test/cxa_atexit_dso.c b/test/cxa_atexit_dso.c index 3f2ba2dccd..c082efc006 100644 --- a/test/cxa_atexit_dso.c +++ b/test/cxa_atexit_dso.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" +#include "../mcfgthread/cxa.h" #include #include #include diff --git a/test/cxa_thread_atexit.c b/test/cxa_thread_atexit.c index 7fd48c901c..97214a4ef1 100644 --- a/test/cxa_thread_atexit.c +++ b/test/cxa_thread_atexit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/thread.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/cxa_thread_atexit_exit.c b/test/cxa_thread_atexit_exit.c index b8f622aa99..9d316106cd 100644 --- a/test/cxa_thread_atexit_exit.c +++ b/test/cxa_thread_atexit_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/cxa.h" -#include "../src/exit.h" +#include "../mcfgthread/cxa.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/dtor_queue_all.c b/test/dtor_queue_all.c index 37eb683a99..9fe7f3be1c 100644 --- a/test/dtor_queue_all.c +++ b/test/dtor_queue_all.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/dtor_queue.h" +#include "../mcfgthread/dtor_queue.h" #include #include diff --git a/test/dtor_queue_dso.c b/test/dtor_queue_dso.c index ef616afd95..e2103a46f8 100644 --- a/test/dtor_queue_dso.c +++ b/test/dtor_queue_dso.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/dtor_queue.h" +#include "../mcfgthread/dtor_queue.h" #include #include diff --git a/test/dtor_queue_remove.c b/test/dtor_queue_remove.c index 371c92b1ed..27750db360 100644 --- a/test/dtor_queue_remove.c +++ b/test/dtor_queue_remove.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/dtor_queue.h" +#include "../mcfgthread/dtor_queue.h" #include #include diff --git a/test/event_init.c b/test/event_init.c index 9ef4b6c0f9..2e42f399fe 100644 --- a/test/event_init.c +++ b/test/event_init.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/event.h" -#include "../src/clock.h" +#include "../mcfgthread/event.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/event_timeout.c b/test/event_timeout.c index eee5fea1a6..1b86bedeed 100644 --- a/test/event_timeout.c +++ b/test/event_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/event.h" -#include "../src/clock.h" +#include "../mcfgthread/event.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/event_value.c b/test/event_value.c index 5581458b9e..6db30e33d2 100644 --- a/test/event_value.c +++ b/test/event_value.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/event.h" -#include "../src/clock.h" +#include "../mcfgthread/event.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/gthr_c89_pedantic.c b/test/gthr_c89_pedantic.c index 8c1caad793..da6c03305a 100644 --- a/test/gthr_c89_pedantic.c +++ b/test/gthr_c89_pedantic.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) # error Please compile this file as C89. diff --git a/test/gthr_cond_consumers.c b/test/gthr_cond_consumers.c index ce921c8759..01ec4aa6a6 100644 --- a/test/gthr_cond_consumers.c +++ b/test/gthr_cond_consumers.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include #include diff --git a/test/gthr_cond_consumers_recursive.c b/test/gthr_cond_consumers_recursive.c index e4f46a814e..8782ad41f5 100644 --- a/test/gthr_cond_consumers_recursive.c +++ b/test/gthr_cond_consumers_recursive.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include #include diff --git a/test/gthr_cond_timeout.c b/test/gthr_cond_timeout.c index d36dd7e005..fa3bf6a5e4 100644 --- a/test/gthr_cond_timeout.c +++ b/test/gthr_cond_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/clock.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/gthr_equal.c b/test/gthr_equal.c index 7fa6f71dea..ca1b4d4437 100644 --- a/test/gthr_equal.c +++ b/test/gthr_equal.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include #include diff --git a/test/gthr_inline_alias.c b/test/gthr_inline_alias.c index 8db62ead6b..f75a79d9c9 100644 --- a/test/gthr_inline_alias.c +++ b/test/gthr_inline_alias.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include int diff --git a/test/gthr_mutex.c b/test/gthr_mutex.c index d75b9e7738..0f832a41e2 100644 --- a/test/gthr_mutex.c +++ b/test/gthr_mutex.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_mutex_nonrecursive.c b/test/gthr_mutex_nonrecursive.c index ba7ba5c032..903d2c6633 100644 --- a/test/gthr_mutex_nonrecursive.c +++ b/test/gthr_mutex_nonrecursive.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/clock.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/gthr_mutex_timeout.c b/test/gthr_mutex_timeout.c index abee0579f1..c0c6775e1d 100644 --- a/test/gthr_mutex_timeout.c +++ b/test/gthr_mutex_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/clock.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/gthr_mutex_trylock.c b/test/gthr_mutex_trylock.c index 9e0ec71652..eb9fc15065 100644 --- a/test/gthr_mutex_trylock.c +++ b/test/gthr_mutex_trylock.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_once.c b/test/gthr_once.c index 4b4984e5ae..eb01ffa60a 100644 --- a/test/gthr_once.c +++ b/test/gthr_once.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_rc_mutex.c b/test/gthr_rc_mutex.c index a566c1a426..29acf18a70 100644 --- a/test/gthr_rc_mutex.c +++ b/test/gthr_rc_mutex.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_rc_mutex_timeout.c b/test/gthr_rc_mutex_timeout.c index 9f3d51f623..ec998adb3e 100644 --- a/test/gthr_rc_mutex_timeout.c +++ b/test/gthr_rc_mutex_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/clock.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/gthr_rc_mutex_trylock.c b/test/gthr_rc_mutex_trylock.c index 54585cd12e..5a4a8a7afe 100644 --- a/test/gthr_rc_mutex_trylock.c +++ b/test/gthr_rc_mutex_trylock.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_thread_return.c b/test/gthr_thread_return.c index 0ae1d16eb5..6b9016f8c4 100644 --- a/test/gthr_thread_return.c +++ b/test/gthr_thread_return.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include #include diff --git a/test/gthr_tls_deleted_key.c b/test/gthr_tls_deleted_key.c index 0c40dbf3f0..411b8e1843 100644 --- a/test/gthr_tls_deleted_key.c +++ b/test/gthr_tls_deleted_key.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_tls_dtor.c b/test/gthr_tls_dtor.c index f87d670248..6a19816bb7 100644 --- a/test/gthr_tls_dtor.c +++ b/test/gthr_tls_dtor.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" -#include "../src/sem.h" +#include "../mcfgthread/gthr.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/gthr_tls_many.c b/test/gthr_tls_many.c index 2569b1da92..595cbbc01e 100644 --- a/test/gthr_tls_many.c +++ b/test/gthr_tls_many.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include int diff --git a/test/gthr_tls_set.c b/test/gthr_tls_set.c index b89a305452..a7f70a7d90 100644 --- a/test/gthr_tls_set.c +++ b/test/gthr_tls_set.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/gthr.h" +#include "../mcfgthread/gthr.h" #include #include diff --git a/test/memory.c b/test/memory.c index 5bc3dcafc8..5b6b5064f8 100644 --- a/test/memory.c +++ b/test/memory.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/xglobals.i" +#include "../mcfgthread/xglobals.i" #include #include #include diff --git a/test/mutex.c b/test/mutex.c index cbd074b0a5..7a41e75710 100644 --- a/test/mutex.c +++ b/test/mutex.c @@ -2,9 +2,9 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/mutex.h" -#include "../src/thread.h" -#include "../src/sem.h" +#include "../mcfgthread/mutex.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/mutex_spin_fail.c b/test/mutex_spin_fail.c index cf5c43dc28..89595f8a4d 100644 --- a/test/mutex_spin_fail.c +++ b/test/mutex_spin_fail.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/mutex.h" +#include "../mcfgthread/mutex.h" #include #include diff --git a/test/mutex_spin_mask.c b/test/mutex_spin_mask.c index ebc2992cac..a150cefa11 100644 --- a/test/mutex_spin_mask.c +++ b/test/mutex_spin_mask.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/mutex.h" +#include "../mcfgthread/mutex.h" #include #include diff --git a/test/mutex_timeout.c b/test/mutex_timeout.c index aa440a52a8..ab98a8a116 100644 --- a/test/mutex_timeout.c +++ b/test/mutex_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/mutex.h" -#include "../src/clock.h" +#include "../mcfgthread/mutex.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/mutex_zero_timeout.c b/test/mutex_zero_timeout.c index 39e628628e..5256aa4b5e 100644 --- a/test/mutex_zero_timeout.c +++ b/test/mutex_zero_timeout.c @@ -2,9 +2,9 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/mutex.h" -#include "../src/thread.h" -#include "../src/sem.h" +#include "../mcfgthread/mutex.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/once_abort.c b/test/once_abort.c index ce23dfe3fb..5ca1f01eb3 100644 --- a/test/once_abort.c +++ b/test/once_abort.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/once.h" -#include "../src/thread.h" +#include "../mcfgthread/once.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/once_release.c b/test/once_release.c index fb79f3f840..eb06148b89 100644 --- a/test/once_release.c +++ b/test/once_release.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/once.h" -#include "../src/thread.h" +#include "../mcfgthread/once.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/once_timeout.c b/test/once_timeout.c index daf53045a7..54449c7ced 100644 --- a/test/once_timeout.c +++ b/test/once_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/once.h" -#include "../src/clock.h" +#include "../mcfgthread/once.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/once_zero_timeout.c b/test/once_zero_timeout.c index c829cf5740..1618b40859 100644 --- a/test/once_zero_timeout.c +++ b/test/once_zero_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/once.h" -#include "../src/thread.h" +#include "../mcfgthread/once.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/sem_init.c b/test/sem_init.c index 9bede6f849..97b66f4c82 100644 --- a/test/sem_init.c +++ b/test/sem_init.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/sem.h" -#include "../src/clock.h" +#include "../mcfgthread/sem.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/sem_timeout.c b/test/sem_timeout.c index f6a4bc9fef..b7c8c4109b 100644 --- a/test/sem_timeout.c +++ b/test/sem_timeout.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/sem.h" -#include "../src/clock.h" +#include "../mcfgthread/sem.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/sem_value.c b/test/sem_value.c index c46540c278..a2324d2034 100644 --- a/test/sem_value.c +++ b/test/sem_value.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/sem.h" -#include "../src/clock.h" +#include "../mcfgthread/sem.h" +#include "../mcfgthread/clock.h" #include #include diff --git a/test/thread_new_alignment.c b/test/thread_new_alignment.c index a7d130c338..eaa37f5c64 100644 --- a/test/thread_new_alignment.c +++ b/test/thread_new_alignment.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include #include #include diff --git a/test/thread_overlarge.c b/test/thread_overlarge.c index 629eaa56e5..7f271fa385 100644 --- a/test/thread_overlarge.c +++ b/test/thread_overlarge.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include #include #include diff --git a/test/thread_self_id.c b/test/thread_self_id.c index dfb6d4eea5..3a3ce99d63 100644 --- a/test/thread_self_id.c +++ b/test/thread_self_id.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include #include #include diff --git a/test/thread_x87_precision.c b/test/thread_x87_precision.c index 960c86f331..0b5ff056a6 100644 --- a/test/thread_x87_precision.c +++ b/test/thread_x87_precision.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include #include diff --git a/test/tls_deleted_key.c b/test/tls_deleted_key.c index cc36e5de20..01ae83be0c 100644 --- a/test/tls_deleted_key.c +++ b/test/tls_deleted_key.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/sem.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/tls_dtor.c b/test/tls_dtor.c index 34f66bb1b6..871deaae70 100644 --- a/test/tls_dtor.c +++ b/test/tls_dtor.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/sem.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/sem.h" #include #include diff --git a/test/tls_dtor_ignored_on__Exit.c b/test/tls_dtor_ignored_on__Exit.c index 0f6642263b..2abf51d051 100644 --- a/test/tls_dtor_ignored_on__Exit.c +++ b/test/tls_dtor_ignored_on__Exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/exit.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/tls_dtor_ignored_on_exit.c b/test/tls_dtor_ignored_on_exit.c index 2c167a7425..497b79e78d 100644 --- a/test/tls_dtor_ignored_on_exit.c +++ b/test/tls_dtor_ignored_on_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/exit.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/tls_dtor_ignored_on_quick_exit.c b/test/tls_dtor_ignored_on_quick_exit.c index 39f15441e4..9990a3ea01 100644 --- a/test/tls_dtor_ignored_on_quick_exit.c +++ b/test/tls_dtor_ignored_on_quick_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/exit.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/tls_dtor_thread_exit.c b/test/tls_dtor_thread_exit.c index c7f138d848..139ecf5ef7 100644 --- a/test/tls_dtor_thread_exit.c +++ b/test/tls_dtor_thread_exit.c @@ -2,8 +2,8 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" -#include "../src/exit.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/exit.h" #include #include diff --git a/test/tls_many.c b/test/tls_many.c index aa95aa2164..e98fb136bc 100644 --- a/test/tls_many.c +++ b/test/tls_many.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include int diff --git a/test/tls_set.c b/test/tls_set.c index 332e3edfb8..abfa00afd9 100644 --- a/test/tls_set.c +++ b/test/tls_set.c @@ -2,7 +2,7 @@ * See LICENSE.TXT for licensing information. * Copyleft 2022, LH_Mouse. All wrongs reserved. */ -#include "../src/thread.h" +#include "../mcfgthread/thread.h" #include #include From c165340cf72dd459aaefc6fc7f6760625dd06f98 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 12 Dec 2022 16:40:35 +0800 Subject: [PATCH 120/133] test/cxa_atexit_order: New test (cherry picked from commit 5b5cbd728966800c5c1ec4137726636f23e456b4) Signed-off-by: LIU Hao --- test/Makefile.inc.am | 1 + test/cxa_atexit_order.c | 46 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/cxa_atexit_order.c diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index afe6455fae..8876a42a73 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -24,6 +24,7 @@ check_PROGRAMS += \ %reldir%/cxa_atexit_all.test \ %reldir%/cxa_thread_atexit.test \ %reldir%/cxa_thread_atexit_exit.test \ + %reldir%/cxa_atexit_order.test \ %reldir%/tls_dtor.test \ %reldir%/tls_set.test \ %reldir%/tls_deleted_key.test \ diff --git a/test/cxa_atexit_order.c b/test/cxa_atexit_order.c new file mode 100644 index 0000000000..63c64d6580 --- /dev/null +++ b/test/cxa_atexit_order.c @@ -0,0 +1,46 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../mcfgthread/cxa.h" +#include +#include +#include + +static +void +cleanup_1(void* ptr) + { + assert((intptr_t) ptr == 1); + } + +static +void +cleanup_2(void* ptr) + { + assert((intptr_t) ptr == 2); + } + +static +void +cleanup_3(void* ptr) + { + assert((intptr_t) ptr == 3); + } + +static +void +cleanup_4(void* ptr) + { + assert((intptr_t) ptr == 4); + } + +int +main(void) + { + __MCF_cxa_atexit(cleanup_4, (void*) 4, NULL); + __MCF_cxa_thread_atexit(cleanup_2, (void*) 2, NULL); + __MCF_cxa_thread_atexit(cleanup_1, (void*) 1, NULL); + __MCF_cxa_atexit(cleanup_3, (void*) 3, NULL); + __MCF_cxa_finalize(NULL); + } From 9e2ec5d375e35746dfebef7aee5f36c4ef72c60d Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Wed, 14 Dec 2022 13:42:57 +0800 Subject: [PATCH 121/133] xglobals: Join two lines (cherry picked from commit 0110702e351e4d09ab3639131fe08f1d4fae8c86) Signed-off-by: LIU Hao --- mcfgthread/xglobals.i | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mcfgthread/xglobals.i b/mcfgthread/xglobals.i index be2ae8602f..eefe92d396 100644 --- a/mcfgthread/xglobals.i +++ b/mcfgthread/xglobals.i @@ -392,8 +392,7 @@ void* __MCF_mrealloc_0(void** __pptr, size_t __size) __MCF_NOEXCEPT { void* __ptr = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *__pptr, __size); - return !__ptr ? NULL - : (*__pptr = __ptr); + return !__ptr ? NULL : (*__pptr = __ptr); } __MCF_XGLOBALS_INLINE @@ -401,8 +400,7 @@ void* __MCF_malloc_copy(const void* __data, size_t __size) __MCF_NOEXCEPT { void* __ptr = HeapAlloc(GetProcessHeap(), 0, __size); - return !__ptr ? NULL - : __MCF_mcopy(__ptr, __data, __size); + return !__ptr ? NULL : __MCF_mcopy(__ptr, __data, __size); } __MCF_XGLOBALS_INLINE From 4b73795751a2db8b7809cb16d5bb2f9a5963c77d Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 29 Dec 2022 17:27:59 +0800 Subject: [PATCH 122/133] sem: Fix comments The value of a semaphore is decreased when a thread starts waiting, and increased when a thread is notified. The wait counter of another type of object (mutex, once flag, condition variable, event) is increased when a thread starts waiting, and decreased when a thread is notified. (cherry picked from commit 5b5ddc919bb4994a95eb0ca30febff765112317d) Signed-off-by: LIU Hao --- mcfgthread/sem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcfgthread/sem.c b/mcfgthread/sem.c index b41d67ef80..ec9366add3 100644 --- a/mcfgthread/sem.c +++ b/mcfgthread/sem.c @@ -43,13 +43,13 @@ _MCF_sem_wait(_MCF_sem* sem, const int64_t* timeout_opt) if(old.__value < 0) return -1; - /* ... It is possible that a second thread has already decremented the + /* ... It is possible that a second thread has already incremented the * counter. If this does take place, it is going to release the keyed * event soon. We must still wait, otherwise we get a deadlock in the * second thread. However, a third thread could start waiting for this * keyed event before us, so we set the timeout to zero. If we time out - * once more, the third thread will have incremented the number of - * sleeping threads and we can try decrementing it again. */ + * once more, the third thread will have decremented the number of + * sleeping threads and we can try incrementing it again. */ status = __MCF_keyed_event_signal(sem, (LARGE_INTEGER[]) { 0 }); } From 2ded344bee03a1c7a3f8f5fdb98e2459626ded46 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 12 Jan 2023 20:49:42 +0800 Subject: [PATCH 123/133] ci: Sync with master --- ci/check_includes.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ci/check_includes.sh b/ci/check_includes.sh index 186d3d9831..708375af25 100755 --- a/ci/check_includes.sh +++ b/ci/check_includes.sh @@ -16,14 +16,13 @@ do ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++98 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "mcfgthread" -name "*.h") ->>>>>>> 2d585f8 (build: Move `src` to `mcfgthread` and use `nobase_include_HEADERS`) +for _file in $(find -L "mcfgthread" -name "*.h" -or -name "*.hpp") do echo "Checking header as C++11: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++11 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} done -for _file in $(find -L "mcfgthread" -name "*.h") +for _file in $(find -L "mcfgthread" -name "*.h" -or -name "*.hpp") do echo "Checking header as C++14: ${_cmd} \"${_file}\"" ${CC} ${CPPFLAGS} ${CFLAGS} -x c++-header -std=c++14 -fsyntax-only -DHAVE_CONFIG_H -I. ${_file} From e429222d672bbbfa70e97d454f0b61c94df06913 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 13 Jan 2023 16:57:04 +0800 Subject: [PATCH 124/133] test/clock: Fix check for DST and eliminate some warnings (cherry picked from commit ba33221a11a666ac2fd9565f1ff7a01a6d334c6e) Signed-off-by: LIU Hao --- test/clock.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/clock.c b/test/clock.c index a1b588cd22..0a6db2835d 100644 --- a/test/clock.c +++ b/test/clock.c @@ -8,12 +8,6 @@ #include #include -#ifdef _USE_32BIT_TIME_T -# define my_mktime _mktime64 -#else -# define my_mktime mktime -#endif - int main(void) { @@ -29,11 +23,19 @@ main(void) tm.tm_hour = st.wHour; tm.tm_min = st.wMinute; tm.tm_sec = st.wSecond; - int64_t vcrt_now = my_mktime(&tm) * 1000 + st.wMilliseconds; + tm.tm_isdst = -1; + + time_t ts; +#ifdef _USE_32BIT_TIME_T + ts = _mktime64(&tm); +#else + ts = mktime(&tm); +#endif + long long vcrt_now = ts * 1000 + st.wMilliseconds; printf("vcrt_now = %lld\n", vcrt_now); - int64_t ms_now = _MCF_utc_now(); - int64_t ms_delta = ms_now - vcrt_now; + long long ms_now = _MCF_utc_now(); + long long ms_delta = ms_now - vcrt_now; printf("_MCF_utc_now() = %lld (delta %+lld)\n", ms_now, ms_delta); assert(ms_delta >= -100); assert(ms_delta <= +100); From a123a1c82c492ef0f9db7d7cc754f3063ce52ef8 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 13 Jan 2023 17:25:50 +0800 Subject: [PATCH 125/133] test/clock: Fix error about integer conversion (cherry picked from commit 0a4c74d5c95485d2b6cb0ecf4ceefb42f65a91fb) Signed-off-by: LIU Hao --- test/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/clock.c b/test/clock.c index 0a6db2835d..0cef1650d9 100644 --- a/test/clock.c +++ b/test/clock.c @@ -25,7 +25,7 @@ main(void) tm.tm_sec = st.wSecond; tm.tm_isdst = -1; - time_t ts; + __time64_t ts; #ifdef _USE_32BIT_TIME_T ts = _mktime64(&tm); #else From 69ce3ea2c2906c9960989ad5a17b772830d24443 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 11 Feb 2023 13:49:17 +0800 Subject: [PATCH 126/133] build: Relicense build scripts to public domain Signed-off-by: LIU Hao (cherry picked from commit 6fc9b99920a1b69f08235ea463cd6404e4a896af) Signed-off-by: LIU Hao --- Makefile.am | 14 ++++++++++++++ configure.ac | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Makefile.am b/Makefile.am index 892eab122e..c98ed4f77b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,17 @@ +## Copyright (C) 2022 - 2023 by LH_Mouse +## +## Permission to use, copy, modify, and/or distribute this +## software for any purpose with or without fee is hereby granted. +## +## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +## WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +## WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +## THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +## CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +## LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +## NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +## CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + ACLOCAL_AMFLAGS = -I m4 END = diff --git a/configure.ac b/configure.ac index 7c47feae67..a5a14ab797 100644 --- a/configure.ac +++ b/configure.ac @@ -1,3 +1,17 @@ +## Copyright (C) 2022 - 2023 by LH_Mouse +## +## Permission to use, copy, modify, and/or distribute this +## software for any purpose with or without fee is hereby granted. +## +## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +## WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +## WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +## THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +## CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +## LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +## NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +## CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + ## AC_INIT(package, version, [bug-report], [tarname], [url]) AC_INIT([mcfgthread], [master], [lh_mouse@126.com], [mcfgthread], [https://github.com/lhmouse/mcfgthread]) AC_LANG([C]) From dcce51fcf2cff0c364ca8fd76e2d8f91d70a7cf4 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 30 Mar 2023 09:50:15 +0800 Subject: [PATCH 127/133] build: Use `-version-number` instead pf `-version-info` This makes no difference at the moment, as the `age` field is an implicit zero. Signed-off-by: LIU Hao (cherry picked from commit 40f3b402de5b31d3f0ff3e3cd5d1e3251f5c08f8) Signed-off-by: LIU Hao --- mcfgthread/Makefile.inc.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcfgthread/Makefile.inc.am b/mcfgthread/Makefile.inc.am index af4d8c0c8f..8d6333801e 100644 --- a/mcfgthread/Makefile.inc.am +++ b/mcfgthread/Makefile.inc.am @@ -56,7 +56,7 @@ lib_libmcfgthread_la_LIBADD = \ lib_libmcfgthread_la_LDFLAGS = \ -Wl,--subsystem,windows:6.1,--entry,__MCF_dll_startup@@Z \ -Wl,--exclude-all-symbols,--kill-at,--enable-auto-image-base \ - -Wc,-nostdlib -no-undefined -version-info @abi_major@:@abi_minor@ + -Wc,-nostdlib -no-undefined -version-number @abi_major@:@abi_minor@ if enable_pch lib_libmcfgthread_la_CFLAGS += -include %reldir%/precompiled.xi From cf1614e209feb6618dd317453bb540e4e9bfd028 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Sat, 20 May 2023 22:27:16 +0800 Subject: [PATCH 128/133] cond,mutex,once,sem,event,thread: Fix fallback paths for missed wakeups The comments above those lines say 'wait again' and it is `__MCF_keyed_event_wait()` that shall be called. This fixes #86. Signed-off-by: LIU Hao (cherry picked from commit d283e3f095c5c4e6a4f1c2d9ae74415cc8df85e9) Signed-off-by: LIU Hao (cherry picked from commit 5b5416a9b616c5dd00b9ad16d5990bea914d06fd) Signed-off-by: LIU Hao --- mcfgthread/cond.c | 2 +- mcfgthread/event.c | 2 +- mcfgthread/mutex.c | 2 +- mcfgthread/once.c | 2 +- mcfgthread/sem.c | 2 +- test/Makefile.inc.am | 1 + test/cond_multi_wait.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 test/cond_multi_wait.c diff --git a/mcfgthread/cond.c b/mcfgthread/cond.c index d1fc7d604f..29c14a3de1 100644 --- a/mcfgthread/cond.c +++ b/mcfgthread/cond.c @@ -80,7 +80,7 @@ _MCF_cond_wait(_MCF_cond* cond, _MCF_cond_unlock_callback* unlock_opt, _MCF_cond * keyed event before us, so we set the timeout to zero. If we time out * once more, the third thread will have incremented the number of * sleeping threads and we can try decrementing it again. */ - status = __MCF_keyed_event_signal(cond, (LARGE_INTEGER[]) { 0 }); + status = __MCF_keyed_event_wait(cond, (LARGE_INTEGER[]) { 0 }); } /* We have got notified. */ diff --git a/mcfgthread/event.c b/mcfgthread/event.c index a159fa85e1..f4e5688ec7 100644 --- a/mcfgthread/event.c +++ b/mcfgthread/event.c @@ -57,7 +57,7 @@ _MCF_event_await_change_slow(_MCF_event* event, int undesired, const int64_t* ti * keyed event before us, so we set the timeout to zero. If we time out * once more, the third thread will have incremented the number of * sleeping threads and we can try decrementing it again. */ - status = __MCF_keyed_event_signal(event, (LARGE_INTEGER[]) { 0 }); + status = __MCF_keyed_event_wait(event, (LARGE_INTEGER[]) { 0 }); } /* We have got notified. */ diff --git a/mcfgthread/mutex.c b/mcfgthread/mutex.c index a0285794ed..2f0aa447ca 100644 --- a/mcfgthread/mutex.c +++ b/mcfgthread/mutex.c @@ -159,7 +159,7 @@ _MCF_mutex_lock_slow(_MCF_mutex* mutex, const int64_t* timeout_opt) * keyed event before us, so we set the timeout to zero. If we time out * once more, the third thread will have incremented the number of * sleeping threads and we can try decrementing it again. */ - status = __MCF_keyed_event_signal(mutex, (LARGE_INTEGER[]) { 0 }); + status = __MCF_keyed_event_wait(mutex, (LARGE_INTEGER[]) { 0 }); } /* We have got notified. */ diff --git a/mcfgthread/once.c b/mcfgthread/once.c index 6d5efb123e..c3c002439f 100644 --- a/mcfgthread/once.c +++ b/mcfgthread/once.c @@ -66,7 +66,7 @@ _MCF_once_wait_slow(_MCF_once* once, const int64_t* timeout_opt) * keyed event before us, so we set the timeout to zero. If we time out * once more, the third thread will have incremented the number of * sleeping threads and we can try decrementing it again. */ - status = __MCF_keyed_event_signal(once, (LARGE_INTEGER[]) { 0 }); + status = __MCF_keyed_event_wait(once, (LARGE_INTEGER[]) { 0 }); } /* We have got notified. */ diff --git a/mcfgthread/sem.c b/mcfgthread/sem.c index ec9366add3..52d1571cb8 100644 --- a/mcfgthread/sem.c +++ b/mcfgthread/sem.c @@ -50,7 +50,7 @@ _MCF_sem_wait(_MCF_sem* sem, const int64_t* timeout_opt) * keyed event before us, so we set the timeout to zero. If we time out * once more, the third thread will have decremented the number of * sleeping threads and we can try incrementing it again. */ - status = __MCF_keyed_event_signal(sem, (LARGE_INTEGER[]) { 0 }); + status = __MCF_keyed_event_wait(sem, (LARGE_INTEGER[]) { 0 }); } /* We have got notified. */ diff --git a/test/Makefile.inc.am b/test/Makefile.inc.am index 8876a42a73..2c58a69bff 100644 --- a/test/Makefile.inc.am +++ b/test/Makefile.inc.am @@ -11,6 +11,7 @@ check_PROGRAMS += \ %reldir%/mutex_timeout.test \ %reldir%/mutex.test \ %reldir%/cond_timeout.test \ + %reldir%/cond_multi_wait.test \ %reldir%/sem_init.test \ %reldir%/sem_timeout.test \ %reldir%/sem_value.test \ diff --git a/test/cond_multi_wait.c b/test/cond_multi_wait.c new file mode 100644 index 0000000000..bf129cb105 --- /dev/null +++ b/test/cond_multi_wait.c @@ -0,0 +1,59 @@ +/* This file is part of MCF Gthread. + * See LICENSE.TXT for licensing information. + * Copyleft 2022, LH_Mouse. All wrongs reserved. */ + +#include "../mcfgthread/cond.h" +#include "../mcfgthread/thread.h" +#include "../mcfgthread/clock.h" +#include +#include + +static _MCF_thread* thread1; +static _MCF_thread* thread2; +static _MCF_cond cond; +static int32_t signal_count; + +static +void +thread_proc(_MCF_thread* self) + { + (void) self; + + const int64_t start_time = _MCF_tick_count(); + while(_MCF_tick_count() < start_time + 3000) { + _MCF_cond_wait(&cond, NULL, NULL, 0, (const int64_t[]){ 0 }); + + // Check whether a deadlock has occurred. + // https://github.com/lhmouse/mcfgthread/issues/86 + int32_t c1 = _MCF_atomic_load_32_rlx(&signal_count); + if(signal_count & 1) { + // Main thread is waiting. + _MCF_sleep((const int64_t[]){ -10 }); + int32_t c2 = _MCF_atomic_load_32_rlx(&signal_count); + if(c1 == c2) { + printf("maybe deadlock\n"); + break; + } + } + } + } + +int +main(void) + { + thread1 = _MCF_thread_new(thread_proc, NULL, 0); + assert(thread1); + thread2 = _MCF_thread_new(thread_proc, NULL, 0); + assert(thread2); + + const int64_t start_time = _MCF_tick_count(); + while(_MCF_tick_count() < start_time + 3000) { + _MCF_atomic_xadd_32_rlx(&signal_count, 1); + _MCF_cond_signal_all(&cond); + _MCF_atomic_xadd_32_rlx(&signal_count, 1); + } + + printf("main waiting\n"); + _MCF_thread_wait(thread1, NULL); + _MCF_thread_wait(thread2, NULL); + } From 1dfb89e7b6ca19d3762d0acf88c6f8b7982ab153 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 9 Nov 2023 10:06:12 +0800 Subject: [PATCH 129/133] c11: Fix check about `__STDC_VERSION__` For C11 it is defined as `201112L`. The erroneous value `201103L` was for C++11. (cherry picked from commit e0bb748aae30ac18b9a91cf0863f286b9eb5eef0) Signed-off-by: LIU Hao (cherry picked from commit cff3a3af7424362b21012fcf79feb83f095f1acf) Signed-off-by: LIU Hao --- mcfgthread/c11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcfgthread/c11.h b/mcfgthread/c11.h index 881e1cf6d5..58d2f56f18 100644 --- a/mcfgthread/c11.h +++ b/mcfgthread/c11.h @@ -15,7 +15,7 @@ __MCF_C_DECLARATIONS_BEGIN #endif /* N1570 7.26.1 Introduction */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201103L) +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) # define thread_local _Thread_local #endif From 424e5b532e52ce1eded0afc9b689b2ce021b0cb5 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Fri, 8 Mar 2024 16:29:11 +0800 Subject: [PATCH 130/133] c11: A little cleanup (cherry picked from commit 33e75c63551ac5299c7906a9f0b5370294003caa) Signed-off-by: LIU Hao --- mcfgthread/c11.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mcfgthread/c11.c b/mcfgthread/c11.c index 07e85ffc50..152d4c1af3 100644 --- a/mcfgthread/c11.c +++ b/mcfgthread/c11.c @@ -34,18 +34,17 @@ __MCF_c11_thrd_sleep(const __MCF_timespec* dur, __MCF_timespec* rem_opt) end_time = __builtin_fmax(end_time, 0); end_time = __builtin_fmin(end_time, 0x1p63 - 0x1p10); + if(rem_opt) + *rem_opt = (__MCF_timespec) __MCF_0_INIT; + int64_t timeout = (int64_t) end_time; int err = _MCF_sleep(&timeout); - if(rem_opt) { - *rem_opt = (__MCF_timespec) __MCF_0_INIT; - - if(err) { - /* Calculate the remaining time if the operation was interrupted. */ - double rem = __builtin_fmax(end_time - _MCF_hires_utc_now(), 0) * 0.001; - rem_opt->tv_sec = (time_t) rem; - rem_opt->tv_nsec = (long) ((rem - (double) rem_opt->tv_sec) * 1000000000); - } + if(rem_opt && err) { + /* Calculate the remaining time if the operation was interrupted. */ + double rem = __builtin_fmax(end_time - _MCF_hires_utc_now(), 0) * 0.001; + rem_opt->tv_sec = (time_t) rem; + rem_opt->tv_nsec = (long) ((rem - (double) rem_opt->tv_sec) * 1000000000); } /* Return 0 in case of timeouts, and -1 in case of interrupts. */ From b5471581403f1301b75dbcfdd8f8ba21fc540a63 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 14 Mar 2024 09:53:45 +0800 Subject: [PATCH 131/133] test/clock: Use `_tzset()` (cherry picked from commit 23154d399ef2c3c66951727b42e374ec3f02f736) Signed-off-by: LIU Hao --- test/clock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/clock.c b/test/clock.c index 0cef1650d9..87c139317b 100644 --- a/test/clock.c +++ b/test/clock.c @@ -11,7 +11,7 @@ int main(void) { - tzset(); + _tzset(); SYSTEMTIME st; GetLocalTime(&st); From 23e8a817cf9658df0f8e2285da6d50f3be9fdab0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 14 Mar 2024 20:53:35 +0800 Subject: [PATCH 132/133] thread: Join two lines (cherry picked from commit a9f1ced1e45580704120185afe76c1a25d5108c7) Signed-off-by: LIU Hao --- mcfgthread/thread.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mcfgthread/thread.c b/mcfgthread/thread.c index b8151b75a0..d29377e682 100644 --- a/mcfgthread/thread.c +++ b/mcfgthread/thread.c @@ -154,8 +154,7 @@ int _MCF_sleep(const int64_t* timeout_opt) { /* Set a handler to receive Ctrl-C notifications. */ - BOOL added __attribute__((__cleanup__(do_handler_cleanup))) = false; - added = SetConsoleCtrlHandler(do_handle_interrupt, true); + BOOL added __attribute__((__cleanup__(do_handler_cleanup))) = SetConsoleCtrlHandler(do_handle_interrupt, true); int err = _MCF_cond_wait(&__MCF_interrupt_cond, NULL, NULL, 0, timeout_opt); return err ^ -1; From 1f5983765d0804d698897a4e0a12ee636b28f81a Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Tue, 15 Oct 2024 10:53:43 +0800 Subject: [PATCH 133/133] xglobals: Preserve `__MCF_seh_top` when LTO is enabled (cherry picked from commit d27e71310a1483ad9cb718a99a39679bc15c1198) Signed-off-by: LIU Hao --- mcfgthread/xglobals.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcfgthread/xglobals.c b/mcfgthread/xglobals.c index c5453fa9f8..0a1d8f82a0 100644 --- a/mcfgthread/xglobals.c +++ b/mcfgthread/xglobals.c @@ -11,7 +11,7 @@ #include "cond.h" #include "dtor_queue.h" -__MCF_DLLEXPORT +__MCF_DLLEXPORT __attribute__((__used__)) EXCEPTION_DISPOSITION __cdecl __MCF_seh_top(EXCEPTION_RECORD* rec, PVOID estab_frame, CONTEXT* ctx, PVOID disp_ctx)