ThreadingSupportAPI.rst 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. Normally ``<__threading_support>`` provides inline definitions to each internal
  28. threading API function it declares. However libc++ also supports using an
  29. external library to provide the definitions.
  30. When ``_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL`` libc++ does not provide inline
  31. definitions for the internal API, instead assuming the definitions will be
  32. provided by an external library.
  33. Threading Configuration Macros
  34. ==============================
  35. **_LIBCPP_HAS_NO_THREADS**
  36. This macro is defined when libc++ is built without threading support. It
  37. should not be manually defined by the user.
  38. **_LIBCPP_HAS_THREAD_API_EXTERNAL**
  39. This macro is defined when libc++ should use the ``<__external_threading>``
  40. header to provide the internal threading API. This macro overrides
  41. ``_LIBCPP_HAS_THREAD_API_PTHREAD``.
  42. **_LIBCPP_HAS_THREAD_API_PTHREAD**
  43. This macro is defined when libc++ should use POSIX threads to implement the
  44. internal threading API.
  45. **_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL**
  46. This macro is defined when libc++ expects the definitions of the internal
  47. threading API to be provided by an external library. When defined
  48. ``<__threading_support>`` will only provide the forward declarations and
  49. typedefs for the internal threading API.
  50. **_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL**
  51. This macro is used to build an external threading library using the
  52. ``<__threading_support>``. Specifically it exposes the threading API
  53. definitions in ``<__threading_support>`` as non-inline definitions meant to
  54. be compiled into a library.