Skip to content

Commit 30d3c8c

Browse files
authored
Merge pull request #368 from dplanitzer/sys_queue_h_for_windows
added a sys/queue.h implementation for Windows
2 parents 84ac6ac + 858f0c5 commit 30d3c8c

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ if(UNIX)
6161
elseif(WIN32)
6262
target_sources(dispatch
6363
PRIVATE
64+
shims/generic_sys_queue.h
6465
shims/generic_win_stubs.c
6566
shims/generic_win_stubs.h)
6667
endif()

src/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
242242
#endif
243243

244244
#include <sys/stat.h>
245-
#include <sys/queue.h>
246245

247246
#if defined(_WIN32)
248247
#include <time.h>
249248
#else
249+
#include <sys/queue.h>
250250
#include <sys/mount.h>
251251
#ifdef __ANDROID__
252252
#include <linux/sysctl.h>

src/shims.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#endif
3333
#if defined(_WIN32)
3434
#include "shims/generic_win_stubs.h"
35+
#include "shims/generic_sys_queue.h"
3536
#elif defined(__unix__)
3637
#include "shims/generic_unix_stubs.h"
3738
#endif

src/shims/generic_sys_queue.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2018 Apple Inc. All rights reserved.
3+
*
4+
* @APPLE_APACHE_LICENSE_HEADER_START@
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @APPLE_APACHE_LICENSE_HEADER_END@
19+
*/
20+
21+
/*
22+
* NOTE: This header files defines a trimmed down version of the BSD sys/queue.h
23+
* macros for use on platforms which do not come with a sys/queue.h file.
24+
*/
25+
26+
#ifndef __DISPATCH_SHIMS_SYS_QUEUE__
27+
#define __DISPATCH_SHIMS_SYS_QUEUE__
28+
29+
#ifndef TRASHIT
30+
#define TRASHIT(elem) (elem) = NULL;
31+
#endif
32+
33+
#define TAILQ_HEAD(list_name, elem_type) \
34+
struct list_name { \
35+
struct elem_type *tq_first; \
36+
struct elem_type *tq_last; \
37+
}
38+
39+
#define TAILQ_ENTRY(elem_type) \
40+
struct { \
41+
struct elem_type *te_next; \
42+
struct elem_type *te_prev; \
43+
}
44+
45+
#define TAILQ_INIT(list) do { \
46+
(list)->tq_first = NULL; \
47+
(list)->tq_last = NULL; \
48+
} while (0)
49+
50+
#define TAILQ_EMPTY(list) ((list)->tq_first == NULL)
51+
52+
#define TAILQ_FIRST(list) ((list)->tq_first)
53+
54+
#define TAILQ_LAST(list) ((list)->tq_last)
55+
56+
#define TAILQ_NEXT(elem, field) ((elem)->field.te_next)
57+
58+
#define TAILQ_PREV(elem, list, field) ((elem)->field.te_prev)
59+
60+
#define TAILQ_FOREACH(var, list, field) \
61+
for ((var) = TAILQ_FIRST(list); \
62+
(var) != NULL; \
63+
(var) = TAILQ_NEXT(var, field))
64+
65+
#define TAILQ_FOREACH_SAFE(var, list, field, temp) \
66+
for ((var) = TAILQ_FIRST(list); \
67+
((var) != NULL) && (temp = TAILQ_NEXT(var, field), 1); \
68+
(var) = (temp))
69+
70+
#define TAILQ_REMOVE(list, elem, field) do { \
71+
if (TAILQ_NEXT(elem, field) != NULL) { \
72+
TAILQ_NEXT(elem, field)->field.te_prev = (elem)->field.te_prev; \
73+
} else { \
74+
(list)->tq_last = (elem)->field.te_prev; \
75+
} \
76+
if (TAILQ_PREV(elem, list, field) != NULL) { \
77+
TAILQ_PREV(elem, list, field)->field.te_next = (elem)->field.te_next; \
78+
} else { \
79+
(list)->tq_first = (elem)->field.te_next; \
80+
} \
81+
TRASHIT((elem)->field.te_next); \
82+
TRASHIT((elem)->field.te_prev); \
83+
} while(0)
84+
85+
#define TAILQ_INSERT_TAIL(list, elem, field) do { \
86+
if (TAILQ_EMPTY(list)) { \
87+
(list)->tq_first = (list)->tq_last = (elem); \
88+
(elem)->field.te_prev = (elem)->field.te_next = NULL; \
89+
} else { \
90+
(elem)->field.te_next = NULL; \
91+
(elem)->field.te_prev = (list)->tq_last; \
92+
TAILQ_LAST(list)->field.te_next = (elem); \
93+
(list)->tq_last = (elem); \
94+
} \
95+
} while(0)
96+
97+
#endif // __DISPATCH_SHIMS_SYS_QUEUE__

0 commit comments

Comments
 (0)