1 /* Implementation of threads compatibility routines for libgcc2. */
3 /* Copyright (C) 1999-2024 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 /* This module is separate from the rest of the implementation because it
27 references symbols in system libraries that are only available on Vista
28 and Server 2008 or later versions. */
30 /* Get the out-of-line version of the inline routines. */
32 #if _WIN32_WINNT < 0x0600
34 #define _WIN32_WINNT 0x0600
37 #define __GTHREAD_WIN32_COND_INLINE
39 #define __gthread_cond_init_function __gthr_win32_cond_init_function
40 #define __gthread_cond_broadcast __gthr_win32_cond_broadcast
41 #define __gthread_cond_signal __gthr_win32_cond_signal
42 #define __gthread_cond_wait __gthr_win32_cond_wait
43 #define __gthread_cond_timedwait __gthr_win32_cond_timedwait
45 #include "gthr-win32.h"
47 /* The number of 100-nanoseconds between 1/1/1601 and 1/1/1970. */
48 #define FILETIME_1970 116444736000000000ULL
50 /* The number of 100-nanoseconds per second. */
51 #define NSEC100_PER_SEC (1000000000ULL / 100)
53 /* The number of 100-nanoseconds per millisecond. */
54 #define NSEC100_PER_MSEC (NSEC100_PER_SEC / 1000)
56 /* The ceiling division of X by Y. */
57 #define CEIL_DIV(X, Y) (((X) + (Y) - 1) / (Y))
59 /* Convert absolute thread time to relative time in millisecond. */
62 __gthr_win32_abs_to_rel_time (const __gthread_time_t
*abs_time
)
68 ULONGLONG abs_time_nsec100
;
70 /* The Windows epoch is 1/1/1601 while the Unix epoch is 1/1/1970. */
71 GetSystemTimeAsFileTime (&now
.ft
);
72 now
.nsec100
-= FILETIME_1970
;
75 = (ULONGLONG
) abs_time
->tv_sec
* NSEC100_PER_SEC
76 + CEIL_DIV (abs_time
->tv_nsec
, 100);
78 if (abs_time_nsec100
< now
.nsec100
)
81 return (DWORD
) CEIL_DIV (abs_time_nsec100
- now
.nsec100
, NSEC100_PER_MSEC
);
84 /* Check the sizes of the local version of the Win32 types. */
86 #define CHECK_SIZE_OF(TYPE) \
87 typedef int assertion[sizeof(__gthr_win32_##TYPE) == sizeof(TYPE) ? 1 : -1];
89 CHECK_SIZE_OF (CONDITION_VARIABLE
)