diff options
author | Asiri Rathnayake <asiri.rathnayake@arm.com> | 2016-09-11 21:46:40 +0000 |
---|---|---|
committer | Asiri Rathnayake <asiri.rathnayake@arm.com> | 2016-09-11 21:46:40 +0000 |
commit | 8c2bf45da9d830c11dbc577330dfc958608dc78d (patch) | |
tree | 097f317afc053ca2e65db10b9cc6082c522cd32d /libcxx/test/support | |
parent | 958b699883f6e05e930fd4c40b3d1054839e5d1d (diff) | |
download | bcm5719-llvm-8c2bf45da9d830c11dbc577330dfc958608dc78d.tar.gz bcm5719-llvm-8c2bf45da9d830c11dbc577330dfc958608dc78d.zip |
[libcxx] Introduce an externally-threaded libc++ variant.
This patch further decouples libc++ from pthread, allowing libc++ to be built
against other threading systems. There are two main use cases:
- Building libc++ against a thread library other than pthreads.
- Building libc++ with an "external" thread API, allowing a separate library to
provide the implementation of that API.
The two use cases are quite similar, the second one being sligtly more
de-coupled than the first. The cmake option LIBCXX_HAS_EXTERNAL_THREAD_API
enables both kinds of builds. One needs to place an <__external_threading>
header file containing an implementation of the "libc++ thread API" declared
in the <__threading_support> header.
For the second use case, the implementation of the libc++ thread API can
delegate to a custom "external" thread API where the implementation of this
external API is provided in a seperate library. This mechanism allows toolchain
vendors to distribute a build of libc++ with a custom thread-porting-layer API
(which is the "external" API above), platform vendors (recipients of the
toolchain/libc++) are then required to provide their implementation of this API
to be linked with (end-user) C++ programs.
Note that the second use case still requires establishing the basic types that
get passed between the external thread library and the libc++ library
(e.g. __libcpp_mutex_t). These cannot be opaque pointer types (libc++ sources
won't compile otherwise). It should also be noted that the second use case can
have a slight performance penalty; as all the thread constructs need to cross a
library boundary through an additional function call.
When the header <__external_threading> is omitted, libc++ is built with the
"libc++ thread API" (declared in <__threading_support>) as the "external" thread
API (basic types are pthread based). An implementation (pthread based) of this
API is provided in test/support/external_threads.cpp, which is built into a
separate DSO and linked in when running the libc++ test suite. A test run
therefore demonstrates the second use case (less the intermediate custom API).
Differential revision: https://reviews.llvm.org/D21968
Reviewers: bcraig, compnerd, EricWF, mclow.lists
llvm-svn: 281179
Diffstat (limited to 'libcxx/test/support')
-rw-r--r-- | libcxx/test/support/external_threads.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libcxx/test/support/external_threads.cpp b/libcxx/test/support/external_threads.cpp new file mode 100644 index 00000000000..381ec651eef --- /dev/null +++ b/libcxx/test/support/external_threads.cpp @@ -0,0 +1,10 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#define _LIBCPP_BUILDING_EXTERNAL_THREADS +#include <__threading_support> |