Skip to content

Commit ab16f5e

Browse files
authored
Merge pull request swiftlang#142 from apple/das-darwin-006-merge-master
Merge darwin/trunk, including libdispatch-703.1.4 Apple source drop, to master
2 parents 57cdb0f + 40a9bfb commit ab16f5e

39 files changed

+603
-385
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ config
2929
configure
3030
libtool
3131
.dirstamp
32+
/dispatch/module.modulemap
33+
/private/module.modulemap

PATCHES

+26
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,29 @@ github commits starting with 29bdc2f from
241241
[4a6ec51] APPLIED rdar://25159995
242242
[bc16cc9] APPLIED rdar://25159995
243243
[954ace4] APPLIED rdar://25159995
244+
[5ea30b5] APPLIED rdar://26822213
245+
[9f1e778] APPLIED rdar://26822213
246+
[3339b81] APPLIED rdar://26822213
247+
[4fa8d8d] APPLIED rdar://26822213
248+
[e922531] APPLIED rdar://26822213
249+
[195cbcf] APPLIED rdar://27303844
250+
[5b893c8] APPLIED rdar://27303844
251+
[92689ed] APPLIED rdar://27303844
252+
[ecc14fa] APPLIED rdar://27303844
253+
[2dbf83c] APPLIED rdar://27303844
254+
[78b9e82] APPLIED rdar://27303844
255+
[2c0e5ee] APPLIED rdar://27303844
256+
[5ee237f] APPLIED rdar://27600964
257+
[77299ec] APPLIED rdar://27600964
258+
[57c5c28] APPLIED rdar://27600964
259+
[f8423ec] APPLIED rdar://27600964
260+
[325f73d] APPLIED rdar://27600964
261+
[b84e87e] APPLIED rdar://27600964
262+
[ae71a91] APPLIED rdar://27600964
263+
[8669dea] APPLIED rdar://27600964
264+
[a8d0327] APPLIED rdar://27600964
265+
[2e4e6af] APPLIED rdar://27600964
266+
[2457fb2] APPLIED rdar://27600964
267+
[4d58038] APPLIED rdar://27600964
268+
[98d0a05] APPLIED rdar://27600964
269+
[8976101] APPLIED rdar://27600964

config/config.h

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
don't. */
1414
#define HAVE_DECL_FD_COPY 1
1515

16+
/* Define to 1 if you have the declaration of `NOTE_LOWAT', and to 0 if you
17+
don't. */
18+
#define HAVE_DECL_NOTE_LOWAT 1
19+
1620
/* Define to 1 if you have the declaration of `NOTE_NONE', and to 0 if you
1721
don't. */
1822
#define HAVE_DECL_NOTE_NONE 1

configure.ac

+16-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ AC_CHECK_FUNCS([mach_port_construct])
353353
#
354354
AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
355355
[[#include <time.h>]])
356-
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL], [], [],
356+
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL, NOTE_LOWAT], [], [],
357357
[[#include <sys/event.h>]])
358358
AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
359359
AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
@@ -432,6 +432,20 @@ AS_IF([test "x$have_mach" = "xtrue"], [
432432
])
433433
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])
434434

435+
#
436+
# symlink platform-specific module.modulemap files
437+
#
438+
AS_CASE([$target_os],
439+
[darwin*], [ dispatch_module_map_os=darwin ],
440+
[ dispatch_module_map_os=generic ]
441+
)
442+
AC_CONFIG_COMMANDS([modulemaps], [
443+
ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/dispatch/module.modulemap
444+
ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/private/module.modulemap
445+
],
446+
[dispatch_module_map_os="$dispatch_module_map_os"]
447+
)
448+
435449
#
436450
# Temporary: some versions of clang do not mark __builtin_trap() as
437451
# __attribute__((__noreturn__)). Detect and add if required.
@@ -449,6 +463,6 @@ AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Mak
449463
#
450464
# Generate testsuite links
451465
#
452-
AC_CONFIG_LINKS([tests/dispatch:$top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])
466+
AC_CONFIG_LINKS([tests/dispatch:$ac_top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])
453467

454468
AC_OUTPUT

dispatch/base.h

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#define DISPATCH_MALLOC __attribute__((__malloc__))
6565
#define DISPATCH_ALWAYS_INLINE __attribute__((__always_inline__))
6666
#define DISPATCH_UNAVAILABLE __attribute__((__unavailable__))
67+
#define DISPATCH_UNAVAILABLE_MSG(msg) __attribute__((__unavailable__(msg)))
6768
#else
6869
/*! @parseOnly */
6970
#define DISPATCH_NORETURN
@@ -99,6 +100,16 @@
99100
#define DISPATCH_ALWAYS_INLINE
100101
/*! @parseOnly */
101102
#define DISPATCH_UNAVAILABLE
103+
/*! @parseOnly */
104+
#define DISPATCH_UNAVAILABLE_MSG(msg)
105+
#endif
106+
107+
#ifdef __linux__
108+
#define DISPATCH_LINUX_UNAVAILABLE() \
109+
DISPATCH_UNAVAILABLE_MSG( \
110+
"This interface is unavailable on linux systems")
111+
#else
112+
#define DISPATCH_LINUX_UNAVAILABLE()
102113
#endif
103114

