Skip to content

Commit e7ca00f

Browse files
committed
Merge pull request swiftlang#13 from KatashiMonosato/port-transform-and-use-libbsd
Port transform and use libbsd
2 parents b2ccfeb + b850646 commit e7ca00f

19 files changed

+72
-90
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ config.status
2828
config
2929
configure
3030
libtool
31-
31+
.dirstamp

INSTALL

+1-1
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

+8-1
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

-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ typedef void (*dispatch_mach_handler_function_t)(void*, dispatch_mach_reason_t,
7070

7171
typedef void (*dispatch_mach_msg_destructor_t)(void*);
7272

73-
typedef uint32_t voucher_activity_mode_t;
74-
7573
struct voucher_offsets_s {
7674
uint32_t vo_version;
7775
};

private/voucher_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ dispatch_queue_create_with_accounting_override_voucher(const char *label,
404404

405405
#ifdef __APPLE__
406406
#include <mach/mach.h>
407-
#endif
408407

409408
/*!
410409
* @function voucher_create_with_mach_msg
@@ -428,6 +427,7 @@ OS_VOUCHER_EXPORT OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT OS_NOTHROW
428427
voucher_t
429428
voucher_create_with_mach_msg(mach_msg_header_t *msg);
430429

430+
#endif
431431
__END_DECLS
432432

433433
#endif // __OS_VOUCHER_PRIVATE__

src/Makefile.am

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@ 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_LDFLAGS=-avoid-version
60-
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS)
61-
6259
if HAVE_PTHREAD_WORKQUEUES
6360
PTHREAD_WORKQUEUE_LIBS=-lpthread_workqueue
6461
endif
6562

63+
libdispatch_la_LDFLAGS=-avoid-version
64+
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS) $(BSD_OVERLAY_LIBS)
65+
6666
if HAVE_DARWIN_LD
6767
libdispatch_la_LDFLAGS+=-Wl,-compatibility_version,1 \
6868
-Wl,-current_version,$(VERSION) -Wl,-dead_strip \

src/allocator.c

+1-1
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/init.c

+4
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ DISPATCH_VTABLE_INSTANCE(source,
335335
.do_debug = _dispatch_source_debug,
336336
);
337337

338+
#if HAVE_MACH
338339
DISPATCH_VTABLE_INSTANCE(mach,
339340
.do_type = DISPATCH_MACH_CHANNEL_TYPE,
340341
.do_kind = "mach-channel",
@@ -351,6 +352,7 @@ DISPATCH_VTABLE_INSTANCE(mach_msg,
351352
.do_invoke = _dispatch_mach_msg_invoke,
352353
.do_debug = _dispatch_mach_msg_debug,
353354
);
355+
#endif
354356

355357
#if !USE_OBJC
356358
DISPATCH_VTABLE_INSTANCE(data,
@@ -793,6 +795,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
793795
_dispatch_set_unwind_tsd(u);
794796
}
795797

798+
#if HAVE_MACH
796799
#undef _dispatch_client_callout4
797800
void
798801
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -807,6 +810,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
807810
_dispatch_free_unwind_tsd();
808811
_dispatch_set_unwind_tsd(u);
809812
}
813+
#endif
810814

811815
#endif // DISPATCH_USE_CLIENT_CALLOUT
812816

src/inline_internal.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ DISPATCH_NOTHROW void
3838
_dispatch_client_callout(void *ctxt, dispatch_function_t f);
3939
DISPATCH_NOTHROW void
4040
_dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t));
41+
#if HAVE_MACH
4142
DISPATCH_NOTHROW void
4243
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
4344
dispatch_mach_msg_t dmsg, mach_error_t error,
4445
dispatch_mach_handler_function_t f);
46+
#endif
4547

4648
#else // !DISPATCH_USE_CLIENT_CALLOUT
4749

@@ -59,6 +61,7 @@ _dispatch_client_callout2(void *ctxt, size_t i, void (*f)(void *, size_t))
5961
return f(ctxt, i);
6062
}
6163

64+
#if HAVE_MACH
6265
DISPATCH_ALWAYS_INLINE
6366
static inline void
6467
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -67,6 +70,7 @@ _dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
6770
{
6871
return f(ctxt, reason, dmsg, error);
6972
}
73+
#endif
7074

7175
#endif // !DISPATCH_USE_CLIENT_CALLOUT
7276

src/internal.h

+1-5
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>
@@ -328,10 +324,10 @@ DISPATCH_NOINLINE
328324
void _dispatch_bug_client(const char* msg);
329325
DISPATCH_NOINLINE
330326
void _dispatch_bug_mach_client(const char *msg, mach_msg_return_t kr);
327+
#endif
331328
DISPATCH_NOINLINE
332329
void _dispatch_bug_kevent_client(const char* msg, const char* filter,
333330
const char *operation, int err);
334-
#endif
335331

336332
DISPATCH_NOINLINE DISPATCH_NORETURN
337333
void _dispatch_abort(size_t line, long val);

src/object.m

+2
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ - (NSString *)debugDescription {
524524
}
525525
}
526526

527+
#if HAVE_MACH
527528
#undef _dispatch_client_callout4
528529
void
529530
_dispatch_client_callout4(void *ctxt, dispatch_mach_reason_t reason,
@@ -537,6 +538,7 @@ - (NSString *)debugDescription {
537538
objc_terminate();
538539
}
539540
}
541+
#endif
540542

541543
#endif // DISPATCH_USE_CLIENT_CALLOUT
542544

src/queue.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
858858
thread_pool_size = pool_size;
859859
}
860860
qc->dgq_thread_pool_size = thread_pool_size;
861+
#if HAVE_PTHREAD_WORKQUEUES
861862
if (qc->dgq_qos) {
862863
(void)dispatch_assume_zero(pthread_attr_init(&pqc->dpq_thread_attr));
863864
(void)dispatch_assume_zero(pthread_attr_setdetachstate(
@@ -867,6 +868,7 @@ _dispatch_root_queue_init_pthread_pool(dispatch_root_queue_context_t qc,
867868
&pqc->dpq_thread_attr, qc->dgq_qos, 0));
868869
#endif
869870
}
871+
#endif
870872
#if USE_MACH_SEM
871873
// override the default FIFO behavior for the pool semaphores
872874
kern_return_t kr = semaphore_create(mach_task_self(),
@@ -1464,6 +1466,7 @@ static dispatch_once_t _dispatch_mgr_sched_pred;
14641466

14651467
// TODO: switch to "event-reflector thread" property <rdar://problem/18126138>
14661468

1469+
#if HAVE_PTHREAD_WORKQUEUE_QOS
14671470
// Must be kept in sync with list of qos classes in sys/qos.h
14681471
static const int _dispatch_mgr_sched_qos2prio[] = {
14691472
[_DISPATCH_QOS_CLASS_MAINTENANCE] = 4,
@@ -1473,6 +1476,7 @@ static const int _dispatch_mgr_sched_qos2prio[] = {
14731476
[_DISPATCH_QOS_CLASS_USER_INITIATED] = 37,
14741477
[_DISPATCH_QOS_CLASS_USER_INTERACTIVE] = 47,
14751478
};
1479+
#endif
14761480

14771481
static void
14781482
_dispatch_mgr_sched_init(void *ctxt DISPATCH_UNUSED)
@@ -4056,7 +4060,7 @@ _dispatch_queue_push_override(dispatch_queue_t dq, dispatch_queue_t tq,
40564060

40574061
_dispatch_queue_push(rq, dc, 0);
40584062
#else
4059-
(void)dq; (void)tq; (void)p;
4063+
(void)dq; (void)tq; (void)p; (void)owning;
40604064
#endif
40614065
}
40624066

src/shims/.dirstamp

Whitespace-only changes.

src/shims/hw_config.h

+10
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

+4-29
Original file line numberDiff line numberDiff line change
@@ -24,66 +24,41 @@
2424
*/
2525

2626
#include <stdint.h>
27-
27+
#include <syscall.h>
2828
#include <config/config.h>
2929

3030
#include "pthread.h"
31-
32-
#define program_invocation_short_name "hi"
33-
3431
#include "os/linux_base.h"
3532
#include "internal.h"
3633

3734

3835
#undef LINUX_PORT_ERROR
3936
#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); abort(); } while (0)
4037

41-
void _dispatch_mach_msg_dispose() { LINUX_PORT_ERROR(); }
42-
43-
unsigned long _dispatch_mach_probe(dispatch_mach_t dm) {
44-
LINUX_PORT_ERROR();
45-
}
46-
4738
dispatch_block_t _dispatch_block_create(dispatch_block_flags_t flags,
4839
voucher_t voucher, pthread_priority_t priority,
4940
dispatch_block_t block) {
5041
LINUX_PORT_ERROR();
5142
}
5243

53-
void _dispatch_mach_invoke() { LINUX_PORT_ERROR(); }
54-
55-
size_t _dispatch_mach_msg_debug(dispatch_mach_msg_t dmsg, char* buf, size_t bufsiz) {
56-
LINUX_PORT_ERROR();
57-
}
58-
void _dispatch_mach_dispose() { LINUX_PORT_ERROR(); }
59-
void _dispatch_mach_msg_invoke() { LINUX_PORT_ERROR(); }
60-
6144
unsigned long _dispatch_runloop_queue_probe(dispatch_queue_t dq) {
6245
LINUX_PORT_ERROR();
6346
}
6447
void _dispatch_runloop_queue_xref_dispose() { LINUX_PORT_ERROR(); }
6548

66-
void strlcpy() { LINUX_PORT_ERROR(); }
6749
void _dispatch_runloop_queue_dispose() { LINUX_PORT_ERROR(); }
6850
char* mach_error_string(mach_msg_return_t x) {
6951
LINUX_PORT_ERROR();
7052
}
71-
7253
void mach_vm_deallocate() { LINUX_PORT_ERROR(); }
7354

74-
mach_port_t pthread_mach_thread_np() {
75-
return (mach_port_t)pthread_self();
55+
mach_port_t pthread_mach_thread_np(void) {
56+
return (pid_t)syscall(SYS_gettid);
7657
}
77-
78-
mach_port_t mach_task_self() {
58+
mach_port_t mach_task_self(void) {
7959
return (mach_port_t)pthread_self();
8060
}
8161

82-
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
83-
void *newp, size_t newlen) {
84-
LINUX_PORT_ERROR();
85-
}
86-
8762
/*
8863
* Stubbed out static data
8964
*/

src/shims/linux_stubs.h

-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#ifndef __DISPATCH__STUBS__INTERNAL
2323
#define __DISPATCH__STUBS__INTERNAL
2424

25-
int sysctlbyname(const char *name, void *oldp, size_t *oldlenp,
26-
void *newp, size_t newlen);
27-
2825
mach_port_t pthread_mach_thread_np();
2926

3027
mach_port_t mach_task_self();

0 commit comments

Comments
 (0)