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