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