Eric Fiselier | 66134e8 | 2017-01-06 20:05:40 +0000 | [diff] [blame^] | 1 | ===================== |
| 2 | Threading Support API |
| 3 | ===================== |
| 4 | |
| 5 | .. contents:: |
| 6 | :local: |
| 7 | |
| 8 | Overview |
| 9 | ======== |
| 10 | |
| 11 | Libc++ supports using multiple different threading models and configurations |
| 12 | to implement the threading parts of libc++, including ``<thread>`` and ``<mutex>``. |
| 13 | These different models provide entirely different interfaces from each |
| 14 | other. To address this libc++ wraps the underlying threading API in a new and |
| 15 | consistent API, which it uses internally to implement threading primitives. |
| 16 | |
| 17 | The ``<__threading_support>`` header is where libc++ defines its internal |
| 18 | threading interface. It contains forward declarations of the internal threading |
| 19 | interface as well as definitions for the interface. |
| 20 | |
| 21 | External Threading API and the ``<__external_threading>`` header |
| 22 | ================================================================ |
| 23 | |
| 24 | In order to support vendors with custom threading API's libc++ allows the |
| 25 | entire internal threading interface to be provided by an external, |
| 26 | vendor provided, header. |
| 27 | |
| 28 | When ``_LIBCPP_HAS_THREAD_API_EXTERNAL`` is defined the ``<__threading_support>`` |
| 29 | header simply forwards to the ``<__external_threading>`` header (which must exist). |
| 30 | It is expected that the ``<__external_threading>`` header provide the exact |
| 31 | interface normally provided by ``<__threading_support>``. |
| 32 | |
| 33 | External Threading Library |
| 34 | ========================== |
| 35 | |
| 36 | Normally ``<__threading_support>`` provides inline definitions to each internal |
| 37 | threading API function it declares. However libc++ also supports using an |
| 38 | external library to provide the definitions. |
| 39 | |
| 40 | When ``_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`` libc++ does not provide inline |
| 41 | definitions for the internal API, instead assuming the definitions will be |
| 42 | provided by an external library. |
| 43 | |
| 44 | Threading Configuration Macros |
| 45 | ============================== |
| 46 | |
| 47 | **_LIBCPP_HAS_NO_THREADS** |
| 48 | This macro is defined when libc++ is built without threading support. It |
| 49 | should not be manually defined by the user. |
| 50 | |
| 51 | **_LIBCPP_HAS_THREAD_API_EXTERNAL** |
| 52 | This macro is defined when libc++ should use the ``<__external_threading>`` |
| 53 | header to provide the internal threading API. This macro overrides |
| 54 | ``_LIBCPP_HAS_THREAD_API_PTHREAD``. |
| 55 | |
| 56 | **_LIBCPP_HAS_THREAD_API_PTHREAD** |
| 57 | This macro is defined when libc++ should use POSIX threads to implement the |
| 58 | internal threading API. |
| 59 | |
| 60 | **_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL** |
| 61 | This macro is defined when libc++ expects the definitions of the internal |
| 62 | threading API to be provided by an external library. When defined |
| 63 | ``<__threading_support>`` will only provide the forward declarations and |
| 64 | typedefs for the internal threading API. |
| 65 | |
| 66 | **_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL** |
| 67 | This macro is used to build an external threading library using the |
| 68 | ``<__threading_support>``. Specifically it exposes the threading API |
| 69 | definitions in ``<__threading_support>`` as non-inline definitions meant to |
| 70 | be compiled into a library. |