nlib
Platform_cafe.h
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
13  *---------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_PLATFORM_CAFE_H_
17 #define INCLUDE_NN_NLIB_PLATFORM_CAFE_H_
18 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_
19 # error do not include directly
20 #endif
21 #ifdef CAFE
22 
23 #ifdef __cplusplus
24 #ifndef __STDC_LIMIT_MACROS
25 #define __STDC_LIMIT_MACROS
26 #endif
27 #ifndef __STDC_CONSTANT_MACROS
28 #define __STDC_CONSTANT_MACROS
29 #endif
30 #endif
31 
32 #define NLIB_HAS_STDHEADER_INTTYPES
33 
34 #include <ppc_ps.h>
35 #include <cafe/os.h>
36 #include <stdint.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #ifndef NLIB_CAFE_PPC
43 # define NLIB_CAFE_PPC
44 #endif
45 #define NLIB_ALWAYS_INLINE inline __attribute__((always_inline))
46 #define NLIB_NEVER_INLINE __attribute__((__noinline__))
47 #ifdef __cplusplus
48 #define NLIB_LIKELY(x) __builtin_expect(!!(x), 1)
49 #define NLIB_UNLIKELY(x) __builtin_expect(!!(x), 0)
50 #else
51 #define NLIB_LIKELY(x) (x)
52 #define NLIB_UNLIKELY(x) (x)
53 #endif
54 #define NLIB_EXPECT(var, exp_value) __builtin_expect((var), (exp_value))
55 #define NLIB_CHECK_RESULT __attribute__((warn_unused_result))
56 #define NLIB_NORETURN __attribute__((noreturn))
57 #define NLIB_NONNULL __attribute__((nonnull))
58 #define NLIB_NONNULL_1 __attribute__((nonnull (1)))
59 #define NLIB_NONNULL_2 __attribute__((nonnull (2)))
60 #define NLIB_NONNULL_3 __attribute__((nonnull (3)))
61 #define NLIB_NONNULL_4 __attribute__((nonnull (4)))
62 #define NLIB_NONNULL_5 __attribute__((nonnull (5)))
63 #define NLIB_NONNULL_ENABLED
64 #define NLIB_ATTRIBUTE_MALLOC __attribute__((malloc))
65 #define NLIB_ATTRIBUTE_PURE __attribute__((pure))
66 #define NLIB_ATTRIBUTE_CONST __attribute__((const))
67 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n)
68 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1)
69 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn)
70 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n)
71 #ifndef NLIB_DEPRECATED
72 #define NLIB_DEPRECATED __attribute__((deprecated))
73 #endif
74 #ifndef NLIB_DEPRECATED_MSG
75 #define NLIB_DEPRECATED_MSG(msg) __attribute__((deprecated))
76 #endif
77 #define NLIB_VIS_HIDDEN
78 #define NLIB_VIS_PUBLIC
79 #define NLIB_WEAKSYMBOL __attribute__((weak))
80 
81 #define NLIB_MEMORY_ORDER_RELEASE __LWSYNC()
82 #define NLIB_MEMORY_ORDER_ACQUIRE __ISYNC()
83 #define NLIB_MEMORY_ORDER_ACQ_REL __LWSYNC(); __ISYNC()
84 #define NLIB_MEMORY_ORDER_SEQ_CST OSCoherencyBarrier()
85 
86 // GHS does not support '%zu', and cafe is 32bit environment
87 #define __PRIS_PREFIX
88 
89 typedef unsigned int nlib_tls;
90 
91 typedef OSFastMutex nlib_mutex;
92 #define NLIB_MUTEX_INITIALIZER {0}
93 #define NLIB_RECURSIVE_MUTEX_INITIALIZER {0}
94 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER {0}
95 
96 typedef void* nlib_thread;
97 
98 typedef OSSemaphore nlib_semaphore;
99 
100 typedef OSFastCond nlib_cond;
101 #define NLIB_COND_INITIALIZER {0}
102 
103 void MyNoreturn_(void) __attribute__((noreturn));
104 #define NLIB_ASSUME(cond) switch (0) case 0: default: if (cond) ; else MyNoreturn_() /* NOLINT */
105 
106 #define NLIB_ATOMIC_RELAXED (0)
107 #define NLIB_ATOMIC_ACQUIRE (1)
108 #define NLIB_ATOMIC_RELEASE (2)
109 #define NLIB_ATOMIC_ACQ_REL (3)
110 #define NLIB_ATOMIC_SEQ_CST (7)
111 
112 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_load32(const int32_t* ptr, int memorder) {
113  int32_t rval = *(volatile int32_t*)ptr; // NOLINT
114  if (memorder & NLIB_ATOMIC_ACQUIRE)
116  return rval;
117 }
118 
119 static NLIB_ALWAYS_INLINE void nlib_atomic_store32(int32_t* ptr, int32_t val,
120  int memorder) {
121  if (memorder == NLIB_ATOMIC_SEQ_CST)
122  OSCoherencyBarrier();
123  else if (memorder & NLIB_ATOMIC_RELEASE)
125  *(volatile int32_t*)ptr = val; // NOLINT
126  if (memorder == NLIB_ATOMIC_SEQ_CST)
127  OSCoherencyBarrier();
128 }
129 
130 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_exchange32(int32_t* ptr, int32_t val,
131  int memorder) {
132  uint32_t x;
133  if (memorder == NLIB_ATOMIC_SEQ_CST)
134  OSCoherencyBarrier();
135  else if (memorder & NLIB_ATOMIC_RELEASE)
137  x = OSSwapAtomic((volatile OSAtomicVar*)ptr, (uint32_t)val); // NOLINT
138  if (memorder & NLIB_ATOMIC_ACQUIRE)
140  return (int32_t)x;
141 }
142 
143 static __inline void* nlib_atomic_exchangeptr(void** ptr, void* val, int memorder) {
144  return (void*)nlib_atomic_exchange32((int32_t*)ptr, (int32_t)val, memorder); // NOLINT
145 }
146 
147 static NLIB_ALWAYS_INLINE int nlib_atomic_compare_exchange32(int32_t* ptr, int32_t* expected,
148  int32_t desired, int weak,
149  int success_memorder,
150  int failure_memorder) {
151  if (success_memorder == NLIB_ATOMIC_SEQ_CST)
152  OSCoherencyBarrier();
153  else if (success_memorder & NLIB_ATOMIC_RELEASE)
155  if (weak == 0) {
156  BOOL result = OSCompareAndSwapAtomicEx(
157  (volatile OSAtomicVar*)ptr, // NOLINT
158  (u32)*expected, // NOLINT
159  (u32)desired, // NOLINT
160  (u32*)expected); // NOLINT
161  if (result) {
162  if (success_memorder & NLIB_ATOMIC_ACQUIRE)
164  } else {
165  if (failure_memorder & NLIB_ATOMIC_ACQUIRE)
167  }
168  return result;
169  } else {
170  u32 orig_val;
171  orig_val = (u32)__LWARX((u32*)ptr, 0);
172  if (orig_val == *expected) {
173  __DCBST(0, (u32)ptr);
174  if (__STWCX((u32*)ptr, 0, (u32)desired)) {
175  if (success_memorder & NLIB_ATOMIC_ACQUIRE)
177  return 1;
178  }
179  if (failure_memorder & NLIB_ATOMIC_ACQUIRE)
181  return 0;
182  } else {
183  *expected = (int32_t)orig_val;
184  if (failure_memorder & NLIB_ATOMIC_ACQUIRE)
186  return 0;
187  }
188  }
189 }
190 
191 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_add_fetch32(int32_t* ptr, int32_t val,
192  int memorder) {
193  int32_t x;
194  if (memorder == NLIB_ATOMIC_SEQ_CST)
195  OSCoherencyBarrier();
196  else if (memorder & NLIB_ATOMIC_RELEASE)
198  x = OSAddAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
199  if (memorder & NLIB_ATOMIC_ACQUIRE)
201  return x + val;
202 }
203 
204 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_sub_fetch32(int32_t* ptr, int32_t val,
205  int memorder) {
206  int32_t x;
207  if (memorder == NLIB_ATOMIC_SEQ_CST)
208  OSCoherencyBarrier();
209  else if (memorder & NLIB_ATOMIC_RELEASE)
211  x = OSAddAtomic((volatile OSAtomicVar*)ptr, -val); // NOLINT
212  if (memorder & NLIB_ATOMIC_ACQUIRE)
214  return x - val;
215 }
216 
217 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_and_fetch32(int32_t* ptr, int32_t val,
218  int memorder) {
219  int32_t x;
220  if (memorder == NLIB_ATOMIC_SEQ_CST)
221  OSCoherencyBarrier();
222  else if (memorder & NLIB_ATOMIC_RELEASE)
224  x = OSAndAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
225  if (memorder & NLIB_ATOMIC_ACQUIRE)
227  return x & val;
228 }
229 
230 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_xor_fetch32(int32_t* ptr, int32_t val,
231  int memorder) {
232  int32_t x;
233  if (memorder == NLIB_ATOMIC_SEQ_CST)
234  OSCoherencyBarrier();
235  else if (memorder & NLIB_ATOMIC_RELEASE)
237  x = OSXorAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
238  if (memorder & NLIB_ATOMIC_ACQUIRE)
240  return x ^ val;
241 }
242 
243 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_or_fetch32(int32_t* ptr, int32_t val,
244  int memorder) {
245  int32_t x;
246  if (memorder == NLIB_ATOMIC_SEQ_CST)
247  OSCoherencyBarrier();
248  else if (memorder & NLIB_ATOMIC_RELEASE)
250  x = OSOrAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
251  if (memorder & NLIB_ATOMIC_ACQUIRE)
253  return x | val;
254 }
255 
256 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_add32(int32_t* ptr, int32_t val,
257  int memorder) {
258  int32_t x;
259  if (memorder == NLIB_ATOMIC_SEQ_CST)
260  OSCoherencyBarrier();
261  else if (memorder & NLIB_ATOMIC_RELEASE)
263  x = OSAddAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
264  if (memorder & NLIB_ATOMIC_ACQUIRE)
266  return x;
267 }
268 
269 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_sub32(int32_t* ptr, int32_t val,
270  int memorder) {
271  int32_t x;
272  if (memorder == NLIB_ATOMIC_SEQ_CST)
273  OSCoherencyBarrier();
274  else if (memorder & NLIB_ATOMIC_RELEASE)
276  x = OSAddAtomic((volatile OSAtomicVar*)ptr, -val); // NOLINT
277  if (memorder & NLIB_ATOMIC_ACQUIRE)
279  return x;
280 }
281 
282 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_and32(int32_t* ptr, int32_t val,
283  int memorder) {
284  int32_t x;
285  if (memorder == NLIB_ATOMIC_SEQ_CST)
286  OSCoherencyBarrier();
287  else if (memorder & NLIB_ATOMIC_RELEASE)
289  x = OSAndAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
290  if (memorder & NLIB_ATOMIC_ACQUIRE)
292  return x;
293 }
294 
295 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_xor32(int32_t* ptr, int32_t val,
296  int memorder) {
297  int32_t x;
298  if (memorder == NLIB_ATOMIC_SEQ_CST)
299  OSCoherencyBarrier();
300  else if (memorder & NLIB_ATOMIC_RELEASE)
302  x = OSXorAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
303  if (memorder & NLIB_ATOMIC_ACQUIRE)
305  return x;
306 }
307 
308 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_or32(int32_t* ptr, int32_t val,
309  int memorder) {
310  int32_t x;
311  if (memorder == NLIB_ATOMIC_SEQ_CST)
312  OSCoherencyBarrier();
313  else if (memorder & NLIB_ATOMIC_RELEASE)
315  x = OSOrAtomic((volatile OSAtomicVar*)ptr, val); // NOLINT
316  if (memorder & NLIB_ATOMIC_ACQUIRE)
318  return x;
319 }
320 
321 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_load64(const int64_t* ptr, int memorder) {
322  int64_t rval = (int64_t)OSGetAtomic64((volatile OSAtomicVar64*)ptr); // NOLINT
323  if (memorder & NLIB_ATOMIC_ACQUIRE)
325  return rval;
326 }
327 
328 static NLIB_ALWAYS_INLINE void nlib_atomic_store64(int64_t* ptr, int64_t val,
329  int memorder) {
330  if (memorder == NLIB_ATOMIC_SEQ_CST)
331  OSCoherencyBarrier();
332  else if (memorder & NLIB_ATOMIC_RELEASE)
334  OSSetAtomic64((volatile OSAtomicVar64*)ptr, (u64)val);
335  if (memorder == NLIB_ATOMIC_SEQ_CST)
336  OSCoherencyBarrier();
337 }
338 
339 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_exchange64(int64_t* ptr, int64_t val,
340  int memorder) {
341  uint64_t x;
342  if (memorder == NLIB_ATOMIC_SEQ_CST)
343  OSCoherencyBarrier();
344  else if (memorder & NLIB_ATOMIC_RELEASE)
346  x = OSSwapAtomic64((volatile OSAtomicVar64*)ptr, (uint64_t)val); // NOLINT
347  if (memorder & NLIB_ATOMIC_ACQUIRE)
349  return (int64_t)x;
350 }
351 
352 static NLIB_ALWAYS_INLINE int nlib_atomic_compare_exchange64(int64_t* ptr, int64_t* expected,
353  int64_t desired, int weak,
354  int success_memorder,
355  int failure_memorder) {
356  BOOL result;
357  (void)weak;
358  if (success_memorder == NLIB_ATOMIC_SEQ_CST)
359  OSCoherencyBarrier();
360  else if (success_memorder & NLIB_ATOMIC_RELEASE)
362 
363  result = OSCompareAndSwapAtomicEx64(
364  (volatile OSAtomicVar64*)ptr, // NOLINT
365  (u64)*expected, // NOLINT
366  (u64)desired, // NOLINT
367  (u64*)expected); // NOLINT
368  if (result) {
369  if (success_memorder & NLIB_ATOMIC_ACQUIRE)
371  } else {
372  if (failure_memorder & NLIB_ATOMIC_ACQUIRE)
374  }
375  return result;
376 }
377 
378 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_add_fetch64(int64_t* ptr, int64_t val,
379  int memorder) {
380  int64_t x;
381  if (memorder == NLIB_ATOMIC_SEQ_CST)
382  OSCoherencyBarrier();
383  else if (memorder & NLIB_ATOMIC_RELEASE)
385  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
386  if (memorder & NLIB_ATOMIC_ACQUIRE)
388  return x + val;
389 }
390 
391 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_sub_fetch64(int64_t* ptr, int64_t val,
392  int memorder) {
393  int64_t x;
394  if (memorder == NLIB_ATOMIC_SEQ_CST)
395  OSCoherencyBarrier();
396  else if (memorder & NLIB_ATOMIC_RELEASE)
398  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, -val); // NOLINT
399  if (memorder & NLIB_ATOMIC_ACQUIRE)
401  return x - val;
402 }
403 
404 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_and_fetch64(int64_t* ptr, int64_t val,
405  int memorder) {
406  int64_t x;
407  if (memorder == NLIB_ATOMIC_SEQ_CST)
408  OSCoherencyBarrier();
409  else if (memorder & NLIB_ATOMIC_RELEASE)
411  x = OSAndAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
412  if (memorder & NLIB_ATOMIC_ACQUIRE)
414  return x & val;
415 }
416 
417 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_xor_fetch64(int64_t* ptr, int64_t val,
418  int memorder) {
419  int64_t x;
420  if (memorder == NLIB_ATOMIC_SEQ_CST)
421  OSCoherencyBarrier();
422  else if (memorder & NLIB_ATOMIC_RELEASE)
424  x = OSXorAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
425  if (memorder & NLIB_ATOMIC_ACQUIRE)
427  return x ^ val;
428 }
429 
430 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_or_fetch64(int64_t* ptr, int64_t val,
431  int memorder) {
432  int64_t x;
433  if (memorder == NLIB_ATOMIC_SEQ_CST)
434  OSCoherencyBarrier();
435  else if (memorder & NLIB_ATOMIC_RELEASE)
437  x = OSOrAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
438  if (memorder & NLIB_ATOMIC_ACQUIRE)
440  return x | val;
441 }
442 
443 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_add64(int64_t* ptr, int64_t val,
444  int memorder) {
445  int64_t x;
446  if (memorder == NLIB_ATOMIC_SEQ_CST)
447  OSCoherencyBarrier();
448  else if (memorder & NLIB_ATOMIC_RELEASE)
450  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
451  if (memorder & NLIB_ATOMIC_ACQUIRE)
453  return x;
454 }
455 
456 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_sub64(int64_t* ptr, int64_t val,
457  int memorder) {
458  int64_t x;
459  if (memorder == NLIB_ATOMIC_SEQ_CST)
460  OSCoherencyBarrier();
461  else if (memorder & NLIB_ATOMIC_RELEASE)
463  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, -val); // NOLINT
464  if (memorder & NLIB_ATOMIC_ACQUIRE)
466  return x;
467 }
468 
469 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_and64(int64_t* ptr, int64_t val,
470  int memorder) {
471  int64_t x;
472  if (memorder == NLIB_ATOMIC_SEQ_CST)
473  OSCoherencyBarrier();
474  else if (memorder & NLIB_ATOMIC_RELEASE)
476  x = OSAndAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
477  if (memorder & NLIB_ATOMIC_ACQUIRE)
479  return x;
480 }
481 
482 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_xor64(int64_t* ptr, int64_t val,
483  int memorder) {
484  int64_t x;
485  if (memorder == NLIB_ATOMIC_SEQ_CST)
486  OSCoherencyBarrier();
487  else if (memorder & NLIB_ATOMIC_RELEASE)
489  x = OSXorAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
490  if (memorder & NLIB_ATOMIC_ACQUIRE)
492  return x;
493 }
494 
495 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_or64(int64_t* ptr, int64_t val,
496  int memorder) {
497  int64_t x;
498  if (memorder == NLIB_ATOMIC_SEQ_CST)
499  OSCoherencyBarrier();
500  else if (memorder & NLIB_ATOMIC_RELEASE)
502  x = OSOrAtomic64((volatile OSAtomicVar64*)ptr, val); // NOLINT
503  if (memorder & NLIB_ATOMIC_ACQUIRE)
505  return x;
506 }
507 
508 static NLIB_ALWAYS_INLINE void* nlib_atomic_loadptr(void* const* ptr, int memorder) {
509  void* rval = *(void* volatile*)ptr; // NOLINT
510  if (memorder & NLIB_ATOMIC_ACQUIRE)
512  return rval;
513 }
514 
515 static NLIB_ALWAYS_INLINE void nlib_atomic_storeptr(void** ptr, void* val, int memorder) {
516  if (memorder == NLIB_ATOMIC_SEQ_CST)
517  OSCoherencyBarrier();
518  else if (memorder & NLIB_ATOMIC_RELEASE)
520  *(void* volatile*)ptr = val; // NOLINT
521  if (memorder == NLIB_ATOMIC_SEQ_CST)
522  OSCoherencyBarrier();
523 }
524 
525 static NLIB_ALWAYS_INLINE int nlib_atomic_compare_exchangeptr(void** ptr, void** expected,
526  void* desired, int weak,
527  int success_memorder,
528  int failure_memorder) {
529  return nlib_atomic_compare_exchange32((int32_t*)ptr, (int32_t*)expected, (int32_t)desired, // NOLINT
530  weak, success_memorder, failure_memorder);
531 }
532 
533 static NLIB_ALWAYS_INLINE void nlib_atomic_thread_fence(int memorder) {
534  switch (memorder) {
535  case NLIB_ATOMIC_RELAXED:
536  break;
537  case NLIB_ATOMIC_ACQUIRE:
539  break;
540  case NLIB_ATOMIC_RELEASE:
542  break;
543  case NLIB_ATOMIC_ACQ_REL:
545  break;
546  default:
548  break;
549  }
550 }
551 
552 #define NLIB_FD_O_RDONLY (0x0000)
553 #define NLIB_FD_O_WRONLY (0x0001)
554 #define NLIB_FD_O_RDWR (0x0002)
555 #define NLIB_FD_O_APPEND (0x0008)
556 #define NLIB_FD_O_CREAT (0x0100)
557 #define NLIB_FD_O_TRUNC (0x0200)
558 #define NLIB_FD_O_EXCL (0x0400)
559 
560 #ifdef __cplusplus
561 }
562 #endif
563 
564 #define NLIB_NOEXCEPT
565 
566 // --restrict is not specified in SDK's configuration
567 #ifndef __cplusplus
568 # define __restrict
569 #endif
570 
571 #define NLIB_MEMCPY(a, b, c) OSBlockMove((a), (b), (c), FALSE)
572 #define NLIB_MEMMOVE(a, b, c) OSBlockMove((a), (b), (c), FALSE)
573 #define NLIB_MEMSET(a, b, c) OSBlockSet((a), (b), (c))
574 
575 #ifndef NLIB_HAS_ZLIB
576 # define NLIB_HAS_ZLIB
577 #endif
578 
579 #ifndef NLIB_HAS_LIBCURL
580 # define NLIB_HAS_LIBCURL
581 #endif
582 
583 #endif
584 #endif // INCLUDE_NN_NLIB_PLATFORM_CAFE_H_
int32_t nlib_atomic_xor_fetch32(int32_t *ptr, int32_t val, int memorder)
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_xor_fetch() of gcc...
int64_t nlib_atomic_fetch_and64(int64_t *ptr, int64_t val, int memorder)
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_fetch_and() of gcc...
void * nlib_atomic_exchangeptr(void **ptr, void *val, int memorder)
Swaps values in an atomic manner. Its behavior is similar to the one for __atomic_exchange_n() of gcc...
int nlib_atomic_compare_exchangeptr(void **ptr, void **expected, void *desired, int weak, int success_memorder, int failure_memorder)
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n(...
int32_t nlib_atomic_load32(const int32_t *ptr, int memorder)
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc...
#define NLIB_ALWAYS_INLINE
Indicates that the compiler is forced to perform inline expansion of functions.
Definition: Platform_unix.h:95
int64_t nlib_atomic_fetch_add64(int64_t *ptr, int64_t val, int memorder)
Adds atomic values. Its behavior is similar to the one for __atomic_fetch_add() of gcc...
sem_t nlib_semaphore
The type for a semaphore object.
#define NLIB_MEMORY_ORDER_ACQUIRE
A memory fence. Corresponds to atomic_thread_fence(memory_order_acquire) in C++11.
#define NLIB_ATOMIC_RELEASE
Similar to __ATOMIC_RELEASE of gcc or std::memory_order_release of C++11.
int32_t nlib_atomic_or_fetch32(int32_t *ptr, int32_t val, int memorder)
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_or_fetch() of gcc...
int64_t nlib_atomic_fetch_sub64(int64_t *ptr, int64_t val, int memorder)
Subtracts atomic values. Its behavior is similar to the one for __atomic_fetch_sub() of gcc...
int64_t nlib_atomic_and_fetch64(int64_t *ptr, int64_t val, int memorder)
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_and_fetch() of gcc...
int nlib_atomic_compare_exchange64(int64_t *ptr, int64_t *expected, int64_t desired, int weak, int success_memorder, int failure_memorder)
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n(...
int64_t nlib_atomic_fetch_or64(int64_t *ptr, int64_t val, int memorder)
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_fetch_or() of gcc...
#define NLIB_ATOMIC_ACQ_REL
Similar to __ATOMIC_ACQ_REL of gcc or std::memory_order_acq_rel of C++11.
#define NLIB_ATOMIC_ACQUIRE
Similar to __ATOMIC_ACQUIRE of gcc or std::memory_order_acquire of C++11.
pthread_key_t nlib_tls
The type for TLS slot IDs.
void * nlib_atomic_loadptr(void *const *ptr, int memorder)
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc...
int64_t nlib_atomic_exchange64(int64_t *ptr, int64_t val, int memorder)
Swaps values in an atomic operation. Its behavior is similar to the one for __atomic_exchange_n() of ...
#define NLIB_MEMORY_ORDER_SEQ_CST
A memory fence. Corresponds to atomic_thread_fence(memory_order_seq_cst) in C++11.
int64_t nlib_atomic_sub_fetch64(int64_t *ptr, int64_t val, int memorder)
Subtracts atomic values. Its behavior is similar to the one for __atomic_sub_fetch() of gcc...
int32_t nlib_atomic_fetch_xor32(int32_t *ptr, int32_t val, int memorder)
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_fetch_xor() of gcc...
#define NLIB_MEMORY_ORDER_ACQ_REL
A memory fence. Corresponds to atomic_thread_fence(memory_order_acq_rel) in C++11.
int32_t nlib_atomic_sub_fetch32(int32_t *ptr, int32_t val, int memorder)
Subtracts atomic values. Its behavior is similar to the one for __atomic_sub_fetch() of gcc...
int32_t nlib_atomic_fetch_sub32(int32_t *ptr, int32_t val, int memorder)
Subtracts atomic values. Its behavior is similar to the one for __atomic_fetch_sub() of gcc...
int32_t nlib_atomic_add_fetch32(int32_t *ptr, int32_t val, int memorder)
Adds atomic values. Its behavior is similar to the one for __atomic_add_fetch() of gcc...
void nlib_atomic_storeptr(void **ptr, void *val, int memorder)
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of g...
void nlib_atomic_thread_fence(int memorder)
Places the specified memory barrier.
int32_t nlib_atomic_fetch_and32(int32_t *ptr, int32_t val, int memorder)
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_fetch_and() of gcc...
pthread_cond_t nlib_cond
The type for a condition variable object.
#define NLIB_ATOMIC_RELAXED
Similar to __ATOMIC_RELAXED of gcc or std::memory_order_relaxed of C++11.
pthread_mutex_t nlib_mutex
The type for mutex variables.
int64_t nlib_atomic_xor_fetch64(int64_t *ptr, int64_t val, int memorder)
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_xor_fetch() of gcc...
#define NLIB_MEMORY_ORDER_RELEASE
A memory fence. Corresponds to atomic_thread_fence(memory_order_release) in C++11.
int64_t nlib_atomic_add_fetch64(int64_t *ptr, int64_t val, int memorder)
Adds atomic values. Its behavior is similar to the one for __atomic_add_fetch() of gcc...
int32_t nlib_atomic_and_fetch32(int32_t *ptr, int32_t val, int memorder)
Calculates AND of atomic values. Its behavior is similar to the one for __atomic_and_fetch() of gcc...
int nlib_atomic_compare_exchange32(int32_t *ptr, int32_t *expected, int32_t desired, int weak, int success_memorder, int failure_memorder)
Compares and swaps atomic values. Its behavior is similar to the one for __atomic_compare_exchange_n(...
void nlib_atomic_store64(int64_t *ptr, int64_t val, int memorder)
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of g...
int64_t nlib_atomic_or_fetch64(int64_t *ptr, int64_t val, int memorder)
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_or_fetch() of gcc...
#define NLIB_ATOMIC_SEQ_CST
Similar to __ATOMIC_SEQ_CST of gcc or std::memory_order_seq_cst of C++11.
int32_t nlib_atomic_fetch_or32(int32_t *ptr, int32_t val, int memorder)
Calculates OR of atomic values. Its behavior is similar to the one for __atomic_fetch_or() of gcc...
int64_t nlib_atomic_fetch_xor64(int64_t *ptr, int64_t val, int memorder)
Calculates XOR of atomic values. Its behavior is similar to the one for __atomic_fetch_xor() of gcc...
int32_t nlib_atomic_fetch_add32(int32_t *ptr, int32_t val, int memorder)
Adds atomic values. Its behavior is similar to the one for __atomic_fetch_add() of gcc...
void nlib_atomic_store32(int32_t *ptr, int32_t val, int memorder)
Stores a value in an atomic operation. Its behavior is similar to the one for __atomic_store_n() of g...
int32_t nlib_atomic_exchange32(int32_t *ptr, int32_t val, int memorder)
Swaps values in an atomic operation. Its behavior is similar to the one for __atomic_exchange_n() of ...
pthread_t nlib_thread
The identifier for threads.
int64_t nlib_atomic_load64(const int64_t *ptr, int memorder)
Loads a value in an atomic operation. Its behavior is similar to the one for __atomic_load_n() of gcc...