You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/internal/threading.h
  3. *
  4. * Purpose: Detects whether the library is being built single- or
  5. * multi-threaded.
  6. *
  7. * Created: 20th November 2007
  8. * Updated: 18th March 2012
  9. *
  10. * Home: http://www.pantheios.org/
  11. *
  12. * Copyright (c) 2007-2012, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the names of Matthew Wilson and Synesis Software nor the names
  25. * of any contributors may be used to endorse or promote products derived
  26. * from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/internal/threading.h
  42. *
  43. * \brief [C, C++] INTERNAL FILE: Detects whether the library is being built
  44. * single- or multi-threaded.
  45. */
  46. #ifndef PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING
  47. #define PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING
  48. /* /////////////////////////////////////////////////////////////////////////
  49. * Includes
  50. */
  51. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  52. # include <pantheios/pantheios.h>
  53. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  54. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL
  55. # include <platformstl/platformstl.h>
  56. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL */
  57. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_UTIL_H_FEATURES
  58. # include <platformstl/synch/util/features.h>
  59. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_UTIL_H_FEATURES */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Feature discrimination
  62. */
  63. #ifdef PANTHEIOS_MT
  64. # undef PANTHEIOS_MT
  65. #endif /* PANTHEIOS_MT */
  66. #ifdef PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
  67. # undef PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
  68. #endif /* PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS */
  69. /* Detect whether we're multithreaded */
  70. #if defined(PANTHEIOS_FORCE_MT)
  71. # define PANTHEIOS_MT
  72. #elif !defined(PANTHEIOS_NO_MT)
  73. # if defined(PLATFORMSTL_OS_IS_UNIX)
  74. # if defined(UNIXSTL_USING_PTHREADS)
  75. # define PANTHEIOS_MT
  76. # endif /* UNIXSTL_USING_PTHREADS */
  77. # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  78. # if defined(__MT__) || \
  79. defined(_REENTRANT) || \
  80. defined(_MT)
  81. # define PANTHEIOS_MT
  82. # endif /* ?? mt ?? */
  83. # else /* ? OS */
  84. # error Platform is not yet discriminated
  85. # endif /* OS */
  86. #endif /* PANTHEIOS_FORCE_MT || PANTHEIOS_NO_MT */
  87. /* Detect whether, if we're multithreaded, we're using atomic integer ops */
  88. #ifdef PANTHEIOS_MT
  89. # if defined(PLATFORMSTL_HAS_ATOMIC_INTEGER_OPERATIONS) && \
  90. !defined(PANTHEIOS_FORCE_NO_ATOMIC_INTEGER_OPERATIONS)
  91. # define PANTHEIOS_MT_HAS_ATOMIC_INTEGER_OPERATIONS
  92. # endif
  93. #endif /* PANTHEIOS_MT */
  94. /* ////////////////////////////////////////////////////////////////////// */
  95. #endif /* PANTHEIOS_INCL_PANTHEIOS_INTERNAL_H_THREADING */
  96. /* ///////////////////////////// end of file //////////////////////////// */