104115
#ifndef DISPATCH_ALIAS_V2

dispatch/darwin/module.modulemap

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Dispatch [system] [extern_c] {
2+
umbrella header "dispatch.h"
3+
module * { export * }
4+
export *
5+
}
6+
7+
module DispatchIntrospection [system] [extern_c] {
8+
header "introspection.h"
9+
export *
10+
}

dispatch/dispatch.h

+16-51
Original file line numberDiff line numberDiff line change
@@ -24,71 +24,36 @@
2424
#ifdef __APPLE__
2525
#include <Availability.h>
2626
#include <TargetConditionals.h>
27-
#endif
28-
#include <sys/cdefs.h>
29-
#include <sys/types.h>
30-
#include <stddef.h>
31-
#include <stdint.h>
32-
#include <stdbool.h>
33-
#include <stdarg.h>
34-
#include <unistd.h>
35-
#include <fcntl.h>
36-
37-
#ifdef __has_attribute
38-
#if __has_attribute(unavailable)
39-
#define __DISPATCH_UNAVAILABLE(msg) __attribute__((__unavailable__(msg)))
40-
#endif
41-
#endif
42-
#ifndef __DISPATCH_UNAVAILABLE
43-
#define __DISPATCH_UNAVAILABLE(msg)
44-
#endif
45-
46-
#ifdef __linux__
47-
#if __has_feature(modules)
48-
#include <stdio.h> // for off_t (to match Glibc.modulemap)
49-
#endif
50-
#define DISPATCH_LINUX_UNAVAILABLE() \
51-
__DISPATCH_UNAVAILABLE("This interface is unavailable on linux systems")
5227
#else
53-
#define DISPATCH_LINUX_UNAVAILABLE()
54-
#endif
55-
56-
#ifndef __OSX_AVAILABLE_STARTING
5728
#define __OSX_AVAILABLE_STARTING(x, y)
58-
#endif
59-
#ifndef __OSX_AVAILABLE_BUT_DEPRECATED
6029
#define __OSX_AVAILABLE_BUT_DEPRECATED(...)
61-
#endif
62-
#ifndef __OSX_AVAILABLE_BUT_DEPRECATED_MSG
6330
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(...)
64-
#endif
65-
66-
#ifndef __OSX_AVAILABLE
6731
#define __OSX_AVAILABLE(...)
68-
#endif
69-
#ifndef __IOS_AVAILABLE
7032
#define __IOS_AVAILABLE(...)
71-
#endif
72-
#ifndef __TVOS_AVAILABLE
7333
#define __TVOS_AVAILABLE(...)
74-
#endif
75-
#ifndef __WATCHOS_AVAILABLE
7634
#define __WATCHOS_AVAILABLE(...)
77-
#endif
78-
#ifndef __OSX_DEPRECATED
7935
#define __OSX_DEPRECATED(...)
80-
#endif
81-
#ifndef __IOS_DEPRECATED
8236
#define __IOS_DEPRECATED(...)
83-
#endif
84-
#ifndef __TVOS_DEPRECATED
8537
#define __TVOS_DEPRECATED(...)
86-
#endif
87-
#ifndef __WATCHOS_DEPRECATED
8838
#define __WATCHOS_DEPRECATED(...)
39+
#endif // __APPLE__
40+
41+
#include <sys/cdefs.h>
42+
#include <sys/types.h>
43+
#include <stddef.h>
44+
#include <stdint.h>
45+
#include <stdbool.h>
46+
#include <stdarg.h>
47+
#include <unistd.h>
48+
#include <fcntl.h>
49+
50+
#if defined(__linux__) && defined(__has_feature)
51+
#if __has_feature(modules)
52+
#include <stdio.h> // for off_t (to match Glibc.modulemap)
53+
#endif
8954
#endif
9055

91-
#define DISPATCH_API_VERSION 20160612
56+
#define DISPATCH_API_VERSION 20160712
9257

9358
#ifndef __DISPATCH_BUILDING_DISPATCH__
9459

File renamed without changes.

