1*58b9f456SAndroid Build Coastguard Worker===================== 2*58b9f456SAndroid Build Coastguard WorkerThreading Support API 3*58b9f456SAndroid Build Coastguard Worker===================== 4*58b9f456SAndroid Build Coastguard Worker 5*58b9f456SAndroid Build Coastguard Worker.. contents:: 6*58b9f456SAndroid Build Coastguard Worker :local: 7*58b9f456SAndroid Build Coastguard Worker 8*58b9f456SAndroid Build Coastguard WorkerOverview 9*58b9f456SAndroid Build Coastguard Worker======== 10*58b9f456SAndroid Build Coastguard Worker 11*58b9f456SAndroid Build Coastguard WorkerLibc++ supports using multiple different threading models and configurations 12*58b9f456SAndroid Build Coastguard Workerto implement the threading parts of libc++, including ``<thread>`` and ``<mutex>``. 13*58b9f456SAndroid Build Coastguard WorkerThese different models provide entirely different interfaces from each 14*58b9f456SAndroid Build Coastguard Workerother. To address this libc++ wraps the underlying threading API in a new and 15*58b9f456SAndroid Build Coastguard Workerconsistent API, which it uses internally to implement threading primitives. 16*58b9f456SAndroid Build Coastguard Worker 17*58b9f456SAndroid Build Coastguard WorkerThe ``<__threading_support>`` header is where libc++ defines its internal 18*58b9f456SAndroid Build Coastguard Workerthreading interface. It contains forward declarations of the internal threading 19*58b9f456SAndroid Build Coastguard Workerinterface as well as definitions for the interface. 20*58b9f456SAndroid Build Coastguard Worker 21*58b9f456SAndroid Build Coastguard WorkerExternal Threading API and the ``<__external_threading>`` header 22*58b9f456SAndroid Build Coastguard Worker================================================================ 23*58b9f456SAndroid Build Coastguard Worker 24*58b9f456SAndroid Build Coastguard WorkerIn order to support vendors with custom threading API's libc++ allows the 25*58b9f456SAndroid Build Coastguard Workerentire internal threading interface to be provided by an external, 26*58b9f456SAndroid Build Coastguard Workervendor provided, header. 27*58b9f456SAndroid Build Coastguard Worker 28*58b9f456SAndroid Build Coastguard WorkerWhen ``_LIBCPP_HAS_THREAD_API_EXTERNAL`` is defined the ``<__threading_support>`` 29*58b9f456SAndroid Build Coastguard Workerheader simply forwards to the ``<__external_threading>`` header (which must exist). 30*58b9f456SAndroid Build Coastguard WorkerIt is expected that the ``<__external_threading>`` header provide the exact 31*58b9f456SAndroid Build Coastguard Workerinterface normally provided by ``<__threading_support>``. 32*58b9f456SAndroid Build Coastguard Worker 33*58b9f456SAndroid Build Coastguard WorkerExternal Threading Library 34*58b9f456SAndroid Build Coastguard Worker========================== 35*58b9f456SAndroid Build Coastguard Worker 36*58b9f456SAndroid Build Coastguard Workerlibc++ can be compiled with its internal threading API delegating to an external 37*58b9f456SAndroid Build Coastguard Workerlibrary. Such a configuration is useful for library vendors who wish to 38*58b9f456SAndroid Build Coastguard Workerdistribute a thread-agnostic libc++ library, where the users of the library are 39*58b9f456SAndroid Build Coastguard Workerexpected to provide the implementation of the libc++ internal threading API. 40*58b9f456SAndroid Build Coastguard Worker 41*58b9f456SAndroid Build Coastguard WorkerOn a production setting, this would be achieved through a custom 42*58b9f456SAndroid Build Coastguard Worker``<__external_threading>`` header, which declares the libc++ internal threading 43*58b9f456SAndroid Build Coastguard WorkerAPI but leaves out the implementation. 44*58b9f456SAndroid Build Coastguard Worker 45*58b9f456SAndroid Build Coastguard WorkerThe ``-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY`` option allows building libc++ in 46*58b9f456SAndroid Build Coastguard Workersuch a configuration while allowing it to be tested on a platform that supports 47*58b9f456SAndroid Build Coastguard Workerany of the threading systems (e.g. pthread) supported in ``__threading_support`` 48*58b9f456SAndroid Build Coastguard Workerheader. Therefore, the main purpose of this option is to allow testing of this 49*58b9f456SAndroid Build Coastguard Workerparticular configuration of the library without being tied to a vendor-specific 50*58b9f456SAndroid Build Coastguard Workerthreading system. This option is only meant to be used by libc++ library 51*58b9f456SAndroid Build Coastguard Workerdevelopers. 52*58b9f456SAndroid Build Coastguard Worker 53*58b9f456SAndroid Build Coastguard WorkerThreading Configuration Macros 54*58b9f456SAndroid Build Coastguard Worker============================== 55*58b9f456SAndroid Build Coastguard Worker 56*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_HAS_NO_THREADS** 57*58b9f456SAndroid Build Coastguard Worker This macro is defined when libc++ is built without threading support. It 58*58b9f456SAndroid Build Coastguard Worker should not be manually defined by the user. 59*58b9f456SAndroid Build Coastguard Worker 60*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_HAS_THREAD_API_EXTERNAL** 61*58b9f456SAndroid Build Coastguard Worker This macro is defined when libc++ should use the ``<__external_threading>`` 62*58b9f456SAndroid Build Coastguard Worker header to provide the internal threading API. This macro overrides 63*58b9f456SAndroid Build Coastguard Worker ``_LIBCPP_HAS_THREAD_API_PTHREAD``. 64*58b9f456SAndroid Build Coastguard Worker 65*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_HAS_THREAD_API_PTHREAD** 66*58b9f456SAndroid Build Coastguard Worker This macro is defined when libc++ should use POSIX threads to implement the 67*58b9f456SAndroid Build Coastguard Worker internal threading API. 68*58b9f456SAndroid Build Coastguard Worker 69*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_HAS_THREAD_API_WIN32** 70*58b9f456SAndroid Build Coastguard Worker This macro is defined when libc++ should use Win32 threads to implement the 71*58b9f456SAndroid Build Coastguard Worker internal threading API. 72*58b9f456SAndroid Build Coastguard Worker 73*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL** 74*58b9f456SAndroid Build Coastguard Worker This macro is defined when libc++ expects the definitions of the internal 75*58b9f456SAndroid Build Coastguard Worker threading API to be provided by an external library. When defined 76*58b9f456SAndroid Build Coastguard Worker ``<__threading_support>`` will only provide the forward declarations and 77*58b9f456SAndroid Build Coastguard Worker typedefs for the internal threading API. 78*58b9f456SAndroid Build Coastguard Worker 79*58b9f456SAndroid Build Coastguard Worker**_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL** 80*58b9f456SAndroid Build Coastguard Worker This macro is used to build an external threading library using the 81*58b9f456SAndroid Build Coastguard Worker ``<__threading_support>``. Specifically it exposes the threading API 82*58b9f456SAndroid Build Coastguard Worker definitions in ``<__threading_support>`` as non-inline definitions meant to 83*58b9f456SAndroid Build Coastguard Worker be compiled into a library. 84