starpu_util.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2008-2019 Université de Bordeaux
  4. * Copyright (C) 2011,2012,2017 Inria
  5. * Copyright (C) 2010-2017, 2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #ifndef __STARPU_UTIL_H__
  19. #define __STARPU_UTIL_H__
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <stdint.h>
  23. #include <string.h>
  24. #include <assert.h>
  25. #include <starpu_config.h>
  26. #ifdef __GLIBC__
  27. #include <execinfo.h>
  28. #endif
  29. #ifdef STARPU_SIMGRID_MC
  30. #include <simgrid/modelchecker.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C"
  34. {
  35. #endif
  36. /**
  37. @defgroup API_Toolbox Toolbox
  38. @brief The following macros allow to make GCC extensions portable,
  39. and to have a code which can be compiled with any C compiler.
  40. @{
  41. */
  42. /**
  43. Return true (non-zero) if GCC version \p maj.\p min or later is
  44. being used (macro taken from glibc.)
  45. */
  46. #if defined __GNUC__ && defined __GNUC_MINOR__
  47. # define STARPU_GNUC_PREREQ(maj, min) \
  48. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  49. #else
  50. # define STARPU_GNUC_PREREQ(maj, min) 0
  51. #endif
  52. /**
  53. When building with a GNU C Compiler, allow programmers to mark an
  54. expression as unlikely.
  55. */
  56. #ifdef __GNUC__
  57. # define STARPU_UNLIKELY(expr) (__builtin_expect(!!(expr),0))
  58. #else
  59. # define STARPU_UNLIKELY(expr) (expr)
  60. #endif
  61. /**
  62. When building with a GNU C Compiler, allow programmers to mark an
  63. expression as likely.
  64. */
  65. #ifdef __GNUC__
  66. # define STARPU_LIKELY(expr) (__builtin_expect(!!(expr),1))
  67. #else
  68. # define STARPU_LIKELY(expr) (expr)
  69. #endif
  70. /**
  71. When building with a GNU C Compiler, defined to __attribute__((unused))
  72. */
  73. #ifdef __GNUC__
  74. # define STARPU_ATTRIBUTE_UNUSED __attribute__((unused))
  75. #else
  76. # define STARPU_ATTRIBUTE_UNUSED
  77. #endif
  78. /**
  79. When building with a GNU C Compiler, defined to __attribute__((noreturn))
  80. */
  81. #ifdef __GNUC__
  82. # define STARPU_ATTRIBUTE_NORETURN __attribute__((noreturn))
  83. #else
  84. # define STARPU_ATTRIBUTE_NORETURN
  85. #endif
  86. /**
  87. When building with a GNU C Compiler, defined to __attribute__((visibility ("internal")))
  88. */
  89. #ifdef __GNUC__
  90. # define STARPU_ATTRIBUTE_INTERNAL __attribute__ ((visibility ("internal")))
  91. #else
  92. # define STARPU_ATTRIBUTE_INTERNAL
  93. #endif
  94. /**
  95. When building with a GNU C Compiler, defined to __attribute__((malloc))
  96. */
  97. #ifdef __GNUC__
  98. # define STARPU_ATTRIBUTE_MALLOC __attribute__((malloc))
  99. #else
  100. # define STARPU_ATTRIBUTE_MALLOC
  101. #endif
  102. /**
  103. When building with a GNU C Compiler, defined to __attribute__((warn_unused_result))
  104. */
  105. #ifdef __GNUC__
  106. # define STARPU_ATTRIBUTE_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  107. #else
  108. # define STARPU_ATTRIBUTE_WARN_UNUSED_RESULT
  109. #endif
  110. /**
  111. When building with a GNU C Compiler, defined to __attribute__((pure))
  112. */
  113. #ifdef __GNUC__
  114. # define STARPU_ATTRIBUTE_PURE __attribute__((pure))
  115. #else
  116. # define STARPU_ATTRIBUTE_PURE
  117. #endif
  118. /**
  119. When building with a GNU C Compiler, defined to__attribute__((aligned(size)))
  120. */
  121. #ifdef __GNUC__
  122. # define STARPU_ATTRIBUTE_ALIGNED(size) __attribute__((aligned(size)))
  123. #else
  124. # define STARPU_ATTRIBUTE_ALIGNED(size)
  125. #endif
  126. #ifdef __GNUC__
  127. # define STARPU_ATTRIBUTE_FORMAT(type, string, first) __attribute__((format(type, string, first)))
  128. #else
  129. # define STARPU_ATTRIBUTE_FORMAT(type, string, first)
  130. #endif
  131. /* Note that if we're compiling C++, then just use the "inline"
  132. keyword, since it's part of C++ */
  133. #if defined(c_plusplus) || defined(__cplusplus)
  134. # define STARPU_INLINE inline
  135. #elif defined(_MSC_VER) || defined(__HP_cc)
  136. # define STARPU_INLINE __inline
  137. #else
  138. # define STARPU_INLINE __inline__
  139. #endif
  140. #if STARPU_GNUC_PREREQ(4, 3)
  141. # define STARPU_ATTRIBUTE_CALLOC_SIZE(num,size) __attribute__((alloc_size(num,size)))
  142. # define STARPU_ATTRIBUTE_ALLOC_SIZE(size) __attribute__((alloc_size(size)))
  143. #else
  144. # define STARPU_ATTRIBUTE_CALLOC_SIZE(num,size)
  145. # define STARPU_ATTRIBUTE_ALLOC_SIZE(size)
  146. #endif
  147. #if STARPU_GNUC_PREREQ(3, 1) && !defined(BUILDING_STARPU) && !defined(STARPU_USE_DEPRECATED_API) && !defined(STARPU_USE_DEPRECATED_ONE_ZERO_API)
  148. #define STARPU_DEPRECATED __attribute__((__deprecated__))
  149. #else
  150. #define STARPU_DEPRECATED
  151. #endif /* __GNUC__ */
  152. #if STARPU_GNUC_PREREQ(3,3)
  153. #define STARPU_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
  154. #else
  155. #define STARPU_WARN_UNUSED_RESULT
  156. #endif /* __GNUC__ */
  157. #define STARPU_BACKTRACE_LENGTH 32
  158. #ifdef __GLIBC__
  159. # define STARPU_DUMP_BACKTRACE() do { \
  160. void *__ptrs[STARPU_BACKTRACE_LENGTH]; \
  161. int __n = backtrace(__ptrs, STARPU_BACKTRACE_LENGTH); \
  162. backtrace_symbols_fd(__ptrs, __n, 2); \
  163. } while (0)
  164. #else
  165. # define STARPU_DUMP_BACKTRACE() do { } while (0)
  166. #endif
  167. #ifdef STARPU_SIMGRID_MC
  168. #define STARPU_SIMGRID_ASSERT(x) MC_assert(!!(x))
  169. #else
  170. #define STARPU_SIMGRID_ASSERT(x)
  171. #endif
  172. /**
  173. Unless StarPU has been configured with the option \ref enable-fast
  174. "--enable-fast", this macro will abort if the expression \p x is false.
  175. */
  176. #ifdef STARPU_NO_ASSERT
  177. #define STARPU_ASSERT(x) do { if (0) { (void) (x); } } while(0)
  178. #else
  179. # if defined(__CUDACC__) || defined(STARPU_HAVE_WINDOWS)
  180. # define STARPU_ASSERT(x) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); STARPU_SIMGRID_ASSERT(x); *(int*)NULL = 0; } } while(0)
  181. # else
  182. # define STARPU_ASSERT(x) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); STARPU_SIMGRID_ASSERT(x); assert(x); } } while (0)
  183. # endif
  184. #endif
  185. #ifdef STARPU_NO_ASSERT
  186. #define STARPU_ASSERT_ACCESSIBLE(x) do { if (0) { (void) (x); } } while(0)
  187. #else
  188. #define STARPU_ASSERT_ACCESSIBLE(ptr) do { volatile char __c STARPU_ATTRIBUTE_UNUSED = *(char*) (ptr); } while(0)
  189. #endif
  190. /**
  191. Unless StarPU has been configured with the option \ref enable-fast
  192. "--enable-fast", this macro will abort if the expression \p x is false.
  193. The string \p msg will be displayed.
  194. */
  195. #ifdef STARPU_NO_ASSERT
  196. #define STARPU_ASSERT_MSG(x, msg, ...) do { if (0) { (void) (x); (void) msg; } } while(0)
  197. #else
  198. # if defined(__CUDACC__) || defined(STARPU_HAVE_WINDOWS)
  199. # define STARPU_ASSERT_MSG(x, msg, ...) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); STARPU_SIMGRID_ASSERT(x); *(int*)NULL = 0; }} while(0)
  200. # else
  201. # define STARPU_ASSERT_MSG(x, msg, ...) do { if (STARPU_UNLIKELY(!(x))) { STARPU_DUMP_BACKTRACE(); fprintf(stderr, "\n[starpu][%s][assert failure] " msg "\n\n", __starpu_func__, ## __VA_ARGS__); STARPU_SIMGRID_ASSERT(x); assert(x); } } while(0)
  202. # endif
  203. #endif
  204. #ifdef __APPLE_CC__
  205. # ifdef __clang_analyzer__
  206. # define _starpu_abort() exit(42)
  207. # else
  208. # define _starpu_abort() *(volatile int*)NULL = 0
  209. # endif
  210. #else
  211. # define _starpu_abort() abort()
  212. #endif
  213. /**
  214. Abort the program.
  215. */
  216. #define STARPU_ABORT() do { \
  217. STARPU_DUMP_BACKTRACE(); \
  218. fprintf(stderr, "[starpu][abort][%s()@%s:%d]\n", __starpu_func__, __FILE__, __LINE__); \
  219. _starpu_abort(); \
  220. } while(0)
  221. /**
  222. Print the string '[starpu][abort][name of the calling function:name
  223. of the file:line in the file]' followed by the given string \p msg
  224. and abort the program
  225. */
  226. #define STARPU_ABORT_MSG(msg, ...) do { \
  227. STARPU_DUMP_BACKTRACE(); \
  228. fprintf(stderr, "[starpu][abort][%s()@%s:%d] " msg "\n", __starpu_func__, __FILE__, __LINE__, ## __VA_ARGS__); \
  229. _starpu_abort(); \
  230. } while(0)
  231. #if defined(STARPU_HAVE_STRERROR_R)
  232. #if (! defined(__GLIBC__) || !__GLIBC__) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && (! defined(_GNU_SOURCE)))
  233. /* XSI-compliant version of strerror_r returns an int */
  234. # define starpu_strerror_r(errnum, buf, buflen) \
  235. do \
  236. { \
  237. int _ret = strerror_r((errnum), (buf), (buflen)); \
  238. STARPU_ASSERT(_ret == 0); \
  239. } \
  240. while (0)
  241. #else
  242. /* GNU-specific version of strerror_r returns a char * */
  243. # define starpu_strerror_r(errnum, buf, buflen) \
  244. do \
  245. { \
  246. char * const _user_buf = (buf); \
  247. const size_t _user_buflen = (buflen); \
  248. /* the GNU-specific behaviour when 'buf' == NULL cannot be emulated with the XSI-compliant version */ \
  249. STARPU_ASSERT((buf) != NULL); \
  250. char * _tmp_buf = strerror_r((errnum), _user_buf, _user_buflen); \
  251. if (_tmp_buf != _user_buf) \
  252. { \
  253. if (_user_buflen > 0) \
  254. { \
  255. strncpy(_user_buf, _tmp_buf, _user_buflen-1); \
  256. _user_buf[_user_buflen-1] = '\0'; \
  257. } \
  258. } \
  259. } \
  260. while (0)
  261. #endif /* strerror_r ABI version */
  262. #endif /* STARPU_HAVE_STRERROR_R */
  263. /**
  264. Abort the program (after displaying \p message) if \p err has a
  265. value which is not 0.
  266. */
  267. #if defined(STARPU_HAVE_STRERROR_R)
  268. # define STARPU_CHECK_RETURN_VALUE(err, message, ...) {if (STARPU_UNLIKELY(err != 0)) { \
  269. char xmessage[256]; starpu_strerror_r(-err, xmessage, 256); \
  270. fprintf(stderr, "[starpu] Unexpected value: <%d:%s> returned for " message "\n", err, xmessage, ## __VA_ARGS__); \
  271. STARPU_ABORT(); }}
  272. #else
  273. # define STARPU_CHECK_RETURN_VALUE(err, message, ...) {if (STARPU_UNLIKELY(err != 0)) { \
  274. fprintf(stderr, "[starpu] Unexpected value: <%d> returned for " message "\n", err, ## __VA_ARGS__); \
  275. STARPU_ABORT(); }}
  276. #endif
  277. /**
  278. Abort the program (after displaying \p message) if \p err is
  279. different from \p value.
  280. */
  281. #if defined(STARPU_HAVE_STRERROR_R)
  282. # define STARPU_CHECK_RETURN_VALUE_IS(err, value, message, ...) {if (STARPU_UNLIKELY(err != value)) { \
  283. char xmessage[256]; starpu_strerror_r(-err, xmessage, 256); \
  284. fprintf(stderr, "[starpu] Unexpected value: <%d!=%d:%s> returned for " message "\n", err, value, xmessage, ## __VA_ARGS__); \
  285. STARPU_ABORT(); }}
  286. #else
  287. # define STARPU_CHECK_RETURN_VALUE_IS(err, value, message, ...) {if (STARPU_UNLIKELY(err != value)) { \
  288. fprintf(stderr, "[starpu] Unexpected value: <%d != %d> returned for " message "\n", err, value, ## __VA_ARGS__); \
  289. STARPU_ABORT(); }}
  290. #endif
  291. #if defined(__i386__) || defined(__x86_64__)
  292. static __starpu_inline unsigned starpu_cmpxchg(unsigned *ptr, unsigned old, unsigned next)
  293. {
  294. __asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  295. return old;
  296. }
  297. static __starpu_inline unsigned starpu_xchg(unsigned *ptr, unsigned next)
  298. {
  299. /* Note: xchg is always locked already */
  300. __asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  301. return next;
  302. }
  303. #define STARPU_HAVE_XCHG
  304. #if defined(__i386__)
  305. static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
  306. {
  307. __asm__ __volatile__("lock cmpxchgl %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  308. return old;
  309. }
  310. static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
  311. {
  312. /* Note: xchg is always locked already */
  313. __asm__ __volatile__("xchgl %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  314. return next;
  315. }
  316. #define STARPU_HAVE_XCHGL
  317. #endif
  318. #if defined(__x86_64__)
  319. static __starpu_inline unsigned long starpu_cmpxchgl(unsigned long *ptr, unsigned long old, unsigned long next)
  320. {
  321. __asm__ __volatile__("lock cmpxchgq %2,%1": "+a" (old), "+m" (*ptr) : "q" (next) : "memory");
  322. return old;
  323. }
  324. static __starpu_inline unsigned long starpu_xchgl(unsigned long *ptr, unsigned long next)
  325. {
  326. /* Note: xchg is always locked already */
  327. __asm__ __volatile__("xchgq %1,%0": "+m" (*ptr), "+q" (next) : : "memory");
  328. return next;
  329. }
  330. #define STARPU_HAVE_XCHGL
  331. #endif
  332. #endif
  333. #define STARPU_ATOMIC_SOMETHING(name,expr) \
  334. static __starpu_inline unsigned starpu_atomic_##name(unsigned *ptr, unsigned value) \
  335. { \
  336. unsigned old, next; \
  337. while (1) \
  338. { \
  339. old = *ptr; \
  340. next = expr; \
  341. if (starpu_cmpxchg(ptr, old, next) == old) \
  342. break; \
  343. }; \
  344. return expr; \
  345. }
  346. #define STARPU_ATOMIC_SOMETHINGL(name,expr) \
  347. static __starpu_inline unsigned long starpu_atomic_##name##l(unsigned long *ptr, unsigned long value) \
  348. { \
  349. unsigned long old, next; \
  350. while (1) \
  351. { \
  352. old = *ptr; \
  353. next = expr; \
  354. if (starpu_cmpxchgl(ptr, old, next) == old) \
  355. break; \
  356. }; \
  357. return expr; \
  358. }
  359. /* Returns the new value */
  360. #ifdef STARPU_HAVE_SYNC_FETCH_AND_ADD
  361. #define STARPU_ATOMIC_ADD(ptr, value) (__sync_fetch_and_add ((ptr), (value)) + (value))
  362. #define STARPU_ATOMIC_ADDL(ptr, value) (__sync_fetch_and_add ((ptr), (value)) + (value))
  363. #else
  364. #if defined(STARPU_HAVE_XCHG)
  365. STARPU_ATOMIC_SOMETHING(add, old + value)
  366. #define STARPU_ATOMIC_ADD(ptr, value) starpu_atomic_add(ptr, value)
  367. #endif
  368. #if defined(STARPU_HAVE_XCHGL)
  369. STARPU_ATOMIC_SOMETHINGL(add, old + value)
  370. #define STARPU_ATOMIC_ADDL(ptr, value) starpu_atomic_addl(ptr, value)
  371. #endif
  372. #endif
  373. #ifdef STARPU_HAVE_SYNC_FETCH_AND_OR
  374. #define STARPU_ATOMIC_OR(ptr, value) (__sync_fetch_and_or ((ptr), (value)))
  375. #define STARPU_ATOMIC_ORL(ptr, value) (__sync_fetch_and_or ((ptr), (value)))
  376. #else
  377. #if defined(STARPU_HAVE_XCHG)
  378. STARPU_ATOMIC_SOMETHING(or, old | value)
  379. #define STARPU_ATOMIC_OR(ptr, value) starpu_atomic_or(ptr, value)
  380. #endif
  381. #if defined(STARPU_HAVE_XCHGL)
  382. STARPU_ATOMIC_SOMETHINGL(or, old | value)
  383. #define STARPU_ATOMIC_ORL(ptr, value) starpu_atomic_orl(ptr, value)
  384. #endif
  385. #endif
  386. #ifdef STARPU_HAVE_SYNC_BOOL_COMPARE_AND_SWAP
  387. #define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (__sync_bool_compare_and_swap ((ptr), (old), (value)))
  388. #elif defined(STARPU_HAVE_XCHG)
  389. #define STARPU_BOOL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)) == (old))
  390. #endif
  391. #ifdef STARPU_HAVE_SYNC_VAL_COMPARE_AND_SWAP
  392. #define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (__sync_val_compare_and_swap ((ptr), (old), (value)))
  393. #elif defined(STARPU_HAVE_XCHG)
  394. #define STARPU_VAL_COMPARE_AND_SWAP(ptr, old, value) (starpu_cmpxchg((ptr), (old), (value)))
  395. #endif
  396. /* Returns the previous value */
  397. #ifdef STARPU_HAVE_SYNC_LOCK_TEST_AND_SET
  398. #define STARPU_TEST_AND_SET(ptr, value) (__sync_lock_test_and_set ((ptr), (value)))
  399. #define STARPU_RELEASE(ptr) (__sync_lock_release ((ptr)))
  400. #elif defined(STARPU_HAVE_XCHG)
  401. #define STARPU_TEST_AND_SET(ptr, value) (starpu_xchg((ptr), (value)))
  402. #define STARPU_RELEASE(ptr) (starpu_xchg((ptr), 0))
  403. #endif
  404. #ifdef STARPU_HAVE_SYNC_SYNCHRONIZE
  405. #define STARPU_SYNCHRONIZE() __sync_synchronize()
  406. #elif defined(__i386__)
  407. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  408. #elif defined(__KNC__) || defined(__KNF__)
  409. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  410. #elif defined(__x86_64__)
  411. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("mfence" ::: "memory")
  412. #elif defined(__ppc__) || defined(__ppc64__)
  413. #define STARPU_SYNCHRONIZE() __asm__ __volatile__("sync" ::: "memory")
  414. #endif
  415. /**
  416. This macro can be used to do a synchronization.
  417. */
  418. #if defined(__i386__)
  419. #define STARPU_RMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  420. #elif defined(__KNC__) || defined(__KNF__)
  421. #define STARPU_RMB() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  422. #elif defined(__x86_64__)
  423. #define STARPU_RMB() __asm__ __volatile__("lfence" ::: "memory")
  424. #elif defined(__ppc__) || defined(__ppc64__)
  425. #define STARPU_RMB() __asm__ __volatile__("sync" ::: "memory")
  426. #else
  427. #define STARPU_RMB() STARPU_SYNCHRONIZE()
  428. #endif
  429. /**
  430. This macro can be used to do a synchronization.
  431. */
  432. #if defined(__i386__)
  433. #define STARPU_WMB() __asm__ __volatile__("lock; addl $0,0(%%esp)" ::: "memory")
  434. #elif defined(__KNC__) || defined(__KNF__)
  435. #define STARPU_WMB() __asm__ __volatile__("lock; addl $0,0(%%rsp)" ::: "memory")
  436. #elif defined(__x86_64__)
  437. #define STARPU_WMB() __asm__ __volatile__("sfence" ::: "memory")
  438. #elif defined(__ppc__) || defined(__ppc64__)
  439. #define STARPU_WMB() __asm__ __volatile__("sync" ::: "memory")
  440. #else
  441. #define STARPU_WMB() STARPU_SYNCHRONIZE()
  442. #endif
  443. #ifdef _WIN32
  444. /* Try to fetch the system definition of timespec */
  445. #include <sys/types.h>
  446. #include <sys/stat.h>
  447. #ifdef HAVE_UNISTD_H
  448. #include <unistd.h>
  449. #endif
  450. #include <time.h>
  451. #if !defined(_MSC_VER) || defined(BUILDING_STARPU)
  452. #include <pthread.h>
  453. #endif
  454. #if !defined(STARPU_HAVE_STRUCT_TIMESPEC) || (defined(_MSC_VER) && _MSC_VER < 1900)
  455. /* If it didn't get defined in the standard places, then define it ourself */
  456. #ifndef STARPU_TIMESPEC_DEFINED
  457. #define STARPU_TIMESPEC_DEFINED 1
  458. struct timespec
  459. {
  460. time_t tv_sec; /* Seconds */
  461. long tv_nsec; /* Nanoseconds */
  462. };
  463. #endif /* STARPU_TIMESPEC_DEFINED */
  464. #endif /* STARPU_HAVE_STRUCT_TIMESPEC */
  465. /* Fetch gettimeofday on mingw/cygwin */
  466. #if defined(__MINGW32__) || defined(__CYGWIN__)
  467. #include <sys/time.h>
  468. #endif
  469. #else
  470. #include <sys/time.h>
  471. #endif /* _WIN32 */
  472. /** @} */
  473. #ifdef __cplusplus
  474. }
  475. #endif
  476. #endif /* __STARPU_UTIL_H__ */