Skip to content

added a sys/queue.h implementation for Windows #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if(UNIX)
elseif(WIN32)
target_sources(dispatch
PRIVATE
shims/generic_sys_queue.h
shims/generic_win_stubs.c
shims/generic_win_stubs.h)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
#endif

#include <sys/stat.h>
#include <sys/queue.h>

#if defined(_WIN32)
#include <time.h>
#else
#include <sys/queue.h>
#include <sys/mount.h>
#ifdef __ANDROID__
#include <linux/sysctl.h>
Expand Down
1 change: 1 addition & 0 deletions src/shims.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#endif
#if defined(_WIN32)
#include "shims/generic_win_stubs.h"
#include "shims/generic_sys_queue.h"
#elif defined(__unix__)
#include "shims/generic_unix_stubs.h"
#endif
Expand Down
97 changes: 97 additions & 0 deletions src/shims/generic_sys_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (c) 2018 Apple Inc. All rights reserved.
*
* @APPLE_APACHE_LICENSE_HEADER_START@
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @APPLE_APACHE_LICENSE_HEADER_END@
*/

/*
* NOTE: This header files defines a trimmed down version of the BSD sys/queue.h
* macros for use on platforms which do not come with a sys/queue.h file.
*/

#ifndef __DISPATCH_SHIMS_SYS_QUEUE__
#define __DISPATCH_SHIMS_SYS_QUEUE__

#ifndef TRASHIT
#define TRASHIT(elem) (elem) = NULL;
#endif

#define TAILQ_HEAD(list_name, elem_type) \
struct list_name { \
struct elem_type *tq_first; \
struct elem_type *tq_last; \
}

#define TAILQ_ENTRY(elem_type) \
struct { \
struct elem_type *te_next; \
struct elem_type *te_prev; \
}

#define TAILQ_INIT(list) do { \
(list)->tq_first = NULL; \
(list)->tq_last = NULL; \
} while (0)

#define TAILQ_EMPTY(list) ((list)->tq_first == NULL)

#define TAILQ_FIRST(list) ((list)->tq_first)

#define TAILQ_LAST(list) ((list)->tq_last)

#define TAILQ_NEXT(elem, field) ((elem)->field.te_next)

#define TAILQ_PREV(elem, list, field) ((elem)->field.te_prev)

#define TAILQ_FOREACH(var, list, field) \
for ((var) = TAILQ_FIRST(list); \
(var) != NULL; \
(var) = TAILQ_NEXT(var, field))

#define TAILQ_FOREACH_SAFE(var, list, field, temp) \
for ((var) = TAILQ_FIRST(list); \
((var) != NULL) && (temp = TAILQ_NEXT(var, field), 1); \
(var) = (temp))

#define TAILQ_REMOVE(list, elem, field) do { \
if (TAILQ_NEXT(elem, field) != NULL) { \
TAILQ_NEXT(elem, field)->field.te_prev = (elem)->field.te_prev; \
} else { \
(list)->tq_last = (elem)->field.te_prev; \
} \
if (TAILQ_PREV(elem, list, field) != NULL) { \
TAILQ_PREV(elem, list, field)->field.te_next = (elem)->field.te_next; \
} else { \
(list)->tq_first = (elem)->field.te_next; \
} \
TRASHIT((elem)->field.te_next); \
TRASHIT((elem)->field.te_prev); \
} while(0)

#define TAILQ_INSERT_TAIL(list, elem, field) do { \
if (TAILQ_EMPTY(list)) { \
(list)->tq_first = (list)->tq_last = (elem); \
(elem)->field.te_prev = (elem)->field.te_next = NULL; \
} else { \
(elem)->field.te_next = NULL; \
(elem)->field.te_prev = (list)->tq_last; \
TAILQ_LAST(list)->field.te_next = (elem); \
(list)->tq_last = (elem); \
} \
} while(0)

#endif // __DISPATCH_SHIMS_SYS_QUEUE__