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.

397 lines
15 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: platformstl/synch/atomic_functions.h
  3. *
  4. * Purpose: Definition of the atomic functions.
  5. *
  6. * Created: 22nd March 2005
  7. * Updated: 7th June 2010
  8. *
  9. * Home: http://stlsoft.org/
  10. *
  11. * Copyright (c) 2005-2010, Matthew Wilson and Synesis Software
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright notice, this
  18. * list of conditions and the following disclaimer.
  19. * - Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  23. * any contributors may be used to endorse or promote products derived from
  24. * this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  30. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  31. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  32. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  33. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  34. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  35. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * ////////////////////////////////////////////////////////////////////// */
  39. /** \file platformstl/synch/atomic_functions.h
  40. *
  41. * \brief [C, C++] Definition of the atomic functions
  42. * (\ref group__library__synch "Synchronisation" Library).
  43. */
  44. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS
  45. #define PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS
  46. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  47. # define PLATFORMSTL_VER_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS_MAJOR 2
  48. # define PLATFORMSTL_VER_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS_MINOR 3
  49. # define PLATFORMSTL_VER_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS_REVISION 2
  50. # define PLATFORMSTL_VER_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS_EDIT 29
  51. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  52. /* /////////////////////////////////////////////////////////////////////////
  53. * Compatibility
  54. */
  55. /*
  56. [<[STLSOFT-AUTO:NO-UNITTEST]>]
  57. [Incompatibilies-start]
  58. [Incompatibilies-end]
  59. */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Includes
  62. */
  63. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL
  64. # include <platformstl/platformstl.h>
  65. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_H_PLATFORMSTL */
  66. #ifndef PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_H_ATOMIC_TYPES
  67. # include <platformstl/synch/atomic_types.h>
  68. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_H_ATOMIC_TYPES */
  69. #if defined(PLATFORMSTL_OS_IS_UNIX)
  70. # ifndef UNIXSTL_INCL_UNIXSTL_SYNCH_H_ATOMIC_FUNCTIONS
  71. # include <unixstl/synch/atomic_functions.h>
  72. # endif /* !UNIXSTL_INCL_UNIXSTL_SYNCH_H_ATOMIC_FUNCTIONS */
  73. #elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  74. # ifndef WINSTL_INCL_WINSTL_SYNCH_H_ATOMIC_FUNCTIONS
  75. # include <winstl/synch/atomic_functions.h>
  76. # endif /* !WINSTL_INCL_WINSTL_SYNCH_H_ATOMIC_FUNCTIONS */
  77. #else /* ? operating system */
  78. # error Operating system not discriminated
  79. #endif /* operating system */
  80. /* /////////////////////////////////////////////////////////////////////////
  81. * Namespace
  82. */
  83. #if !defined(__cplusplus)
  84. /* Nothing defined in C */
  85. #elif defined(_STLSOFT_NO_NAMESPACE) || \
  86. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  87. /* There is no stlsoft namespace, so must define ::platformstl */
  88. namespace platformstl
  89. {
  90. #else
  91. /* Define stlsoft::platformstl_project */
  92. namespace stlsoft
  93. {
  94. namespace platformstl_project
  95. {
  96. #endif /* _STLSOFT_NO_NAMESPACE */
  97. /* /////////////////////////////////////////////////////////////////////////
  98. * Features
  99. */
  100. #ifdef PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  101. # undef PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  102. #endif /* PLATFORMSTL_HAS_ATOMIC_PREINCREMENT */
  103. #ifdef PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  104. # undef PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  105. #endif /* PLATFORMSTL_HAS_ATOMIC_PREDECREMENT */
  106. #ifdef PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  107. # undef PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  108. #endif /* PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT */
  109. #ifdef PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  110. # undef PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  111. #endif /* PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT */
  112. #ifdef PLATFORMSTL_HAS_ATOMIC_INCREMENT
  113. # undef PLATFORMSTL_HAS_ATOMIC_INCREMENT
  114. #endif /* PLATFORMSTL_HAS_ATOMIC_INCREMENT */
  115. #ifdef PLATFORMSTL_HAS_ATOMIC_DECREMENT
  116. # undef PLATFORMSTL_HAS_ATOMIC_DECREMENT
  117. #endif /* PLATFORMSTL_HAS_ATOMIC_DECREMENT */
  118. #ifdef PLATFORMSTL_HAS_ATOMIC_READ
  119. # undef PLATFORMSTL_HAS_ATOMIC_READ
  120. #endif /* PLATFORMSTL_HAS_ATOMIC_READ */
  121. #ifdef PLATFORMSTL_HAS_ATOMIC_WRITE
  122. # undef PLATFORMSTL_HAS_ATOMIC_WRITE
  123. #endif /* PLATFORMSTL_HAS_ATOMIC_WRITE */
  124. #ifdef PLATFORMSTL_HAS_ATOMIC_PREADD
  125. # undef PLATFORMSTL_HAS_ATOMIC_PREADD
  126. #endif /* PLATFORMSTL_HAS_ATOMIC_PREADD */
  127. #ifdef PLATFORMSTL_HAS_ATOMIC_POSTADD
  128. # undef PLATFORMSTL_HAS_ATOMIC_POSTADD
  129. #endif /* PLATFORMSTL_HAS_ATOMIC_POSTADD */
  130. /* ////////////////////////////////////////////////////////////////////// */
  131. #if defined(__cplusplus)
  132. # ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  133. namespace implementation
  134. {
  135. # endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  136. # if defined(PLATFORMSTL_OS_IS_UNIX)
  137. # ifndef PLATFORSL_DEFINED_platform_stl_
  138. # define PLATFORSL_DEFINED_platform_stl_
  139. namespace platform_stl_ = ::unixstl;
  140. # endif /* !PLATFORSL_DEFINED_platform_stl_ */
  141. # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  142. # ifndef PLATFORSL_DEFINED_platform_stl_
  143. # define PLATFORSL_DEFINED_platform_stl_
  144. namespace platform_stl_ = ::winstl;
  145. # endif /* !PLATFORSL_DEFINED_platform_stl_ */
  146. # else /* ? operating system */
  147. # error Operating system not discriminated
  148. # endif /* operating system */
  149. # ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  150. }
  151. # endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  152. # if ( defined(PLATFORMSTL_OS_IS_UNIX) && \
  153. defined(_UNIXSTL_NO_NAMESPACE)) || \
  154. ( defined(PLATFORMSTL_OS_IS_WINDOWS) && \
  155. defined(_WINSTL_NO_NAMESPACE))
  156. /* Source atomic functions are defined within a namespace, either unixstl or winstl. */
  157. # if defined(PLATFORMSTL_OS_IS_UNIX)
  158. # ifdef UNIXSTL_HAS_ATOMIC_PREINCREMENT
  159. using atomic_preincrement;
  160. # define PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  161. # endif /* UNIXSTL_HAS_ATOMIC_PREINCREMENT */
  162. # ifdef UNIXSTL_HAS_ATOMIC_PREDECREMENT
  163. using atomic_predecrement;
  164. # define PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  165. # endif /* UNIXSTL_HAS_ATOMIC_PREDECREMENT */
  166. # ifdef UNIXSTL_HAS_ATOMIC_POSTINCREMENT
  167. using atomic_postincrement;
  168. # define PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  169. # endif /* UNIXSTL_HAS_ATOMIC_POSTINCREMENT */
  170. # ifdef UNIXSTL_HAS_ATOMIC_POSTDECREMENT
  171. using atomic_postdecrement;
  172. # define PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  173. # endif /* UNIXSTL_HAS_ATOMIC_POSTDECREMENT */
  174. # ifdef UNIXSTL_HAS_ATOMIC_INCREMENT
  175. using atomic_increment;
  176. # define PLATFORMSTL_HAS_ATOMIC_INCREMENT
  177. # endif /* UNIXSTL_HAS_ATOMIC_INCREMENT */
  178. # ifdef UNIXSTL_HAS_ATOMIC_DECREMENT
  179. using atomic_decrement;
  180. # define PLATFORMSTL_HAS_ATOMIC_DECREMENT
  181. # endif /* UNIXSTL_HAS_ATOMIC_DECREMENT */
  182. # ifdef UNIXSTL_HAS_ATOMIC_READ
  183. using atomic_read;
  184. # define PLATFORMSTL_HAS_ATOMIC_READ
  185. # endif /* UNIXSTL_HAS_ATOMIC_READ */
  186. # ifdef UNIXSTL_HAS_ATOMIC_WRITE
  187. using atomic_write;
  188. # define PLATFORMSTL_HAS_ATOMIC_WRITE
  189. # endif /* UNIXSTL_HAS_ATOMIC_WRITE */
  190. # ifdef UNIXSTL_HAS_ATOMIC_PREADD
  191. using atomic_preadd;
  192. # define PLATFORMSTL_HAS_ATOMIC_PREADD
  193. # endif /* UNIXSTL_HAS_ATOMIC_PREADD */
  194. # ifdef UNIXSTL_HAS_ATOMIC_POSTADD
  195. using atomic_postadd;
  196. # define PLATFORMSTL_HAS_ATOMIC_POSTADD
  197. # endif /* UNIXSTL_HAS_ATOMIC_POSTADD */
  198. # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  199. /* OS: Win32 */
  200. # if defined(UNIXSTL_ARCH_IS_X86) || \
  201. defined(UNIXSTL_ARCH_IS_IA64) || \
  202. defined(UNIXSTL_ARCH_IS_X64)
  203. /* Arch: i386 */
  204. using atomic_preincrement_up;
  205. using atomic_predecrement_up;
  206. using atomic_postincrement_up;
  207. using atomic_postdecrement_up;
  208. using atomic_increment_up;
  209. using atomic_decrement_up;
  210. using atomic_write_up;
  211. using atomic_read_up;
  212. using atomic_postadd_up;
  213. using atomic_preadd_up;
  214. using atomic_preincrement_smp;
  215. using atomic_predecrement_smp;
  216. using atomic_postincrement_smp;
  217. using atomic_postdecrement_smp;
  218. using atomic_increment_smp;
  219. using atomic_decrement_smp;
  220. using atomic_write_smp;
  221. using atomic_read_smp;
  222. using atomic_postadd_smp;
  223. using atomic_preadd_smp;
  224. using atomic_preincrement;
  225. using atomic_predecrement;
  226. using atomic_postincrement;
  227. using atomic_postdecrement;
  228. using atomic_increment;
  229. using atomic_decrement;
  230. using atomic_write;
  231. using atomic_read;
  232. using atomic_postadd;
  233. using atomic_preadd;
  234. # define PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  235. # define PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  236. # define PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  237. # define PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  238. # define PLATFORMSTL_HAS_ATOMIC_INCREMENT
  239. # define PLATFORMSTL_HAS_ATOMIC_DECREMENT
  240. # define PLATFORMSTL_HAS_ATOMIC_READ
  241. # define PLATFORMSTL_HAS_ATOMIC_WRITE
  242. # define PLATFORMSTL_HAS_ATOMIC_PREADD
  243. # define PLATFORMSTL_HAS_ATOMIC_POSTADD
  244. # else /* ? arch */
  245. # error Not valid for processors other than Intel
  246. # endif /* arch */
  247. # else /* ? operating system */
  248. # error Operating system not discriminated
  249. # endif /* operating system */
  250. # else /* ? global */
  251. /* Source atomic functions are defined within the global namespace. */
  252. # if defined(PLATFORMSTL_OS_IS_UNIX)
  253. # ifdef UNIXSTL_HAS_ATOMIC_PREINCREMENT
  254. using implementation::platform_stl_::atomic_preincrement;
  255. # define PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  256. # endif /* UNIXSTL_HAS_ATOMIC_PREINCREMENT */
  257. # ifdef UNIXSTL_HAS_ATOMIC_PREDECREMENT
  258. using implementation::platform_stl_::atomic_predecrement;
  259. # define PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  260. # endif /* UNIXSTL_HAS_ATOMIC_PREDECREMENT */
  261. # ifdef UNIXSTL_HAS_ATOMIC_POSTINCREMENT
  262. using implementation::platform_stl_::atomic_postincrement;
  263. # define PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  264. # endif /* UNIXSTL_HAS_ATOMIC_POSTINCREMENT */
  265. # ifdef UNIXSTL_HAS_ATOMIC_POSTDECREMENT
  266. using implementation::platform_stl_::atomic_postdecrement;
  267. # define PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  268. # endif /* UNIXSTL_HAS_ATOMIC_POSTDECREMENT */
  269. # ifdef UNIXSTL_HAS_ATOMIC_INCREMENT
  270. using implementation::platform_stl_::atomic_increment;
  271. # define PLATFORMSTL_HAS_ATOMIC_INCREMENT
  272. # endif /* UNIXSTL_HAS_ATOMIC_INCREMENT */
  273. # ifdef UNIXSTL_HAS_ATOMIC_DECREMENT
  274. using implementation::platform_stl_::atomic_decrement;
  275. # define PLATFORMSTL_HAS_ATOMIC_DECREMENT
  276. # endif /* UNIXSTL_HAS_ATOMIC_DECREMENT */
  277. # ifdef UNIXSTL_HAS_ATOMIC_READ
  278. using implementation::platform_stl_::atomic_read;
  279. # define PLATFORMSTL_HAS_ATOMIC_READ
  280. # endif /* UNIXSTL_HAS_ATOMIC_READ */
  281. # ifdef UNIXSTL_HAS_ATOMIC_WRITE
  282. using implementation::platform_stl_::atomic_write;
  283. # define PLATFORMSTL_HAS_ATOMIC_WRITE
  284. # endif /* UNIXSTL_HAS_ATOMIC_WRITE */
  285. # ifdef UNIXSTL_HAS_ATOMIC_PREADD
  286. using implementation::platform_stl_::atomic_preadd;
  287. # define PLATFORMSTL_HAS_ATOMIC_PREADD
  288. # endif /* UNIXSTL_HAS_ATOMIC_PREADD */
  289. # ifdef UNIXSTL_HAS_ATOMIC_POSTADD
  290. using implementation::platform_stl_::atomic_postadd;
  291. # define PLATFORMSTL_HAS_ATOMIC_POSTADD
  292. # endif /* UNIXSTL_HAS_ATOMIC_POSTADD */
  293. # elif defined(PLATFORMSTL_OS_IS_WINDOWS)
  294. /* OS: Win32 */
  295. # if defined(WINSTL_ARCH_IS_X86) || \
  296. defined(WINSTL_ARCH_IS_IA64) || \
  297. defined(WINSTL_ARCH_IS_X64)
  298. /* Arch: i386 */
  299. using implementation::platform_stl_::atomic_preincrement_up;
  300. using implementation::platform_stl_::atomic_predecrement_up;
  301. using implementation::platform_stl_::atomic_postincrement_up;
  302. using implementation::platform_stl_::atomic_postdecrement_up;
  303. using implementation::platform_stl_::atomic_increment_up;
  304. using implementation::platform_stl_::atomic_decrement_up;
  305. using implementation::platform_stl_::atomic_write_up;
  306. using implementation::platform_stl_::atomic_read_up;
  307. using implementation::platform_stl_::atomic_postadd_up;
  308. using implementation::platform_stl_::atomic_preadd_up;
  309. using implementation::platform_stl_::atomic_preincrement_smp;
  310. using implementation::platform_stl_::atomic_predecrement_smp;
  311. using implementation::platform_stl_::atomic_postincrement_smp;
  312. using implementation::platform_stl_::atomic_postdecrement_smp;
  313. using implementation::platform_stl_::atomic_increment_smp;
  314. using implementation::platform_stl_::atomic_decrement_smp;
  315. using implementation::platform_stl_::atomic_write_smp;
  316. using implementation::platform_stl_::atomic_read_smp;
  317. using implementation::platform_stl_::atomic_postadd_smp;
  318. using implementation::platform_stl_::atomic_preadd_smp;
  319. using implementation::platform_stl_::atomic_preincrement;
  320. using implementation::platform_stl_::atomic_predecrement;
  321. using implementation::platform_stl_::atomic_postincrement;
  322. using implementation::platform_stl_::atomic_postdecrement;
  323. using implementation::platform_stl_::atomic_increment;
  324. using implementation::platform_stl_::atomic_decrement;
  325. using implementation::platform_stl_::atomic_write;
  326. using implementation::platform_stl_::atomic_read;
  327. using implementation::platform_stl_::atomic_postadd;
  328. using implementation::platform_stl_::atomic_preadd;
  329. # define PLATFORMSTL_HAS_ATOMIC_PREINCREMENT
  330. # define PLATFORMSTL_HAS_ATOMIC_PREDECREMENT
  331. # define PLATFORMSTL_HAS_ATOMIC_POSTINCREMENT
  332. # define PLATFORMSTL_HAS_ATOMIC_POSTDECREMENT
  333. # define PLATFORMSTL_HAS_ATOMIC_INCREMENT
  334. # define PLATFORMSTL_HAS_ATOMIC_DECREMENT
  335. # define PLATFORMSTL_HAS_ATOMIC_READ
  336. # define PLATFORMSTL_HAS_ATOMIC_WRITE
  337. # define PLATFORMSTL_HAS_ATOMIC_PREADD
  338. # define PLATFORMSTL_HAS_ATOMIC_POSTADD
  339. # else /* ? arch */
  340. # error Not valid for processors other than Intel
  341. # endif /* arch */
  342. # else /* ? operating system */
  343. # error Operating system not discriminated
  344. # endif /* operating system */
  345. # endif /* global */
  346. #endif /* __cplusplus */
  347. /* ////////////////////////////////////////////////////////////////////// */
  348. #if !defined(__cplusplus)
  349. /* Nothing defined in C */
  350. #elif defined(_STLSOFT_NO_NAMESPACE) || \
  351. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  352. } /* namespace platformstl */
  353. #else
  354. } /* namespace platformstl_project */
  355. } /* namespace stlsoft */
  356. #endif /* _STLSOFT_NO_NAMESPACE */
  357. /* ////////////////////////////////////////////////////////////////////// */
  358. #endif /* !PLATFORMSTL_INCL_PLATFORMSTL_SYNCH_H_ATOMIC_FUNCTIONS */
  359. /* ///////////////////////////// end of file //////////////////////////// */