We'll make use of address-wait functions in the next commit.
---
mingw-w64-libraries/winpthreads/src/misc.c | 66 ++++++++++++++--------
mingw-w64-libraries/winpthreads/src/misc.h | 14 +++++
2 files changed, 56 insertions(+), 24 deletions(-)
diff --git a/mingw-w64-libraries/winpthreads/src/misc.c
b/mingw-w64-libraries/winpthreads/src/misc.c
index ea8d3551..dcb73d82 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.c
+++ b/mingw-w64-libraries/winpthreads/src/misc.c
@@ -41,6 +41,10 @@ static ULONGLONG (WINAPI *_pthread_get_tick_count_64) (VOID);
HRESULT (WINAPI *_pthread_set_thread_description) (HANDLE, PCWSTR) = NULL;
BOOL (WINAPI *_pthread_get_handle_information) (HANDLE, LPDWORD) = NULL;
+pWaitOnAddress_t _pthread_wait_on_address;
+pWakeByAddressSingle_t _pthread_wake_by_address_single;
+pWakeByAddressAll_t _pthread_wake_by_address_all;
+
#if defined(__GNUC__) || defined(__clang__)
#if __GNUC__ >= 9 && !defined(__clang__)
#pragma GCC diagnostic push
@@ -50,38 +54,52 @@ __attribute__((constructor(0)))
#endif
static void winpthreads_init(void)
{
- HMODULE mod = GetModuleHandleA("kernel32.dll");
- if (mod)
- {
- _pthread_get_handle_information =
- (BOOL (WINAPI *)(HANDLE, LPDWORD))(void*) GetProcAddress(mod,
"GetHandleInformation");
+HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
+ HMODULE kernelbase = GetModuleHandleA("kernelbase.dll");
- _pthread_get_tick_count_64 =
- (ULONGLONG (WINAPI *)(VOID))(void*) GetProcAddress(mod,
"GetTickCount64");
+ assert (kernel32);
- _pthread_set_thread_description =
- (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) GetProcAddress(mod,
"SetThreadDescription");
+ _pthread_get_handle_information =
+ (BOOL (WINAPI *)(HANDLE, LPDWORD))(void*) GetProcAddress(kernel32,
"GetHandleInformation");
- /* <1us precision on Windows 10 */
- _pthread_get_system_time_best_as_file_time =
- (void (WINAPI *)(LPFILETIME))(void*) GetProcAddress(mod,
"GetSystemTimePreciseAsFileTime");
- }
+ _pthread_get_tick_count_64 =
+ (ULONGLONG (WINAPI *)(VOID))(void*) GetProcAddress(kernel32,
"GetTickCount64");
+
+ _pthread_set_thread_description =
+ (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*) GetProcAddress(kernel32,
"SetThreadDescription");
- if (!_pthread_get_system_time_best_as_file_time)
+ /* <1us precision on Windows 10 */
+ _pthread_get_system_time_best_as_file_time =
+ (void (WINAPI *)(LPFILETIME))(void*) GetProcAddress(kernel32,
"GetSystemTimePreciseAsFileTime");
+
+ if (!_pthread_get_system_time_best_as_file_time) {
/* >15ms precision on Windows 10 */
_pthread_get_system_time_best_as_file_time = GetSystemTimeAsFileTime;
+ }
- /* Although SetThreadDescription lives in kernel32.dll, on Windows Server
2016,
- * Windows 10 LTSB 2016 and Windows 10 version 1607, it was only available
in
- * kernelbase.dll. So, load it from there for maximum coverage.
- */
- if (!_pthread_set_thread_description)
- {
- mod = GetModuleHandleA("kernelbase.dll");
- if (mod)
- {
+ if (kernelbase) {
+ /* Although SetThreadDescription lives in kernel32.dll, on Windows
Server 2016,
+ * Windows 10 LTSB 2016 and Windows 10 version 1607, it was only
available in
+ * kernelbase.dll. So, load it from there for maximum coverage.
+ */
+ if (!_pthread_set_thread_description) {
_pthread_set_thread_description =
- (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*)
GetProcAddress(mod, "SetThreadDescription");
+ (HRESULT (WINAPI *)(HANDLE, PCWSTR))(void*)
GetProcAddress(kernelbase, "SetThreadDescription");
+ }
+
+ _pthread_wait_on_address =
+ (pWaitOnAddress_t) GetProcAddress(kernelbase, "WaitOnAddress");
+
+ if (_pthread_wait_on_address) {
+ _pthread_wake_by_address_single =
+ (pWakeByAddressSingle_t) GetProcAddress(kernelbase,
"WakeByAddressSingle");
+
+ assert (_pthread_wake_by_address_single);
+
+ _pthread_wake_by_address_all =
+ (pWakeByAddressAll_t) GetProcAddress(kernelbase,
"WakeByAddressAll");
+
+ assert (_pthread_wake_by_address_all);
}
}
}
diff --git a/mingw-w64-libraries/winpthreads/src/misc.h
b/mingw-w64-libraries/winpthreads/src/misc.h
index cc9e3df4..eb020011 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.h
+++ b/mingw-w64-libraries/winpthreads/src/misc.h
@@ -23,6 +23,8 @@
#ifndef WIN_PTHREADS_MISC_H
#define WIN_PTHREADS_MISC_H
+#include <windows.h>
+
#include <limits.h>
/* public header files */
#include "pthread_compat.h"
@@ -95,6 +97,18 @@ unsigned long _pthread_wait_for_multiple_objects (unsigned
long count, void **ha
extern void (WINAPI *_pthread_get_system_time_best_as_file_time) (LPFILETIME);
extern HRESULT (WINAPI *_pthread_set_thread_description) (HANDLE, PCWSTR);
+typedef BOOL (WINAPI *pWaitOnAddress_t) (volatile VOID *, PVOID, SIZE_T,
DWORD);
+typedef VOID (WINAPI *pWakeByAddressSingle_t) (PVOID);
+typedef VOID (WINAPI *pWakeByAddressAll_t) (PVOID);
+
+extern pWaitOnAddress_t _pthread_wait_on_address;
+extern pWakeByAddressSingle_t _pthread_wake_by_address_single;
+extern pWakeByAddressAll_t _pthread_wake_by_address_all;
+
+#define pWaitOnAddress _pthread_wait_on_address
+#define pWakeByAddressSingle _pthread_wake_by_address_single
+#define pWakeByAddressAll _pthread_wake_by_address_all
+
typedef struct {
void *key;
void *value;
--
2.55.0.windows.5
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public