Skip to content

Commit 91fb699

Browse files
KatashiMonosatodas
authored andcommitted
Linux has libbsd which provides an overlay that has all we need
Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent bc937d3 commit 91fb699

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

INSTALL

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Prepare your system
109109
2. Install dtrace (to generate provider.h)
110110
sudo apt-get install systemtap-sdt-dev
111111
3. Install libdispatch pre-reqs
112-
sudo apt-get install libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev
112+
sudo apt-get install libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev libbsd-dev
113113

114114
Build:
115115
sh autogen.sh

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ AC_CHECK_HEADER(sys/event.h, [],
140140
[PKG_CHECK_MODULES(KQUEUE, libkqueue)]
141141
)
142142

143+
AC_CHECK_FUNCS([strlcpy getprogname], [],
144+
[PKG_CHECK_MODULES(BSD_OVERLAY, libbsd-overlay,[
145+
AC_DEFINE(HAVE_STRLCPY, 1, [])
146+
AC_DEFINE(HAVE_GETPROGNAME, 1, [])
147+
])], [#include <string.h>]
148+
)
149+
143150
#
144151
# Checks for header files.
145152
#
@@ -241,7 +248,7 @@ AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
241248
AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
242249
AC_CHECK_DECLS([VQ_UPDATE, VQ_VERYLOWDISK], [], [], [[#include <sys/mount.h>]])
243250
AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
244-
AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf getprogname])
251+
AC_CHECK_FUNCS([pthread_key_init_np pthread_main_np mach_absolute_time malloc_create_zone sysconf])
245252

246253
AC_CHECK_DECLS([POSIX_SPAWN_START_SUSPENDED],
247254
[have_posix_spawn_start_suspended=true], [have_posix_spawn_start_suspended=false],

os/linux_base.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
6464

6565
typedef void (*dispatch_mach_msg_destructor_t)(void*);
6666

67-
typedef uint32_t voucher_activity_mode_t;
68-
6967
struct voucher_offsets_s {
7068
uint32_t vo_version;
7169
};

src/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ AM_CPPFLAGS=-I$(top_builddir) -I$(top_srcdir) \
5050
-I$(top_srcdir)/private -I$(top_srcdir)/os
5151

5252
DISPATCH_CFLAGS=-Wall $(VISIBILITY_FLAGS) $(OMIT_LEAF_FP_FLAGS) \
53-
$(MARCH_FLAGS) $(KQUEUE_CFLAGS)
53+
$(MARCH_FLAGS) $(KQUEUE_CFLAGS) $(BSD_OVERLAY_CFLAGS)
5454
AM_CFLAGS=$(DISPATCH_CFLAGS) $(CBLOCKS_FLAGS)
5555
AM_OBJCFLAGS=$(DISPATCH_CFLAGS) $(CBLOCKS_FLAGS)
5656
AM_CXXFLAGS=$(DISPATCH_CFLAGS) $(CXXBLOCKS_FLAGS)
5757
AM_OBJCXXFLAGS=$(DISPATCH_CFLAGS) $(CXXBLOCKS_FLAGS)
5858

59+
libdispatch_la_LIBADD = $(BSD_OVERLAY_LIBS)
5960
libdispatch_la_LDFLAGS=-avoid-version
6061
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS)
6162

src/allocator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ _dispatch_malloc_init(void)
676676
malloc_set_zone_name(_dispatch_ccache_zone, "DispatchContinuations");
677677
}
678678
#else
679-
static inline void _dispatch_malloc_init(void) {}
679+
#define _dispatch_malloc_init() ((void)0)
680680
#endif // DISPATCH_USE_MALLOCZONE
681681

682682
static dispatch_continuation_t

src/internal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ DISPATCH_EXPORT DISPATCH_NOTHROW void dispatch_atfork_child(void);
208208
#if !TARGET_OS_WIN32
209209
#include <sys/event.h>
210210
#include <sys/mount.h>
211-
#ifdef __linux__
212-
#include <shims/sys_queue.h>
213-
#else
214211
#include <sys/queue.h>
215-
#endif
216212
#include <sys/sysctl.h>
217213
#include <sys/socket.h>
218214
#include <sys/time.h>

src/shims/hw_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ static inline uint32_t
8181
_dispatch_hw_get_config(_dispatch_hw_config_t c)
8282
{
8383
uint32_t val = 1;
84+
#if defined(__linux__)
85+
switch (c) {
86+
case _dispatch_hw_config_logical_cpus:
87+
case _dispatch_hw_config_physical_cpus:
88+
return sysconf(_SC_NPROCESSORS_CONF);
89+
case _dispatch_hw_config_active_cpus:
90+
return sysconf(_SC_NPROCESSORS_ONLN);
91+
}
92+
#else
8493
const char *name = NULL;
8594
int r;
8695
#if defined(__APPLE__)
@@ -106,6 +115,7 @@ _dispatch_hw_get_config(_dispatch_hw_config_t c)
106115
if (r > 0) val = (uint32_t)r;
107116
#endif
108117
}
118+
#endif
109119
return val;
110120
}
111121

src/shims/linux_stubs.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
#include <config/config.h>
2222

2323
#include "pthread.h"
24-
25-
#define program_invocation_short_name "hi"
26-
2724
#include "os/linux_base.h"
2825
#include "internal.h"
2926

@@ -56,7 +53,6 @@ unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
5653
}
5754
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }
5855

59-
void strlcpy() { LINUX_PORT_ERROR(); }
6056
void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
6157
char* mach_error_string(mach_msg_return_t x) {
6258
LINUX_PORT_ERROR();
@@ -72,11 +68,6 @@ mach_port_t mach_task_self() {
7268
return (mach_port_t)pthread_self();
7369
}
7470

75-
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
76-
void *newp, size_t newlen) {
77-
LINUX_PORT_ERROR();
78-
}
79-
8071
/*
8172
* Stubbed out static data
8273
*/

src/shims/linux_stubs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#ifndef __DISPATCH__STUBS__INTERNAL
1717
#define __DISPATCH__STUBS__INTERNAL
1818

19-
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
20-
void *newp, size_t newlen);
21-
2219
mach_port_t pthread_mach_thread_np();
2320

2421
mach_port_t mach_task_self();

0 commit comments

Comments
 (0)