Skip to content

Commit 8b018c7

Browse files
committed
Merge 'gettickcount64' into HEAD
These two patches are really a fixup to PR #1004. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 7db5cb8 + 6857fe7 commit 8b018c7

File tree

3 files changed

+58
-38
lines changed

3 files changed

+58
-38
lines changed

compat/poll/poll.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,20 @@ win32_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
267267
return happened;
268268
}
269269

270+
#include <windows.h>
271+
#include "compat/win32/lazyload.h"
272+
273+
static ULONGLONG CompatGetTickCount64(void)
274+
{
275+
DECLARE_PROC_ADDR(kernel32.dll, ULONGLONG, GetTickCount64, void);
276+
277+
if (!INIT_PROC_ADDR(GetTickCount64))
278+
return (ULONGLONG)GetTickCount();
279+
280+
return GetTickCount64();
281+
}
282+
#define GetTickCount64 CompatGetTickCount64
283+
270284
#else /* !MinGW */
271285

272286
/* Convert select(2) returned fd_sets into poll(2) revents values. */

compat/win32.h

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <windows.h>
77
#endif
88

9+
#include "compat/win32/lazyload.h"
10+
911
static inline int file_attr_to_st_mode (DWORD attr, DWORD tag)
1012
{
1113
int fMode = S_IREAD;
@@ -40,42 +42,4 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd
4042
}
4143
}
4244

43-
/* simplify loading of DLL functions */
44-
45-
struct proc_addr {
46-
const char *const dll;
47-
const char *const function;
48-
FARPROC pfunction;
49-
unsigned initialized : 1;
50-
};
51-
52-
/* Declares a function to be loaded dynamically from a DLL. */
53-
#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \
54-
static struct proc_addr proc_addr_##function = \
55-
{ #dll, #function, NULL, 0 }; \
56-
static rettype (WINAPI *function)(__VA_ARGS__)
57-
58-
/*
59-
* Loads a function from a DLL (once-only).
60-
* Returns non-NULL function pointer on success.
61-
* Returns NULL + errno == ENOSYS on failure.
62-
*/
63-
#define INIT_PROC_ADDR(function) (function = get_proc_addr(&proc_addr_##function))
64-
65-
static inline void *get_proc_addr(struct proc_addr *proc)
66-
{
67-
/* only do this once */
68-
if (!proc->initialized) {
69-
HANDLE hnd;
70-
proc->initialized = 1;
71-
hnd = LoadLibraryA(proc->dll);
72-
if (hnd)
73-
proc->pfunction = GetProcAddress(hnd, proc->function);
74-
}
75-
/* set ENOSYS if DLL or function was not found */
76-
if (!proc->pfunction)
77-
errno = ENOSYS;
78-
return proc->pfunction;
79-
}
80-
8145
#endif

compat/win32/lazyload.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef LAZYLOAD_H
2+
#define LAZYLOAD_H
3+
4+
/* simplify loading of DLL functions */
5+
6+
struct proc_addr {
7+
const char *const dll;
8+
const char *const function;
9+
FARPROC pfunction;
10+
unsigned initialized : 1;
11+
};
12+
13+
/* Declares a function to be loaded dynamically from a DLL. */
14+
#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \
15+
static struct proc_addr proc_addr_##function = \
16+
{ #dll, #function, NULL, 0 }; \
17+
static rettype (WINAPI *function)(__VA_ARGS__)
18+
19+
/*
20+
* Loads a function from a DLL (once-only).
21+
* Returns non-NULL function pointer on success.
22+
* Returns NULL + errno == ENOSYS on failure.
23+
*/
24+
#define INIT_PROC_ADDR(function) (function = get_proc_addr(&proc_addr_##function))
25+
26+
static inline void *get_proc_addr(struct proc_addr *proc)
27+
{
28+
/* only do this once */
29+
if (!proc->initialized) {
30+
HANDLE hnd;
31+
proc->initialized = 1;
32+
hnd = LoadLibraryA(proc->dll);
33+
if (hnd)
34+
proc->pfunction = GetProcAddress(hnd, proc->function);
35+
}
36+
/* set ENOSYS if DLL or function was not found */
37+
if (!proc->pfunction)
38+
errno = ENOSYS;
39+
return proc->pfunction;
40+
}
41+
42+
#endif

0 commit comments

Comments
 (0)