Skip to content

Merge darwin/trunk, including libdispatch-703.1.4 Apple source drop, to swift-3.0-branch #143

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 81 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
4d5eff0
Linux port of libdispatch-685 merge
dgrove-oss Jun 15, 2016
847f62b
Merge pull request #81 from dgrove-oss/linux-porting
MadCoder Jun 15, 2016
7f2a683
tweaks to preprocessor checks in libdispatch-685 Linux port
das Jun 23, 2016
10c9991
Avoid overwriting config.h with generated header
dgrove-oss Jun 17, 2016
7518545
Merge pull request #84 from dgrove-oss/gitignore_config.h
MadCoder Jun 18, 2016
31f1d2b
Eliminate dummy mach-specific functions from linux_stubs
dgrove-oss Jun 16, 2016
b11112d
Merge pull request #86 from dgrove-oss/kill_mach_task_self_on_linux
MadCoder Jun 18, 2016
b8cce96
TLS thread local storage refresh
frankeh Jun 16, 2016
c4f4e68
Merge pull request #82 from frankeh/TLS
MadCoder Jun 21, 2016
3e6e4b7
remove mach-specific thread_port macro that should not be used on linux
das Jun 23, 2016
c1f5e46
import Dispatch overlay and apinotes from swift-3.0-preview-2-branch …
das Jun 22, 2016
aee1fe5
add new overlay sourcefiles to Makefile.am (does not build)
das Jun 22, 2016
4af7cad
Merge pull request #89 from apple/das-swift3-overlay
MadCoder Jun 22, 2016
0de9c3c
Mark dispatch_source APIs that are not available on Linux as unavailable
dgrove-oss Jun 30, 2016
0c41eab
Merge pull request #96 from dgrove-oss/hide_evfilt_proc
MadCoder Jun 30, 2016
63b00aa
move DISPATCH_LINUX_UNAVAILABLE to base.h and match it with existing …
das Jul 14, 2016
05255f9
Initial Swift3 wrapping overlay for libdispatch
dgrove-oss Jun 28, 2016
acea647
Merge pull request #94 from dgrove-oss/swift3-overlay-pr1
mwwa Jul 1, 2016
c40d554
need to guard definition of _dispatch_data_destructor_munmap
das Jul 14, 2016
17b7382
avoid requiring __DISPATCH_BUILDING_SWIFT_MODULE__ macro on Linux
dgrove-oss Jul 5, 2016
47369eb
Merge pull request #97 from dgrove-oss/define-dispatch-bridging-macro…
MadCoder Jul 6, 2016
13dd2ef
missing #ifdef __has_feature
das Jul 14, 2016
f3fc317
release wrapped C objects when Swift object deinitialized
dgrove-oss Jul 5, 2016
c9c0aac
Merge pull request #98 from dgrove-oss/release-in-deinit
mwwa Jul 6, 2016
2ab938a
whitespace
das Jul 14, 2016
d3bb7e5
Linux: avoid zombie process when dispatch_main is called
dgrove-oss Jul 6, 2016
fc3a731
Merge pull request #99 from dgrove-oss/dispatch-main-zombie
MadCoder Jul 6, 2016
f3c6254
Update for SE-0112: ErrorProtocol has been renamed to Error
DougGregor Jul 12, 2016
3830f55
Merge pull request #103 from apple/nserror-bridging
DougGregor Jul 12, 2016
3bbed1b
whitespace
das Jul 14, 2016
989c9dd
Enable CF runloop support for linux
dgrove-oss Jul 7, 2016
56eb6b5
Merge pull request #101 from dgrove-oss/cf-runloop-hooks
das Jul 12, 2016
627df61
workaround CF build failure, add resolvers for new symbol, whitespace
das Jul 14, 2016
eff2273
Revert modulemaps changes from PR #94
das Jul 15, 2016
f3bfb6f
Merge libdispatch-703.1.4
das Jul 28, 2016
fa5d032
define SWIFT_CC(swift) macro for DispatchStubs
dgrove-oss Jul 15, 2016
d871b97
Merge pull request #106 from dgrove-oss/dispatch-stubs-fixme
MadCoder Jul 15, 2016
c16870e
cleanup: remove LINUX_PORT_HDD remnants from initial porting work
dgrove-oss Jul 15, 2016
2cfc71e
Merge pull request #107 from dgrove-oss/cleanup-hdd-remnants
MadCoder Jul 15, 2016
9b63963
autoconf support for selecting build variant
dgrove-oss Jul 19, 2016
927f394
Merge pull request #110 from dgrove-oss/build-variants
MadCoder Jul 19, 2016
b1bdd35
Add libkqueue as a git submodule to pick up kqueue fixes
seabaylea Jul 20, 2016
9128fb2
Merge pull request #109 from seabaylea/kqueue
MadCoder Jul 20, 2016
3088ec5
update libkqueue version to include PR-14 (kevent64 timer resolution …
dgrove-oss Jul 20, 2016
34df163
Merge pull request #112 from dgrove-oss/refresh-kqueue
MadCoder Jul 20, 2016
196c268
leverage of new kevent timer granularity functionality
frankeh Jul 20, 2016
afbcf85
Merge pull request #113 from frankeh/kevent_nsecs
MadCoder Jul 20, 2016
191a607
[Data] fix crash when creating iterator of empty DispatchData
springsup Jul 20, 2016
9e7cb39
Merge pull request #111 from karwa/master
mwwa Jul 20, 2016
4fd8252
deallocation support for DispatchData on Linux
dgrove-oss Jul 15, 2016
b31c464
Merge pull request #108 from dgrove-oss/data-destructor
mwwa Jul 21, 2016
5c303da
add dispatchMain to wrapping overlay
dgrove-oss Jul 11, 2016
89c4fe1
Merge pull request #102 from dgrove-oss/missing-dispatchMain
mwwa Jul 21, 2016
12bdffa
fix compilation error when building against old libkqueue
dgrove-oss Jul 21, 2016
6a37681
Merge pull request #114 from dgrove-oss/kevent-nsec-tweak
mwwa Jul 21, 2016
3776c2e
refresh libpwq submodule to include libpwq PR#14
dgrove-oss Jul 21, 2016
6c617c2
Merge pull request #115 from dgrove-oss/refresh-libpwq
MadCoder Jul 21, 2016
e6f5827
Update for SE-0107: Migrate Void->Raw.
atrick Jul 26, 2016
0939cb0
Merge pull request #120 from atrick/rawptr-void
atrick Jul 26, 2016
632ade4
[overlay-syncup] sync overlay changes to Linux
mwwa Jul 21, 2016
8a16704
UnsafeRawPointer fixes.
mwwa Jul 27, 2016
1493f94
Merge pull request #116 from mwwa/overlay-syncup
mwwa Jul 28, 2016
2aed5c6
Update INSTALL instructions
dgrove-oss Jul 28, 2016
cf8aae4
Merge pull request #123 from dgrove-oss/update-build-instructions
parkera Jul 28, 2016
f932a06
merge darwin/darwin-006
das Jul 29, 2016
7863301
Update libpwq for fix to race condition in libpwq's test_api
seabaylea Aug 4, 2016
758bb7f
Merge pull request #134 from seabaylea/pwq_api_test
MadCoder Aug 4, 2016
74b3743
disable dispatch_read2 due to intermittent failure
seabaylea Aug 4, 2016
f99215a
Merge pull request #135 from seabaylea/disable_read2
MadCoder Aug 4, 2016
b65aa22
SR-2309: embed BlocksRuntime in libdispatch to eliminate external dep…
dgrove-oss Aug 9, 2016
4c588e9
Merge pull request #139 from dgrove-oss/integrated-blocks-runtime
MadCoder Aug 10, 2016
310012a
Added Toolchain section in INSTALL.md
amraboelela Aug 9, 2016
1300d06
Merge pull request #138 from amraboelela/INSTALL
MadCoder Aug 10, 2016
5c17dd6
update INSTALL.md and README.md
dgrove-oss Aug 10, 2016
ae1f7e8
Merge pull request #140 from dgrove-oss/update-install-readme
MadCoder Aug 10, 2016
fe6a4bc
Merge branch 'swift-3.0-branch' into das-darwin-006-merge-swift-3.0-b…
das Aug 11, 2016
b5333f0
Merge branch 'master' into das-swift-3.0-branch-backport-134-135-139-…
das Aug 15, 2016
238daea
Merge branch 'das-swift-3.0-branch-backport-134-135-139-138-140' into…
das Aug 15, 2016
6ef4372
fixes for compilation/linking problems on linux
dgrove-oss Aug 12, 2016
754175e
xcode / autoconf plumbing to select module.modulemap file
dgrove-oss Aug 12, 2016
12e8a1b
ensure root_queues are initialized before main thread exits
dgrove-oss Aug 13, 2016
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ config
configure
libtool
.dirstamp
/dispatch/module.modulemap
/private/module.modulemap
114 changes: 70 additions & 44 deletions INSTALL → INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Grand Central Dispatch (GCD)
## Grand Central Dispatch (GCD)

GCD is a concurrent programming framework first shipped with Mac OS X Snow
Leopard. This package is an open source bundling of libdispatch, the core
Expand All @@ -8,7 +8,7 @@ Leopard and FreeBSD 9-CURRENT, are required to use libdispatch. Linux is
supported, but requires specific packages to be installed (see Linux
section at the end of the file). Other systems are currently unsupported.

I. Configuring and installing libdispatch (general comments)
### Configuring and installing libdispatch (general comments)

GCD is built using autoconf, automake, and libtool, and has a number of
compile-time configuration options that should be reviewed before starting.
Expand Down Expand Up @@ -41,59 +41,83 @@ Note that once libdispatch is installed into a Swift toolchain, that
toolchain cannot be used to compile libdispatch again (you must 'make uninstall'
libdispatch from the toolchain before using it to rebuild libdispatch).

II. Building and installing on OS X
You can also use the build-toolchain script to create a toolchain
that includes libdispatch on Linux:

1. Add libdispatch and install-libdispatch lines to ./swift/utils/build-presets.ini under `[preset: buildbot_linux]` section, as following:

```
[preset: buildbot_linux]
mixin-preset=mixin_linux_installation
build-subdir=buildbot_linux
lldb
release
test
validation-test
long-test
libdispatch
foundation
lit-args=-v
dash-dash

install-libdispatch
install-foundation
reconfigure
```

2. Run:

```
./swift/utils/build-toolchain local.swift
```

Note that adding libdispatch in build-presets.ini is for Linux only as Swift on macOS platforms uses the system installed libdispatch, so its not required.

### Building and installing on OS X

The following configure options may be of general interest:

--with-apple-libpthread-source
`--with-apple-libpthread-source`

Specify the path to Apple's libpthread package, so that appropriate headers
Specify the path to Apple's libpthread package, so that appropriate headers
can be found and used.

--with-apple-libplatform-source
`--with-apple-libplatform-source`

Specify the path to Apple's libplatform package, so that appropriate headers
Specify the path to Apple's libplatform package, so that appropriate headers
can be found and used.

--with-apple-libclosure-source
`--with-apple-libclosure-source`

Specify the path to Apple's Libclosure package, so that appropriate headers
Specify the path to Apple's Libclosure package, so that appropriate headers
can be found and used.

--with-apple-xnu-source
`--with-apple-xnu-source`

Specify the path to Apple's XNU package, so that appropriate headers can be
Specify the path to Apple's XNU package, so that appropriate headers can be
found and used.

--with-blocks-runtime
`--with-blocks-runtime`

On systems where -fblocks is supported, specify an additional library path
in which libBlocksRuntime can be found. This is not required on OS X,
where the Blocks runtime is included in libSystem, but is required on
FreeBSD.
On systems where -fblocks is supported, specify an additional library path in which libBlocksRuntime can be found. This is not required on OS X, where the Blocks runtime is included in libSystem, but is required on FreeBSD.

The following options are likely to only be useful when building libdispatch on
OS X as a replacement for /usr/lib/system/libdispatch.dylib:

--with-apple-objc4-source
`--with-apple-objc4-source`

Specify the path to Apple's objc4 package, so that appropriate headers can
Specify the path to Apple's objc4 package, so that appropriate headers can
be found and used.

--disable-libdispatch-init-constructor
`--disable-libdispatch-init-constructor`

Do not tag libdispatch's init routine as __constructor, in which case it
must be run manually before libdispatch routines can be called. This is the
default when building on OS X. For /usr/lib/system/libdispatch.dylib
the init routine is called automatically during process start.
Do not tag libdispatch's init routine as __constructor, in which case it must be run manually before libdispatch routines can be called. This is the default when building on OS X. For /usr/lib/system/libdispatch.dylib the init routine is called automatically during process start.

--enable-apple-tsd-optimizations
`--enable-apple-tsd-optimizations`

Use a non-portable allocation scheme for pthread per-thread data (TSD) keys
when building libdispatch for /usr/lib/system on OS X. This should not
be used on other OS's, or on OS X when building a stand-alone library.
Use a non-portable allocation scheme for pthread per-thread data (TSD) keys when building libdispatch for /usr/lib/system on OS X. This should not be used on other OS's, or on OS X when building a stand-alone library.

Typical configuration commands
#### Typical configuration commands

The following command lines create the configuration required to build
libdispatch for /usr/lib/system on OS X El Capitan:
Expand All @@ -112,7 +136,7 @@ libdispatch for /usr/lib/system on OS X El Capitan:
--with-apple-objc4-source=/path/to/10.11.0/objc4-680
make check

III. Building and installing for FreeBSD
### Building and installing for FreeBSD

Typical configuration line for FreeBSD 8.x and 9.x to build libdispatch with
clang and blocks support:
Expand All @@ -121,33 +145,35 @@ clang and blocks support:
./configure CC=clang --with-blocks-runtime=/usr/local/lib
make check

IV. Building and installing for Linux
### Building and installing for Linux

Note that libdispatch development and testing is done only
on Ubuntu; currently supported versions are 14.04, 15.10 and 16.04.

(1) The first thing to do is install required packages:
1a. Install build tools and clang compiler.
sudo apt-get install autoconf libtool pkg-config clang
1b. Install dtrace (to generate provider.h)
sudo apt-get install systemtap-sdt-dev
1c. Install additional libdispatch dependencies
sudo apt-get install libblocksruntime-dev libkqueue-dev libbsd-dev

Note: compiling libdispatch requires clang 3.8 or better and
1. The first thing to do is install required packages:

`sudo apt-get install autoconf libtool pkg-config clang systemtap-sdt-dev libbsd-dev`

Note: compiling libdispatch requires clang 3.8 or better and
the gold linker. If the default clang on your Ubuntu version is
too old, see http://apt.llvm.org/ to install a newer version.
On older Ubuntu releases, you may need to install binutils-gold
to get the gold linker.

(2) Initialize git submodules.
2. Initialize git submodules.
We are using git submodules to incorporate specific revisions of the
upstream pthread_workqueue and libkqueue projects into the build.

```
git submodule init
git submodule update
```

3. Build (as in the general instructions above)

(3) Build (as in the general instructions above)
sh autogen.sh
./configure
make
```
sh autogen.sh
./configure
make
make install
```
26 changes: 26 additions & 0 deletions PATCHES
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,29 @@ github commits starting with 29bdc2f from
[4a6ec51] APPLIED rdar://25159995
[bc16cc9] APPLIED rdar://25159995
[954ace4] APPLIED rdar://25159995
[5ea30b5] APPLIED rdar://26822213
[9f1e778] APPLIED rdar://26822213
[3339b81] APPLIED rdar://26822213
[4fa8d8d] APPLIED rdar://26822213
[e922531] APPLIED rdar://26822213
[195cbcf] APPLIED rdar://27303844
[5b893c8] APPLIED rdar://27303844
[92689ed] APPLIED rdar://27303844
[ecc14fa] APPLIED rdar://27303844
[2dbf83c] APPLIED rdar://27303844
[78b9e82] APPLIED rdar://27303844
[2c0e5ee] APPLIED rdar://27303844
[5ee237f] APPLIED rdar://27600964
[77299ec] APPLIED rdar://27600964
[57c5c28] APPLIED rdar://27600964
[f8423ec] APPLIED rdar://27600964
[325f73d] APPLIED rdar://27600964
[b84e87e] APPLIED rdar://27600964
[ae71a91] APPLIED rdar://27600964
[8669dea] APPLIED rdar://27600964
[a8d0327] APPLIED rdar://27600964
[2e4e6af] APPLIED rdar://27600964
[2457fb2] APPLIED rdar://27600964
[4d58038] APPLIED rdar://27600964
[98d0a05] APPLIED rdar://27600964
[8976101] APPLIED rdar://27600964
25 changes: 9 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ Grand Central Dispatch (GCD or libdispatch) provides comprehensive support for c

libdispatch is currently available on all Darwin platforms. This project aims to make a modern version of libdispatch available on all other Swift platforms. To do this, we will implement as much of the portable subset of the API as possible, using the existing open source C implementation.

## Project Goals

We are currently very early in the development of this project. Our starting point is simply a mirror of the open source drop that corresponds with OS X El Capitan (10.11). Therefore, our earliest goals are:

0. Build and test the C source code as a dynamic library on the current Swift Linux targets (Ubuntu 14.04 and Ubuntu 15.10).
0. Add a `module.modulemap` and make the libdispatch API importable into Swift.
0. After the previous two steps are done, consider possible improvements to the interface of the libdispatch API in Swift.
libdispatch on Darwin is a combination of logic in the `xnu` kernel alongside the user-space Library. The kernel has the most information available to balance workload across the entire system. As a first step, however, we believe it is useful to bring up the basic functionality of the library using user-space pthread primitives on Linux. Eventually, a Linux kernel module could be developed to support more informed thread scheduling.

## Building a C Library

libdispatch on Darwin is a combination of logic in the `xnu` kernel alongside the user-space Library. The kernel has the most information available to balance workload across the entire system. As a first step, however, we believe it is useful to bring up the basic functionality of the library using user-space pthread primitives on Linux.
## Project Goals

Our first tasks for this project are:
We are currently early in the development of this project. We began with a mirror of the open source drop that corresponds with OS X El Capitan (10.11) and have ported it to x86_64 Ubuntu 14.04 and 15.10. The next steps are:
1. Complete the work to adopt libdispatch in other Core Libraries projects, especially Foundation. This will validate our work and get immediate test coverage on basic functionality of the Swift API.
2. Include libdispatch and libdispatch-enabled Core Libraries in the Swift CI environment and the pre-built Swift toolchains at Swift.org.
4. Develop a test suite for the Swift APIs of libdispatch.
4. Enhance libdispatch as needed to support Swift language evolution and the needs of the other Core Libraries projects.

0. Adapt the current autotools build system to work on Linux, or develop a new makefile or other build script for the project on Linux. The current version of the build system has only been tested on Darwin, though previous versions have been made to work on FreeBSD and Linux (see INSTALL).
0. Omit as much of the extra functionality of the library as possible, to get a core version of the project building. Much of the OS X-specific functionality can be elided completely on Linux.
0. Adopt libdispatch in other Core Libraries projects, especially Foundation. This will validate our work and get immediate coverage on basic functionality.
0. Incrementally add functionality back in.
## Build and Install

Some C headers and sources (e.g. `Availability.h`, `Block.h`, and the libclosure `runtime.c`) are similar to ones embedded into the CoreFoundation part of [swift-corelibs-foundation](http://github.com/apple/swift-corelibs-foundation). We should figure out a mechanism to share these instead of duplicating them across projects.
For detailed instructions on building and installing libdispatch, see [INSTALL.md](INSTALL.md)
4 changes: 4 additions & 0 deletions config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
don't. */
#define HAVE_DECL_FD_COPY 1

/* Define to 1 if you have the declaration of `NOTE_LOWAT', and to 0 if you
don't. */
#define HAVE_DECL_NOTE_LOWAT 1

/* Define to 1 if you have the declaration of `NOTE_NONE', and to 0 if you
don't. */
#define HAVE_DECL_NOTE_NONE 1
Expand Down
18 changes: 16 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ AC_CHECK_FUNCS([mach_port_construct])
#
AC_CHECK_DECLS([CLOCK_UPTIME, CLOCK_MONOTONIC], [], [],
[[#include <time.h>]])
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL], [], [],
AC_CHECK_DECLS([NOTE_NONE, NOTE_REAP, NOTE_REVOKE, NOTE_SIGNAL, NOTE_LOWAT], [], [],
[[#include <sys/event.h>]])
AC_CHECK_DECLS([FD_COPY], [], [], [[#include <sys/select.h>]])
AC_CHECK_DECLS([SIGEMT], [], [], [[#include <signal.h>]])
Expand Down Expand Up @@ -432,6 +432,20 @@ AS_IF([test "x$have_mach" = "xtrue"], [
])
AM_CONDITIONAL(HAVE_DARWIN_LD, [test "x$dispatch_cv_ld_darwin" == "xyes"])

#
# symlink platform-specific module.modulemap files
#
AS_CASE([$target_os],
[darwin*], [ dispatch_module_map_os=darwin ],
[ dispatch_module_map_os=generic ]
)
AC_CONFIG_COMMANDS([modulemaps], [
ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/dispatch/module.modulemap
ln -fs $dispatch_module_map_os/module.modulemap $ac_top_srcdir/private/module.modulemap
],
[dispatch_module_map_os="$dispatch_module_map_os"]
)

#
# Temporary: some versions of clang do not mark __builtin_trap() as
# __attribute__((__noreturn__)). Detect and add if required.
Expand All @@ -449,6 +463,6 @@ AC_CONFIG_FILES([Makefile dispatch/Makefile man/Makefile os/Makefile private/Mak
#
# Generate testsuite links
#
AC_CONFIG_LINKS([tests/dispatch:$top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])
AC_CONFIG_LINKS([tests/dispatch:$ac_top_srcdir/private tests/leaks-wrapper:tests/leaks-wrapper.sh])

AC_OUTPUT
11 changes: 11 additions & 0 deletions dispatch/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#define DISPATCH_MALLOC __attribute__((__malloc__))
#define DISPATCH_ALWAYS_INLINE __attribute__((__always_inline__))
#define DISPATCH_UNAVAILABLE __attribute__((__unavailable__))
#define DISPATCH_UNAVAILABLE_MSG(msg) __attribute__((__unavailable__(msg)))
#else
/*! @parseOnly */
#define DISPATCH_NORETURN
Expand Down Expand Up @@ -99,6 +100,16 @@
#define DISPATCH_ALWAYS_INLINE
/*! @parseOnly */
#define DISPATCH_UNAVAILABLE
/*! @parseOnly */
#define DISPATCH_UNAVAILABLE_MSG(msg)
#endif

#ifdef __linux__
#define DISPATCH_LINUX_UNAVAILABLE() \
DISPATCH_UNAVAILABLE_MSG( \
"This interface is unavailable on linux systems")
#else
#define DISPATCH_LINUX_UNAVAILABLE()
#endif

#ifndef DISPATCH_ALIAS_V2
Expand Down
10 changes: 10 additions & 0 deletions dispatch/darwin/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Dispatch [system] [extern_c] {
umbrella header "dispatch.h"
module * { export * }
export *
}

module DispatchIntrospection [system] [extern_c] {
header "introspection.h"
export *
}
Loading