ThreadingSupportAPI.rst 3.6 KB

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