dispatch/group.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ dispatch_group_async_f(dispatch_group_t group,
134134
* @discussion
135135
* This function waits for the completion of the blocks associated with the
136136
* given dispatch group, and returns after all blocks have completed or when
137-
* the specified timeout has elapsed. When a timeout occurs, the group is
138-
* restored to its original state.
137+
* the specified timeout has elapsed.
139138
*
140139
* This function will return immediately if there are no blocks associated
141140
* with the dispatch group (i.e. the group is empty).
@@ -262,7 +261,7 @@ dispatch_group_enter(dispatch_group_t group);
262261
*
263262
* @discussion
264263
* Calling this function indicates block has completed and left the dispatch
265-
* groupJ by a means other than dispatch_group_async().
264+
* group by a means other than dispatch_group_async().
266265
*
267266
* @param group
268267
* The dispatch group to update.

libdispatch.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@
662662
C01866BD1C5973210040FC07 /* libdispatch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libdispatch.a; sourceTree = BUILT_PRODUCTS_DIR; };
663663
C01866BE1C59735B0040FC07 /* libdispatch-mp-static.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "libdispatch-mp-static.xcconfig"; sourceTree = "<group>"; };
664664
C01866BF1C5976C90040FC07 /* run-on-install.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "run-on-install.sh"; sourceTree = "<group>"; };
665-
C901445E1C73A7FE002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
666-
C90144641C73A845002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = module.modulemap; sourceTree = "<group>"; };
665+
C901445E1C73A7FE002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = darwin/module.modulemap; sourceTree = "<group>"; };
666+
C90144641C73A845002638FC /* module.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = darwin/module.modulemap; sourceTree = "<group>"; };
667667
C913AC0E143BD34800B78976 /* data_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = data_private.h; sourceTree = "<group>"; tabWidth = 8; };
668668
C927F35F10FD7F1000C5AB8B /* ddt.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ddt.xcodeproj; path = tools/ddt/ddt.xcodeproj; sourceTree = "<group>"; };
669669
C96CE17A1CEB851600F4B8E6 /* dispatch_objc.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = dispatch_objc.m; sourceTree = "<group>"; };

man/dispatch_source_create.3

+6-5
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ Sources of this type allow applications to manually trigger the source's event
271271
handler via a call to
272272
.Fn dispatch_source_merge_data .
273273
The data will be merged with the source's pending data via an atomic add or
274-
logic OR (based on the source's type), and the event handler block will be
275-
submitted to the source's target queue. The
274+
atomic bitwise OR (based on the source's type), and the event handler block will
275+
be submitted to the source's target queue. The
276276
.Fa data
277277
is application defined. These sources have no
278278
.Fa handle
@@ -297,7 +297,8 @@ The data returned by
297297
.Fn dispatch_source_get_data
298298
indicates which of the events in the
299299
.Fa mask
300-
were observed. Note that because this source type will request notifications on the provided port, it should not be mixed with the use of
300+
were observed. Note that because this source type will request notifications on
301+
the provided port, it should not be mixed with the use of
301302
.Fn mach_port_request_notification
302303
on the same port.
303304
.Pp
@@ -314,8 +315,8 @@ on the mach port is waiting to be received.
314315
.Pp
315316
.Vt DISPATCH_SOURCE_TYPE_MEMORYPRESSURE
316317
.Pp
317-
Sources of this type monitor the system memory pressure condition for state changes.
318-
The
318+
Sources of this type monitor the system memory pressure condition for state
319+
changes. The
319320
.Fa handle
320321
is unused and should be zero. The
321322
.Fa mask

os/firehose_buffer_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef struct firehose_buffer_chunk_s {
6969
uint8_t fbc_data[FIREHOSE_BUFFER_CHUNK_SIZE
7070
- sizeof(firehose_buffer_pos_u)
7171
- sizeof(uint64_t)];
72-
} *firehose_buffer_chunk_t;
72+
} __attribute__((aligned(8))) *firehose_buffer_chunk_t;
7373

7474
typedef struct firehose_buffer_range_s {
7575
uint16_t fbr_offset; // offset from the start of the buffer
File renamed without changes.

private/generic/module.modulemap

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module DispatchPrivate [system] [extern_c] {
2+
umbrella header "private.h"
3+
exclude header "mach_private.h"
4+
module * { export * }
5+
export *
6+
}
7+
8+
module DispatchIntrospectionPrivate [system] [extern_c] {
9+
header "introspection_private.h"
10+
export *
11+
}

private/private.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
#endif /* !__DISPATCH_BUILDING_DISPATCH__ */
6767

6868
// <rdar://problem/9627726> Check that public and private dispatch headers match
69-
#if DISPATCH_API_VERSION != 20160612 // Keep in sync with <dispatch/dispatch.h>
69+
#if DISPATCH_API_VERSION != 20160712 // Keep in sync with <dispatch/dispatch.h>
7070
#error "Dispatch header mismatch between /usr/include and /usr/local/include"
7171
#endif
7272

@@ -199,10 +199,17 @@ DISPATCH_EXPORT DISPATCH_NOTHROW
199199
dispatch_runloop_handle_t
200200
_dispatch_get_main_queue_handle_4CF(void);
201201

202+
#if TARGET_OS_MAC
203+
__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
204+
DISPATCH_EXPORT DISPATCH_NOTHROW
205+
void
206+
_dispatch_main_queue_callback_4CF(mach_msg_header_t *_Null_unspecified msg);
207+
#else
202208
__OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0)
203209
DISPATCH_EXPORT DISPATCH_NOTHROW
204210
void
205211
_dispatch_main_queue_callback_4CF(void *_Null_unspecified msg);
212+
#endif
206213

