100f6beaeSEric Fiselier===================== 200f6beaeSEric FiselierThreading Support API 300f6beaeSEric Fiselier===================== 400f6beaeSEric Fiselier 500f6beaeSEric Fiselier.. contents:: 600f6beaeSEric Fiselier :local: 700f6beaeSEric Fiselier 800f6beaeSEric FiselierOverview 900f6beaeSEric Fiselier======== 1000f6beaeSEric Fiselier 1100f6beaeSEric FiselierLibc++ supports using multiple different threading models and configurations 1200f6beaeSEric Fiselierto implement the threading parts of libc++, including ``<thread>`` and ``<mutex>``. 1300f6beaeSEric FiselierThese different models provide entirely different interfaces from each 1400f6beaeSEric Fiselierother. To address this libc++ wraps the underlying threading API in a new and 1500f6beaeSEric Fiselierconsistent API, which it uses internally to implement threading primitives. 1600f6beaeSEric Fiselier 1700f6beaeSEric FiselierThe ``<__threading_support>`` header is where libc++ defines its internal 1800f6beaeSEric Fiselierthreading interface. It contains forward declarations of the internal threading 1900f6beaeSEric Fiselierinterface as well as definitions for the interface. 2000f6beaeSEric Fiselier 2100f6beaeSEric FiselierExternal Threading API and the ``<__external_threading>`` header 2200f6beaeSEric Fiselier================================================================ 2300f6beaeSEric Fiselier 2400f6beaeSEric FiselierIn order to support vendors with custom threading API's libc++ allows the 2500f6beaeSEric Fiselierentire internal threading interface to be provided by an external, 2600f6beaeSEric Fiseliervendor provided, header. 2700f6beaeSEric Fiselier 2800f6beaeSEric FiselierWhen ``_LIBCPP_HAS_THREAD_API_EXTERNAL`` is defined the ``<__threading_support>`` 2900f6beaeSEric Fiselierheader simply forwards to the ``<__external_threading>`` header (which must exist). 3000f6beaeSEric FiselierIt is expected that the ``<__external_threading>`` header provide the exact 3100f6beaeSEric Fiselierinterface normally provided by ``<__threading_support>``. 3200f6beaeSEric Fiselier 3300f6beaeSEric FiselierExternal Threading Library 3400f6beaeSEric Fiselier========================== 3500f6beaeSEric Fiselier 36e3d832a3SAsiri Rathnayakelibc++ can be compiled with its internal threading API delegating to an external 37e3d832a3SAsiri Rathnayakelibrary. Such a configuration is useful for library vendors who wish to 38e3d832a3SAsiri Rathnayakedistribute a thread-agnostic libc++ library, where the users of the library are 39e3d832a3SAsiri Rathnayakeexpected to provide the implementation of the libc++ internal threading API. 4000f6beaeSEric Fiselier 41e3d832a3SAsiri RathnayakeOn a production setting, this would be achieved through a custom 42e3d832a3SAsiri Rathnayake``<__external_threading>`` header, which declares the libc++ internal threading 43e3d832a3SAsiri RathnayakeAPI but leaves out the implementation. 44e3d832a3SAsiri Rathnayake 45e3d832a3SAsiri RathnayakeThe ``-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY`` option allows building libc++ in 46e3d832a3SAsiri Rathnayakesuch a configuration while allowing it to be tested on a platform that supports 47e3d832a3SAsiri Rathnayakeany of the threading systems (e.g. pthread) supported in ``__threading_support`` 48e3d832a3SAsiri Rathnayakeheader. Therefore, the main purpose of this option is to allow testing of this 49e3d832a3SAsiri Rathnayakeparticular configuration of the library without being tied to a vendor-specific 50e3d832a3SAsiri Rathnayakethreading system. This option is only meant to be used by libc++ library 51e3d832a3SAsiri Rathnayakedevelopers. 5200f6beaeSEric Fiselier 5300f6beaeSEric FiselierThreading Configuration Macros 5400f6beaeSEric Fiselier============================== 5500f6beaeSEric Fiselier 5600f6beaeSEric Fiselier**_LIBCPP_HAS_NO_THREADS** 5700f6beaeSEric Fiselier This macro is defined when libc++ is built without threading support. It 5800f6beaeSEric Fiselier should not be manually defined by the user. 5900f6beaeSEric Fiselier 6000f6beaeSEric Fiselier**_LIBCPP_HAS_THREAD_API_EXTERNAL** 6100f6beaeSEric Fiselier This macro is defined when libc++ should use the ``<__external_threading>`` 6200f6beaeSEric Fiselier header to provide the internal threading API. This macro overrides 6300f6beaeSEric Fiselier ``_LIBCPP_HAS_THREAD_API_PTHREAD``. 6400f6beaeSEric Fiselier 6500f6beaeSEric Fiselier**_LIBCPP_HAS_THREAD_API_PTHREAD** 6600f6beaeSEric Fiselier This macro is defined when libc++ should use POSIX threads to implement the 6700f6beaeSEric Fiselier internal threading API. 6800f6beaeSEric Fiselier 69*bf02a091SMartin Storsjo**_LIBCPP_HAS_THREAD_API_WIN32** 70*bf02a091SMartin Storsjo This macro is defined when libc++ should use Win32 threads to implement the 71*bf02a091SMartin Storsjo internal threading API. 72*bf02a091SMartin Storsjo 7300f6beaeSEric Fiselier**_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL** 7400f6beaeSEric Fiselier This macro is defined when libc++ expects the definitions of the internal 7500f6beaeSEric Fiselier threading API to be provided by an external library. When defined 7600f6beaeSEric Fiselier ``<__threading_support>`` will only provide the forward declarations and 7700f6beaeSEric Fiselier typedefs for the internal threading API. 7800f6beaeSEric Fiselier 7900f6beaeSEric Fiselier**_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL** 8000f6beaeSEric Fiselier This macro is used to build an external threading library using the 8100f6beaeSEric Fiselier ``<__threading_support>``. Specifically it exposes the threading API 8200f6beaeSEric Fiselier definitions in ``<__threading_support>`` as non-inline definitions meant to 8300f6beaeSEric Fiselier be compiled into a library. 84