Skip to content

Merge darwin/libdispatch-913.1.4 to master #289

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 47 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
851c040
update README and INSTALL for libpwq removal
dgrove-oss May 19, 2017
72c267b
Merge pull request #249 from dgrove-oss/update-docs
MadCoder May 19, 2017
bdcd753
clarify config of pthread_workqueue vs. internal_workqueue
dgrove-oss May 19, 2017
fba90ce
Merge pull request #248 from dgrove-oss/queue_config_cleanup
das May 25, 2017
bde13a1
Linux build fixes
das Jun 1, 2017
6c1c16a
Merge pull request #254 from apple/das-darwin-libdispatch-890-merge-m…
das Jun 2, 2017
f45ac22
attempt to fix autoconf ObjC runtime check
das Jun 4, 2017
0245dd4
Merge pull request #256 from apple/revert-255-revert-254-das-darwin-l…
das Jun 4, 2017
429caa2
[Overlay/Queue]Allow setting an optional value in setSpecific
springsup Sep 19, 2016
5b1738b
Merge pull request #172 from karwa/removespecific
das Jun 4, 2017
201f3c7
Convert dispatch_workq from legacy priorities to qos
dgrove-oss May 29, 2017
8b1e9e7
Merge pull request #253 from dgrove-oss/linux-qos-prioritty
das Jun 5, 2017
d015a75
Thread detach hook for Java JNI on Android
johnno1962 Jun 21, 2017
a1a808b
Merge pull request #259 from johnno1962a/master
MadCoder Jun 21, 2017
495ec35
build: use target_sources instead of custom lists
compnerd Jun 28, 2017
10890b7
build: support internal pthread workqueues in cmake
compnerd Jun 28, 2017
7cd8867
Merge pull request #260 from compnerd/cmake-parity
das Jun 28, 2017
f5e5230
build: create modulemap symlinks
compnerd Jun 28, 2017
66416c3
Merge pull request #261 from compnerd/module-maps
das Jun 28, 2017
5c3c3ce
build: add option to use the gold linker
compnerd Jun 28, 2017
2daa1d7
Merge pull request #262 from compnerd/gold
das Jun 28, 2017
4b45194
build: add dtrace USDT probe support
compnerd Jun 28, 2017
5f00fb0
Merge pull request #264 from compnerd/dtrace-usdt-probes
das Jun 29, 2017
90352b3
build: remove dead code
compnerd Jun 28, 2017
6acca8d
Merge pull request #266 from compnerd/pwq
das Jun 29, 2017
6fc4e18
pr_objc: Expose objc_retainAutoreleasedReturnValue()
spevans Jun 16, 2017
695e969
Merge pull request #258 from spevans/pr_expose_symbol
das Jun 30, 2017
1d62d26
CMake compatibility with Swift build assumptions
dgrove-oss Jun 29, 2017
edb6f9e
Merge pull request #267 from dgrove-oss/cmake-copy-libdisaptch
das Jul 1, 2017
9458512
Set CMake defaults to match autoconf Linux behavior.
dgrove-oss Jun 30, 2017
1d61b1e
Merge pull request #269 from dgrove-oss/cmake-default-args
das Jul 1, 2017
43b23fc
Fix warnings in DispatchQueue.sync() implementation when using a comp…
ktopley-apple Jun 29, 2017
422d736
Merge pull request #268 from ktopley-apple/dispatch-sync-fixup-overlay
das Jul 1, 2017
c015999
Remove dependency on sys_membarrier on linux
MadCoder Jul 13, 2017
176b846
Merge pull request #277 from apple/mad/remove-sys-membarrier
das Jul 14, 2017
b7a87c7
Actually update epoll events if needed when unregistering
jblache Jul 14, 2017
7bf2e83
Merge pull request #280 from apple/mad/epoll-fixes
MadCoder Jul 14, 2017
3015c51
the buffer size ioctls on linux return EINVAL when it's not supported
MadCoder Jul 14, 2017
cfdc94d
Merge pull request #281 from apple/mad/epoll-fixes-2
MadCoder Jul 17, 2017
6a54c47
Fix improper double-fire of signal sources on Linux
MadCoder Jul 14, 2017
8c5fde1
Merge pull request #279 from apple/mad/greedy-signalfd
das Jul 18, 2017
887ac1a
fixes for compiler warnings
dgrove-oss Jul 5, 2017
54651ca
Merge pull request #273 from dgrove-oss/match-darwin-cflags-round1
das Jul 24, 2017
1df729d
Merge libdispatch-913.1.4
das Jul 27, 2017
0acc011
merge darwin/libdispatch-913.1.4
das Jul 31, 2017
0eaaab6
fix linux build failure
das Aug 1, 2017
17c153a
better fix for provider.h
das Aug 1, 2017
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
21 changes: 21 additions & 0 deletions PATCHES
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,24 @@ github commits starting with 29bdc2f from
[5e8789e] APPLIED rdar://32283666
[3fba60a] APPLIED rdar://32283666
[d6eb245] APPLIED rdar://32283666
[0b6c22e] APPLIED rdar://33531111
[5a3c02a] APPLIED rdar://33531111
[22df1e7] APPLIED rdar://33531111
[21273de] APPLIED rdar://33531111
[dc1857c] APPLIED rdar://33531111
[56f36b6] APPLIED rdar://33531111
[c87c6bb] APPLIED rdar://33531111
[b791d23] APPLIED rdar://33531111
[c2d0c49] APPLIED rdar://33531111
[1d25040] APPLIED rdar://33531111
[ab89c6c] APPLIED rdar://33531111
[e591e7e] APPLIED rdar://33531111
[ded5bab] APPLIED rdar://33531111
[ce90d0c] APPLIED rdar://33531111
[69c8f3e] APPLIED rdar://33531111
[23a3a84] APPLIED rdar://33531111
[79b7529] APPLIED rdar://33531111
[f8e71eb] APPLIED rdar://33531111
[8947dcf] APPLIED rdar://33531111
[5ad9208] APPLIED rdar://33531111
[698d085] APPLIED rdar://33531111
2 changes: 1 addition & 1 deletion dispatch/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ dispatch_sync_f(dispatch_queue_t queue,
* @abstract
* Constant to pass to dispatch_apply() or dispatch_apply_f() to request that
* the system automatically use worker threads that match the configuration of
* the current thread most closely.
* the current thread as closely as possible.
*
* @discussion
* When submitting a block for parallel invocation, passing this constant as the
Expand Down
4 changes: 4 additions & 0 deletions libdispatch.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,12 @@
96DF70BD0F38FE3C0074BD99 /* once.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; lineEnding = 0; path = once.c; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.c; };
B63B793F1E8F004F0060C1E1 /* dispatch_no_blocks.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = dispatch_no_blocks.c; sourceTree = "<group>"; };
B68330BC1EBCF6080003E71C /* dispatch_wl.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = dispatch_wl.c; sourceTree = "<group>"; };
B69878521F06F8790088F94F /* dispatch_signals.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = dispatch_signals.c; sourceTree = "<group>"; };
B6AC73FD1EB10973009FB2F2 /* perf_thread_request.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = perf_thread_request.c; sourceTree = "<group>"; };
B6AE9A4A1D7F53B300AC007F /* dispatch_queue_create.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dispatch_queue_create.c; sourceTree = "<group>"; };
B6AE9A561D7F53C100AC007F /* perf_async_bench.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = perf_async_bench.m; sourceTree = "<group>"; };
B6AE9A581D7F53CB00AC007F /* perf_bench.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = perf_bench.m; sourceTree = "<group>"; };
B6FA01801F0AD522004479BF /* dispatch_pthread_root_queue.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = dispatch_pthread_root_queue.c; sourceTree = "<group>"; };
C00B0E0A1C5AEBBE000330B3 /* libdispatch_dyld_stub.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdispatch_dyld_stub.a; sourceTree = BUILT_PRODUCTS_DIR; };
C00B0E121C5AEBF7000330B3 /* libdispatch-dyld-stub.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "libdispatch-dyld-stub.xcconfig"; sourceTree = "<group>"; };
C01866BD1C5973210040FC07 /* libdispatch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdispatch.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -1060,6 +1062,7 @@
6E67D9151C1768B300FC98AC /* dispatch_pingpong.c */,
6E326B441C239B61002A6505 /* dispatch_priority.c */,
6E326AB51C225477002A6505 /* dispatch_proc.c */,
B6FA01801F0AD522004479BF /* dispatch_pthread_root_queue.c */,
6E326AB31C224870002A6505 /* dispatch_qos.c */,
B6AE9A4A1D7F53B300AC007F /* dispatch_queue_create.c */,
6E67D9111C17669C00FC98AC /* dispatch_queue_finalizer.c */,
Expand All @@ -1069,6 +1072,7 @@
6E326ADC1C234396002A6505 /* dispatch_readsync.c */,
6E8E4E6D1C1A35EE0004F5CC /* dispatch_select.c */,
6E8E4E9B1C1A4EF10004F5CC /* dispatch_sema.c */,
B69878521F06F8790088F94F /* dispatch_signals.c */,
6EA2CB841C005DEF0076794A /* dispatch_source.c */,
6E326AE01C234780002A6505 /* dispatch_starfish.c */,
6EE89F3D1BFAF5B000EB140D /* dispatch_state_machine.c */,
Expand Down
41 changes: 30 additions & 11 deletions man/dispatch_apply.3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Copyright (c) 2008-2010 Apple Inc. All rights reserved.
.\" Copyright (c) 2008-2017 Apple Inc. All rights reserved.
.Dd May 1, 2009
.Dt dispatch_apply 3
.Os Darwin
Expand All @@ -20,21 +20,32 @@ The
.Fn dispatch_apply
function provides data-level concurrency through a "for (;;)" loop like primitive:
.Bd -literal
dispatch_queue_t the_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
size_t iterations = 10;

// 'idx' is zero indexed, just like:
// for (idx = 0; idx < iterations; idx++)

dispatch_apply(iterations, the_queue, ^(size_t idx) {
dispatch_apply(iterations, DISPATCH_APPLY_AUTO, ^(size_t idx) {
printf("%zu\\n", idx);
});
.Ed
.Pp
Although any queue can be used, it is strongly recommended to use
.Vt DISPATCH_APPLY_AUTO
as the
.Vt queue
argument to both
.Fn dispatch_apply
and
.Fn dispatch_apply_f ,
as shown in the example above, since this allows the system to automatically use worker threads
that match the configuration of the current thread as closely as possible.
No assumptions should be made about which global concurrent queue will be used.
.Pp
Like a "for (;;)" loop, the
.Fn dispatch_apply
function is synchronous.
If asynchronous behavior is desired, please wrap the call to
If asynchronous behavior is desired, wrap the call to
.Fn dispatch_apply
with a call to
.Fn dispatch_async
Expand All @@ -49,7 +60,7 @@ achieved (perhaps using a power of two search):
.Bd -literal
#define STRIDE 3

dispatch_apply(count / STRIDE, queue, ^(size_t idx) {
dispatch_apply(count / STRIDE, DISPATCH_APPLY_AUTO, ^(size_t idx) {
size_t j = idx * STRIDE;
size_t j_stop = j + STRIDE;
do {
Expand All @@ -74,12 +85,21 @@ This is in contrast to asynchronous functions which must retain both the block
and target queue for the duration of the asynchronous operation (as the calling
function may immediately release its interest in these objects).
.Sh FUNDAMENTALS
Conceptually,
.Fn dispatch_apply
is a convenient wrapper around
and
.Fn dispatch_apply_f
attempt to quickly create enough worker threads to efficiently iterate work in parallel.
By contrast, a loop that passes work items individually to
.Fn dispatch_async
and a semaphore to wait for completion.
In practice, the dispatch library optimizes this function.
or
.Fn dispatch_async_f
will incur more overhead and does not express the desired parallel execution semantics to
the system, so may not create an optimal number of worker threads for a parallel workload.
For this reason, prefer to use
.Fn dispatch_apply
or
.Fn dispatch_apply_f
when parallel execution is important.
.Pp
The
.Fn dispatch_apply
Expand All @@ -99,5 +119,4 @@ use a for-loop around invocations of
.Sh SEE ALSO
.Xr dispatch 3 ,
.Xr dispatch_async 3 ,
.Xr dispatch_queue_create 3 ,
.Xr dispatch_semaphore_create 3
.Xr dispatch_queue_create 3
17 changes: 16 additions & 1 deletion os/voucher_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,23 @@ voucher_decrement_importance_count4CF(voucher_t _Nullable voucher);
* This flag is ignored if a specific voucher object is assigned with the
* dispatch_block_create_with_voucher* functions, and is equivalent to passing
* the NULL voucher to these functions.
*
* @const DISPATCH_BLOCK_IF_LAST_RESET_QUEUE_QOS_OVERRIDE
* Flag indicating that this dispatch block object should try to reset the
* recorded maximum QoS of all currently enqueued items on a serial dispatch
* queue at the base of a queue hierarchy.
*
* This is only works if the queue becomes empty by dequeuing the block in
* question, and then allows that block to enqueue more work on this hierarchy
* without perpetuating QoS overrides resulting from items previously executed
* on the hierarchy.
*
* A dispatch block object created with this flag set cannot be used with
* dispatch_block_wait() or dispatch_block_cancel().
*/
#define DISPATCH_BLOCK_NO_VOUCHER (0x40)
#define DISPATCH_BLOCK_NO_VOUCHER (0x40ul)

#define DISPATCH_BLOCK_IF_LAST_RESET_QUEUE_QOS_OVERRIDE (0x80ul)

/*!
* @function dispatch_block_create_with_voucher
Expand Down
3 changes: 3 additions & 0 deletions private/private.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#include <sys/cdefs.h>
#endif
#include <pthread.h>
#if TARGET_OS_MAC
#include <pthread/qos.h>
#endif

#ifndef __DISPATCH_BUILDING_DISPATCH__
#include <dispatch/dispatch.h>
Expand Down
16 changes: 16 additions & 0 deletions private/source_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ DISPATCH_SOURCE_TYPE_DECL(memorystatus);
API_AVAILABLE(macos(10.8), ios(6.0)) DISPATCH_LINUX_UNAVAILABLE()
DISPATCH_SOURCE_TYPE_DECL(sock);

/*!
* @const DISPATCH_SOURCE_TYPE_NW_CHANNEL
* @discussion A dispatch source that monitors events on a network channel.
*/
#define DISPATCH_SOURCE_TYPE_NW_CHANNEL (&_dispatch_source_type_nw_channel)
API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) DISPATCH_LINUX_UNAVAILABLE()
DISPATCH_SOURCE_TYPE_DECL(nw_channel);

__END_DECLS

Expand Down Expand Up @@ -165,6 +172,15 @@ enum {
DISPATCH_SOCK_NOTIFY_ACK = 0x00004000,
};

/*!
* @enum dispatch_source_nw_channel_flags_t
*
* @constant DISPATCH_NW_CHANNEL_FLOW_ADV_UPDATE
* Received network channel flow advisory.
*/
enum {
DISPATCH_NW_CHANNEL_FLOW_ADV_UPDATE = 0x00000001,
};

/*!
* @enum dispatch_source_vfs_flags_t
Expand Down
16 changes: 12 additions & 4 deletions src/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,23 @@ dispatch_apply_f(size_t iterations, dispatch_queue_t dq, void *ctxt,
if (unlikely(iterations == 0)) {
return;
}
int32_t thr_cnt = (int32_t)dispatch_hw_config(active_cpus);
dispatch_thread_context_t dtctxt =
_dispatch_thread_context_find(_dispatch_apply_key);
size_t nested = dtctxt ? dtctxt->dtc_apply_nesting : 0;
dispatch_queue_t old_dq = _dispatch_queue_get_current();

if (likely(dq == DISPATCH_APPLY_AUTO)) {
dq = _dispatch_apply_root_queue(old_dq);
}
dispatch_qos_t qos = _dispatch_priority_qos(dq->dq_priority);
if (unlikely(dq->do_targetq)) {
// if the queue passed-in is not a root queue, use the current QoS
// since the caller participates in the work anyway
qos = _dispatch_qos_from_pp(_dispatch_get_priority());
}
int32_t thr_cnt = (int32_t)_dispatch_qos_max_parallelism(qos,
DISPATCH_MAX_PARALLELISM_ACTIVE);

if (likely(!nested)) {
nested = iterations;
} else {
Expand All @@ -269,9 +280,6 @@ dispatch_apply_f(size_t iterations, dispatch_queue_t dq, void *ctxt,
if (iterations < (size_t)thr_cnt) {
thr_cnt = (int32_t)iterations;
}
if (likely(dq == DISPATCH_APPLY_AUTO)) {
dq = _dispatch_apply_root_queue(old_dq);
}
struct dispatch_continuation_s dc = {
.dc_func = (void*)func,
.dc_ctxt = ctxt,
Expand Down
24 changes: 24 additions & 0 deletions src/event/event_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@
#define DISPATCH_MACHPORT_DEBUG 0
#endif

#ifndef DISPATCH_TIMER_ASSERTIONS
#if DISPATCH_DEBUG
#define DISPATCH_TIMER_ASSERTIONS 1
#else
#define DISPATCH_TIMER_ASSERTIONS 0
#endif
#endif

#if DISPATCH_TIMER_ASSERTIONS
#define DISPATCH_TIMER_ASSERT(a, op, b, text) ({ \
typeof(a) _a = (a); \
if (unlikely(!(_a op (b)))) { \
DISPATCH_CLIENT_CRASH(_a, "Timer: " text); \
} \
})
#else
#define DISPATCH_TIMER_ASSERT(a, op, b, text) ((void)0)
#endif

#ifndef EV_VANISHED
#define EV_VANISHED 0x0200
#endif
Expand Down Expand Up @@ -105,6 +124,11 @@
# ifndef VQ_DESIRED_DISK
# undef HAVE_DECL_VQ_DESIRED_DISK
# endif // VQ_DESIRED_DISK

# if !defined(EVFILT_NW_CHANNEL) && defined(__APPLE__)
# define EVFILT_NW_CHANNEL (-16)
# define NOTE_FLOW_ADV_UPDATE 0x1
# endif
#else // DISPATCH_EVENT_BACKEND_KEVENT
# define EV_ADD 0x0001
# define EV_DELETE 0x0002
Expand Down
20 changes: 16 additions & 4 deletions src/event/event_kevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,9 @@ _dispatch_kq_drain(dispatch_wlh_t wlh, dispatch_kevent_t ke, int n,
r = 0;
} else if (flags & KEVENT_FLAG_ERROR_EVENTS) {
for (i = 0, r = 0; i < n; i++) {
if ((ke_out[i].flags & EV_ERROR) && (r = (int)ke_out[i].data)) {
if ((ke_out[i].flags & EV_ERROR) && ke_out[i].data) {
_dispatch_kevent_drain(&ke_out[i]);
r = (int)ke_out[i].data;
}
}
} else {
Expand Down Expand Up @@ -1407,6 +1408,17 @@ const dispatch_source_type_s _dispatch_source_type_sock = {
};
#endif // EVFILT_SOCK

#ifdef EVFILT_NW_CHANNEL
const dispatch_source_type_s _dispatch_source_type_nw_channel = {
.dst_kind = "nw_channel",
.dst_filter = EVFILT_NW_CHANNEL,
.dst_flags = DISPATCH_EV_DIRECT|EV_CLEAR|EV_VANISHED,
.dst_mask = NOTE_FLOW_ADV_UPDATE,
.dst_size = sizeof(struct dispatch_source_refs_s),
.dst_create = _dispatch_unote_create_with_fd,
.dst_merge_evt = _dispatch_source_merge_evt,
};
#endif // EVFILT_NW_CHANNEL

#if DISPATCH_USE_MEMORYSTATUS

Expand Down Expand Up @@ -1609,9 +1621,9 @@ _dispatch_mach_notify_source_invoke(mach_msg_header_t *hdr)
if (!tlr) {
DISPATCH_INTERNAL_CRASH(0, "message received without expected trailer");
}
if (tlr->msgh_audit.val[DISPATCH_MACH_AUDIT_TOKEN_PID] != 0) {
(void)dispatch_assume_zero(
tlr->msgh_audit.val[DISPATCH_MACH_AUDIT_TOKEN_PID]);
if (hdr->msgh_id <= MACH_NOTIFY_LAST
&& dispatch_assume_zero(tlr->msgh_audit.val[
DISPATCH_MACH_AUDIT_TOKEN_PID])) {
mach_msg_destroy(hdr);
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,7 @@ void
_dispatch_temporary_resource_shortage(void)
{
sleep(1);
asm(""); // prevent tailcall
}

void *
Expand Down
Loading