207214
__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)
208215
DISPATCH_EXPORT DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT

private/queue_private.h

+17
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ dispatch_pthread_root_queue_flags_pool_size(uint8_t pool_size)
227227

228228
#endif /* __BLOCKS__ */
229229

230+
/*!
231+
* @function dispatch_pthread_root_queue_copy_current
232+
*
233+
* @abstract
234+
* Returns a reference to the pthread root queue object that has created the
235+
* currently executing thread, or NULL if the current thread is not associated
236+
* to a pthread root queue.
237+
*
238+
* @result
239+
* A new reference to a pthread root queue object or NULL.
240+
*/
241+
__OSX_AVAILABLE(10.12) __IOS_AVAILABLE(10.0)
242+
__TVOS_AVAILABLE(10.0) __WATCHOS_AVAILABLE(3.0)
243+
DISPATCH_EXPORT DISPATCH_RETURNS_RETAINED DISPATCH_WARN_RESULT DISPATCH_NOTHROW
244+
dispatch_queue_t _Nullable
245+
dispatch_pthread_root_queue_copy_current(void);
246+
230247
/*!
231248
* @constant DISPATCH_APPLY_CURRENT_ROOT_QUEUE
232249
* @discussion Constant to pass to the dispatch_apply() and dispatch_apply_f()

src/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ if BUILD_OWN_BLOCKS_RUNTIME
8787
libdispatch_la_SOURCES+= BlocksRuntime/data.c BlocksRuntime/runtime.c
8888
CBLOCKS_FLAGS+= -I$(top_srcdir)/src/BlocksRuntime
8989
CXXBLOCKS_FLAGS+= -I$(top_srcdir)/src/BlocksRuntime
90+
BLOCKS_RUNTIME_LIBS=-ldl
9091
endif
9192

9293
libdispatch_la_LDFLAGS=-avoid-version
93-
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS) $(BSD_OVERLAY_LIBS)
94+
libdispatch_la_LIBADD=$(KQUEUE_LIBS) $(PTHREAD_WORKQUEUE_LIBS) $(BSD_OVERLAY_LIBS) $(BLOCKS_RUNTIME_LIBS)
9495

9596
if HAVE_DARWIN_LD
9697
libdispatch_la_LDFLAGS+=-Wl,-compatibility_version,1 \

src/apply.c

+11
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ _dispatch_apply_invoke2(void *ctxt, long invoke_flags)
8787
_dispatch_thread_event_destroy(&da->da_event);
8888
}
8989
if (os_atomic_dec2o(da, da_thr_cnt, release) == 0) {
90+
#if DISPATCH_INTROSPECTION
91+
_dispatch_continuation_free(da->da_dc);
92+
#endif
9093
_dispatch_continuation_free((dispatch_continuation_t)da);
9194
}
9295
}
@@ -145,6 +148,9 @@ _dispatch_apply_serial(void *ctxt)
145148
});
146149
} while (++idx < iter);
147150

151+
#if DISPATCH_INTROSPECTION
152+
_dispatch_continuation_free(da->da_dc);
153+
#endif
148154
_dispatch_continuation_free((dispatch_continuation_t)da);
149155
}
150156

@@ -262,7 +268,12 @@ dispatch_apply_f(size_t iterations, dispatch_queue_t dq, void *ctxt,
262268
da->da_iterations = iterations;
263269
da->da_nested = nested;
264270
da->da_thr_cnt = thr_cnt;
271+
#if DISPATCH_INTROSPECTION
272+
da->da_dc = _dispatch_continuation_alloc();
273+
*da->da_dc = dc;
274+
#else
265275
da->da_dc = &dc;
276+
#endif
266277
da->da_flags = 0;
267278

268279
if (slowpath(dq->dq_width == 1) || slowpath(thr_cnt <= 1)) {

0 commit comments

Comments
 (0)