nlib
Platform_cafe.h
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
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 #include <ppc_ps.h>
33 #include <cafe/os.h>
34 #include <stdint.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifndef NLIB_CAFE_PPC
41 #define NLIB_CAFE_PPC
42 #endif
43 #define NLIB_ALWAYS_INLINE inline __attribute__((always_inline))
44 #define NLIB_NEVER_INLINE __attribute__((__noinline__))
45 #ifdef __cplusplus
46 #define NLIB_LIKELY(x) __builtin_expect(!!(x), 1)
47 #define NLIB_UNLIKELY(x) __builtin_expect(!!(x), 0)
48 #else
49 #define NLIB_LIKELY(x) (x)
50 #define NLIB_UNLIKELY(x) (x)
51 #endif
52 #define NLIB_EXPECT(var, exp_value) __builtin_expect((var), (exp_value))
53 // ghs warns even if (void)func(); written
54 #define NLIB_CHECK_RESULT
55 // #define NLIB_CHECK_RESULT __attribute__((warn_unused_result))
56 #define NLIB_NORETURN __attribute__((noreturn))
57 #define NLIB_FALLTHROUGH
58 #define NLIB_NONNULL __attribute__((nonnull))
59 #define NLIB_NONNULL_1 __attribute__((nonnull(1)))
60 #define NLIB_NONNULL_2 __attribute__((nonnull(2)))
61 #define NLIB_NONNULL_3 __attribute__((nonnull(3)))
62 #define NLIB_NONNULL_4 __attribute__((nonnull(4)))
63 #define NLIB_NONNULL_5 __attribute__((nonnull(5)))
64 #define NLIB_NONNULL_ENABLED
65 #define NLIB_ATTRIBUTE_MALLOC __attribute__((malloc))
66 #define NLIB_ATTRIBUTE_PURE __attribute__((pure))
67 #define NLIB_ATTRIBUTE_CONST __attribute__((const))
68 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n)
69 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1)
70 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn)
71 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n)
72 #ifndef NLIB_DEPRECATED
73 #define NLIB_DEPRECATED __attribute__((deprecated))
74 #endif
75 #ifndef NLIB_DEPRECATED_MSG
76 #define NLIB_DEPRECATED_MSG(msg) __attribute__((deprecated))
77 #endif
78 #define NLIB_VIS_HIDDEN
79 #define NLIB_VIS_PUBLIC
80 #define NLIB_WEAKSYMBOL __attribute__((weak))
81 
82 #define NLIB_MEMORY_ORDER_RELEASE __LWSYNC()
83 #define NLIB_MEMORY_ORDER_ACQUIRE __ISYNC()
84 #define NLIB_MEMORY_ORDER_ACQ_REL \
85  __LWSYNC(); \
86  __ISYNC()
87 #define NLIB_MEMORY_ORDER_SEQ_CST OSCoherencyBarrier()
88 
89 // GHS does not support '%zu', and cafe is 32bit environment
90 #define __PRIS_PREFIX
91 
92 typedef unsigned int nlib_tls;
93 
94 typedef OSFastMutex nlib_mutex;
95 #define NLIB_MUTEX_INITIALIZER \
96  { 0 }
97 #define NLIB_RECURSIVE_MUTEX_INITIALIZER \
98  { 0 }
99 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER \
100  { 0 }
101 
102 typedef void* nlib_thread;
103 
104 typedef OSSemaphore nlib_semaphore;
105 
106 typedef OSFastCond nlib_cond;
107 #define NLIB_COND_INITIALIZER \
108  { 0 }
109 
110 void MyNoreturn_(void) __attribute__((noreturn));
111 #define NLIB_ASSUME(cond) \
112  switch (0) \
113  case 0: \
114  default: \
115  if (cond) \
116  ; \
117  else \
118  MyNoreturn_()
119 
120 #define NLIB_ATOMIC_RELAXED (0)
121 #define NLIB_ATOMIC_ACQUIRE (1)
122 #define NLIB_ATOMIC_RELEASE (2)
123 #define NLIB_ATOMIC_ACQ_REL (3)
124 #define NLIB_ATOMIC_SEQ_CST (7)
125 
126 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_load32(const int32_t* ptr, int memorder) {
127  int32_t rval = *(volatile int32_t*)ptr;
129  return rval;
130 }
131 
132 static NLIB_ALWAYS_INLINE void nlib_atomic_store32(int32_t* ptr, int32_t val, int memorder) {
133  if (memorder == NLIB_ATOMIC_SEQ_CST)
134  OSCoherencyBarrier();
135  else if (memorder & NLIB_ATOMIC_RELEASE)
137  *(volatile int32_t*)ptr = val;
138  if (memorder == NLIB_ATOMIC_SEQ_CST) OSCoherencyBarrier();
139 }
140 
141 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_exchange32(int32_t* ptr, int32_t val, int memorder) {
142  uint32_t x;
143  if (memorder == NLIB_ATOMIC_SEQ_CST)
144  OSCoherencyBarrier();
145  else if (memorder & NLIB_ATOMIC_RELEASE)
147  x = OSSwapAtomic((volatile OSAtomicVar*)ptr, (uint32_t)val);
149  return (int32_t)x;
150 }
151 
152 static __inline void* nlib_atomic_exchangeptr(void** ptr, void* val, int memorder) {
153  return (void*)nlib_atomic_exchange32((int32_t*)ptr, (int32_t)val, memorder);
154 }
155 
156 static NLIB_ALWAYS_INLINE int
157 nlib_atomic_compare_exchange32(int32_t* ptr, int32_t* expected, int32_t desired, int weak,
158  int success_memorder, int failure_memorder) {
159  if (success_memorder == NLIB_ATOMIC_SEQ_CST)
160  OSCoherencyBarrier();
161  else if (success_memorder & NLIB_ATOMIC_RELEASE)
163  if (weak == 0) {
164  BOOL result = OSCompareAndSwapAtomicEx((volatile OSAtomicVar*)ptr, (u32)*expected,
165  (u32)desired, (u32*)expected);
166  if (result) {
167  if (success_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
168  } else {
169  if (failure_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
170  }
171  return result;
172  } else {
173  u32 orig_val;
174  orig_val = (u32)__LWARX((u32*)ptr, 0);
175  if (orig_val == *expected) {
176  __DCBST(0, (u32)ptr);
177  if (__STWCX((u32*)ptr, 0, (u32)desired)) {
178  if (success_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
179  return 1;
180  }
181  if (failure_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
182  return 0;
183  } else {
184  *expected = (int32_t)orig_val;
185  if (failure_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_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, int memorder) {
192  int32_t x;
193  if (memorder == NLIB_ATOMIC_SEQ_CST)
194  OSCoherencyBarrier();
195  else if (memorder & NLIB_ATOMIC_RELEASE)
197  x = OSAddAtomic((volatile OSAtomicVar*)ptr, val);
199  return x + val;
200 }
201 
202 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_sub_fetch32(int32_t* ptr, int32_t val, int memorder) {
203  int32_t x;
204  if (memorder == NLIB_ATOMIC_SEQ_CST)
205  OSCoherencyBarrier();
206  else if (memorder & NLIB_ATOMIC_RELEASE)
208  x = OSAddAtomic((volatile OSAtomicVar*)ptr, -val);
210  return x - val;
211 }
212 
213 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_and_fetch32(int32_t* ptr, int32_t val, int memorder) {
214  int32_t x;
215  if (memorder == NLIB_ATOMIC_SEQ_CST)
216  OSCoherencyBarrier();
217  else if (memorder & NLIB_ATOMIC_RELEASE)
219  x = OSAndAtomic((volatile OSAtomicVar*)ptr, val);
221  return x & val;
222 }
223 
224 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_xor_fetch32(int32_t* ptr, int32_t val, int memorder) {
225  int32_t x;
226  if (memorder == NLIB_ATOMIC_SEQ_CST)
227  OSCoherencyBarrier();
228  else if (memorder & NLIB_ATOMIC_RELEASE)
230  x = OSXorAtomic((volatile OSAtomicVar*)ptr, val);
232  return x ^ val;
233 }
234 
235 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_or_fetch32(int32_t* ptr, int32_t val, int memorder) {
236  int32_t x;
237  if (memorder == NLIB_ATOMIC_SEQ_CST)
238  OSCoherencyBarrier();
239  else if (memorder & NLIB_ATOMIC_RELEASE)
241  x = OSOrAtomic((volatile OSAtomicVar*)ptr, val);
243  return x | val;
244 }
245 
246 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_add32(int32_t* ptr, int32_t val, int memorder) {
247  int32_t x;
248  if (memorder == NLIB_ATOMIC_SEQ_CST)
249  OSCoherencyBarrier();
250  else if (memorder & NLIB_ATOMIC_RELEASE)
252  x = OSAddAtomic((volatile OSAtomicVar*)ptr, val);
254  return x;
255 }
256 
257 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_sub32(int32_t* ptr, int32_t val, 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);
265  return x;
266 }
267 
268 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_and32(int32_t* ptr, int32_t val, int memorder) {
269  int32_t x;
270  if (memorder == NLIB_ATOMIC_SEQ_CST)
271  OSCoherencyBarrier();
272  else if (memorder & NLIB_ATOMIC_RELEASE)
274  x = OSAndAtomic((volatile OSAtomicVar*)ptr, val);
276  return x;
277 }
278 
279 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_xor32(int32_t* ptr, int32_t val, int memorder) {
280  int32_t x;
281  if (memorder == NLIB_ATOMIC_SEQ_CST)
282  OSCoherencyBarrier();
283  else if (memorder & NLIB_ATOMIC_RELEASE)
285  x = OSXorAtomic((volatile OSAtomicVar*)ptr, val);
287  return x;
288 }
289 
290 static NLIB_ALWAYS_INLINE int32_t nlib_atomic_fetch_or32(int32_t* ptr, int32_t val, int memorder) {
291  int32_t x;
292  if (memorder == NLIB_ATOMIC_SEQ_CST)
293  OSCoherencyBarrier();
294  else if (memorder & NLIB_ATOMIC_RELEASE)
296  x = OSOrAtomic((volatile OSAtomicVar*)ptr, val);
298  return x;
299 }
300 
301 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_load64(const int64_t* ptr, int memorder) {
302  int64_t rval = (int64_t)OSGetAtomic64((volatile OSAtomicVar64*)ptr);
304  return rval;
305 }
306 
307 static NLIB_ALWAYS_INLINE void nlib_atomic_store64(int64_t* ptr, int64_t val, int memorder) {
308  if (memorder == NLIB_ATOMIC_SEQ_CST)
309  OSCoherencyBarrier();
310  else if (memorder & NLIB_ATOMIC_RELEASE)
312  OSSetAtomic64((volatile OSAtomicVar64*)ptr, (u64)val);
313  if (memorder == NLIB_ATOMIC_SEQ_CST) OSCoherencyBarrier();
314 }
315 
316 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_exchange64(int64_t* ptr, int64_t val, int memorder) {
317  uint64_t x;
318  if (memorder == NLIB_ATOMIC_SEQ_CST)
319  OSCoherencyBarrier();
320  else if (memorder & NLIB_ATOMIC_RELEASE)
322  x = OSSwapAtomic64((volatile OSAtomicVar64*)ptr, (uint64_t)val);
324  return (int64_t)x;
325 }
326 
327 static NLIB_ALWAYS_INLINE int
328 nlib_atomic_compare_exchange64(int64_t* ptr, int64_t* expected, int64_t desired, int weak,
329  int success_memorder, int failure_memorder) {
330  BOOL result;
331  (void)weak;
332  if (success_memorder == NLIB_ATOMIC_SEQ_CST)
333  OSCoherencyBarrier();
334  else if (success_memorder & NLIB_ATOMIC_RELEASE)
336 
337  result = OSCompareAndSwapAtomicEx64((volatile OSAtomicVar64*)ptr, (u64)*expected, (u64)desired,
338  (u64*)expected);
339  if (result) {
340  if (success_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
341  } else {
342  if (failure_memorder & NLIB_ATOMIC_ACQUIRE) NLIB_MEMORY_ORDER_ACQUIRE;
343  }
344  return result;
345 }
346 
347 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_add_fetch64(int64_t* ptr, int64_t val, int memorder) {
348  int64_t x;
349  if (memorder == NLIB_ATOMIC_SEQ_CST)
350  OSCoherencyBarrier();
351  else if (memorder & NLIB_ATOMIC_RELEASE)
353  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, val);
355  return x + val;
356 }
357 
358 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_sub_fetch64(int64_t* ptr, int64_t val, int memorder) {
359  int64_t x;
360  if (memorder == NLIB_ATOMIC_SEQ_CST)
361  OSCoherencyBarrier();
362  else if (memorder & NLIB_ATOMIC_RELEASE)
364  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, -val);
366  return x - val;
367 }
368 
369 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_and_fetch64(int64_t* ptr, int64_t val, int memorder) {
370  int64_t x;
371  if (memorder == NLIB_ATOMIC_SEQ_CST)
372  OSCoherencyBarrier();
373  else if (memorder & NLIB_ATOMIC_RELEASE)
375  x = OSAndAtomic64((volatile OSAtomicVar64*)ptr, val);
377  return x & val;
378 }
379 
380 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_xor_fetch64(int64_t* ptr, int64_t val, int memorder) {
381  int64_t x;
382  if (memorder == NLIB_ATOMIC_SEQ_CST)
383  OSCoherencyBarrier();
384  else if (memorder & NLIB_ATOMIC_RELEASE)
386  x = OSXorAtomic64((volatile OSAtomicVar64*)ptr, val);
388  return x ^ val;
389 }
390 
391 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_or_fetch64(int64_t* ptr, int64_t val, int memorder) {
392  int64_t x;
393  if (memorder == NLIB_ATOMIC_SEQ_CST)
394  OSCoherencyBarrier();
395  else if (memorder & NLIB_ATOMIC_RELEASE)
397  x = OSOrAtomic64((volatile OSAtomicVar64*)ptr, val);
399  return x | val;
400 }
401 
402 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_add64(int64_t* ptr, int64_t val, int memorder) {
403  int64_t x;
404  if (memorder == NLIB_ATOMIC_SEQ_CST)
405  OSCoherencyBarrier();
406  else if (memorder & NLIB_ATOMIC_RELEASE)
408  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, val);
410  return x;
411 }
412 
413 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_sub64(int64_t* ptr, int64_t val, int memorder) {
414  int64_t x;
415  if (memorder == NLIB_ATOMIC_SEQ_CST)
416  OSCoherencyBarrier();
417  else if (memorder & NLIB_ATOMIC_RELEASE)
419  x = OSAddAtomic64((volatile OSAtomicVar64*)ptr, -val);
421  return x;
422 }
423 
424 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_and64(int64_t* ptr, int64_t val, int memorder) {
425  int64_t x;
426  if (memorder == NLIB_ATOMIC_SEQ_CST)
427  OSCoherencyBarrier();
428  else if (memorder & NLIB_ATOMIC_RELEASE)
430  x = OSAndAtomic64((volatile OSAtomicVar64*)ptr, val);
432  return x;
433 }
434 
435 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_xor64(int64_t* ptr, int64_t val, int memorder) {
436  int64_t x;
437  if (memorder == NLIB_ATOMIC_SEQ_CST)
438  OSCoherencyBarrier();
439  else if (memorder & NLIB_ATOMIC_RELEASE)
441  x = OSXorAtomic64((volatile OSAtomicVar64*)ptr, val);
443  return x;
444 }
445 
446 static NLIB_ALWAYS_INLINE int64_t nlib_atomic_fetch_or64(int64_t* ptr, int64_t val, int memorder) {
447  int64_t x;
448  if (memorder == NLIB_ATOMIC_SEQ_CST)
449  OSCoherencyBarrier();
450  else if (memorder & NLIB_ATOMIC_RELEASE)
452  x = OSOrAtomic64((volatile OSAtomicVar64*)ptr, val);
454  return x;
455 }
456 
457 static NLIB_ALWAYS_INLINE void* nlib_atomic_loadptr(void* const* ptr, int memorder) {
458  void* rval = *(void* volatile*)ptr;
460  return rval;
461 }
462 
463 static NLIB_ALWAYS_INLINE void nlib_atomic_storeptr(void** ptr, void* val, int memorder) {
464  if (memorder == NLIB_ATOMIC_SEQ_CST)
465  OSCoherencyBarrier();
466  else if (memorder & NLIB_ATOMIC_RELEASE)
468  *(void* volatile*)ptr = val;
469  if (memorder == NLIB_ATOMIC_SEQ_CST) OSCoherencyBarrier();
470 }
471 
472 static NLIB_ALWAYS_INLINE int
473 nlib_atomic_compare_exchangeptr(void** ptr, void** expected, void* desired, int weak,
474  int success_memorder, int failure_memorder) {
475  return nlib_atomic_compare_exchange32((int32_t*)ptr, (int32_t*)expected, (int32_t)desired, weak,
476  success_memorder, failure_memorder);
477 }
478 
479 static NLIB_ALWAYS_INLINE void nlib_atomic_thread_fence(int memorder) {
480  switch (memorder) {
481  case NLIB_ATOMIC_RELAXED:
482  break;
483  case NLIB_ATOMIC_ACQUIRE:
485  break;
486  case NLIB_ATOMIC_RELEASE:
488  break;
489  case NLIB_ATOMIC_ACQ_REL:
491  break;
492  default:
494  break;
495  }
496 }
497 
498 #define NLIB_FD_O_RDONLY (0x0000)
499 #define NLIB_FD_O_WRONLY (0x0001)
500 #define NLIB_FD_O_RDWR (0x0002)
501 #define NLIB_FD_O_APPEND (0x0008)
502 #define NLIB_FD_O_CREAT (0x0100)
503 #define NLIB_FD_O_TRUNC (0x0200)
504 #define NLIB_FD_O_EXCL (0x0400)
505 
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 #define NLIB_NOEXCEPT
511 
512 // --restrict is not specified in SDK's configuration
513 #ifndef __cplusplus
514 #define __restrict
515 #endif
516 
517 #define NLIB_MEMCPY(a, b, c) OSBlockMove((a), (b), (c), FALSE)
518 #define NLIB_MEMMOVE(a, b, c) OSBlockMove((a), (b), (c), FALSE)
519 #define NLIB_MEMSET(a, b, c) OSBlockSet((a), (b), (c))
520 
521 #ifndef NLIB_HAS_ZLIB
522 #define NLIB_HAS_ZLIB
523 #endif
524 
525 #ifndef NLIB_HAS_LIBCURL
526 #define NLIB_HAS_LIBCURL
527 #endif
528 
529 #endif
530 #endif // INCLUDE_NN_NLIB_PLATFORM_CAFE_H_
int32_t nlib_atomic_xor_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の排他的論理和の計算を行います。動作はgccの__atomic_xor_fetch()に準じます。 ...
int64_t nlib_atomic_fetch_and64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の論理積の計算を行います。動作はgccの__atomic_fetch_and()に準じます。 ...
void * nlib_atomic_exchangeptr(void **ptr, void *val, int memorder)
アトミックに値を入れ替えます。動作はgccの__atomic_exchange_n()に準じます。
int nlib_atomic_compare_exchangeptr(void **ptr, void **expected, void *desired, int weak, int success_memorder, int failure_memorder)
アトミックな値の比較と入れ替えを行います。動作はgccの__atomic_compare_exchange_n()に準じます。 ...
int32_t nlib_atomic_load32(const int32_t *ptr, int memorder)
アトミックに値をロードします。動作はgccの__atomic_load_n()に準じます。
#define NLIB_ALWAYS_INLINE
コンパイラに関数をインライン展開するように強く示します。
Definition: Platform_unix.h:95
int64_t nlib_atomic_fetch_add64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の加算を行います。動作はgccの__atomic_fetch_add()に準じます。
sem_t nlib_semaphore
セマフォオブジェクトの型です。
#define NLIB_MEMORY_ORDER_ACQUIRE
メモリフェンスです。C++11ではatomic_thread_fence(memory_order_acquire)に一致します。 ...
#define NLIB_ATOMIC_RELEASE
gccの__ATOMIC_RELEASEやC++11のstd::memory_order_releaseに準じます。
int32_t nlib_atomic_or_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_or_fetch()に準じます。 ...
int64_t nlib_atomic_fetch_sub64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の減算を行います。動作はgccの__atomic_fetch_sub()に準じます。
int64_t nlib_atomic_and_fetch64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の論理積の計算を行います。動作はgccの__atomic_and_fetch()に準じます。 ...
int nlib_atomic_compare_exchange64(int64_t *ptr, int64_t *expected, int64_t desired, int weak, int success_memorder, int failure_memorder)
アトミックな値の比較と入れ替えを行います。動作はgccの__atomic_compare_exchange_n()に準じます。 ...
int64_t nlib_atomic_fetch_or64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_fetch_or()に準じます。 ...
#define NLIB_ATOMIC_ACQ_REL
gccの__ATOMIC_ACQ_RELやC++11のstd::memory_order_acq_relに準じます。
#define NLIB_ATOMIC_ACQUIRE
gccの__ATOMIC_ACQUIREやC++11のstd::memory_order_acquireに準じます。
pthread_key_t nlib_tls
TLSスロットのIDを示す型です。
void * nlib_atomic_loadptr(void *const *ptr, int memorder)
アトミックに値をロードします。動作はgccの__atomic_load_n()に準じます。
int64_t nlib_atomic_exchange64(int64_t *ptr, int64_t val, int memorder)
アトミックに値を入れ替えます。動作はgccの__atomic_exchange_n()に準じます。
#define NLIB_MEMORY_ORDER_SEQ_CST
メモリフェンスです。C++11ではatomic_thread_fence(memory_order_seq_cst)に一致します。 ...
int64_t nlib_atomic_sub_fetch64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の減算を行います。動作はgccの__atomic_sub_fetch()に準じます。
int32_t nlib_atomic_fetch_xor32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の排他的論理和の計算を行います。動作はgccの__atomic_fetch_xor()に準じます。 ...
#define NLIB_MEMORY_ORDER_ACQ_REL
メモリフェンスです。C++11ではatomic_thread_fence(memory_order_acq_rel)に一致します。 ...
int32_t nlib_atomic_sub_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の減算を行います。動作はgccの__atomic_sub_fetch()に準じます。
int32_t nlib_atomic_fetch_sub32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の減算を行います。動作はgccの__atomic_fetch_sub()に準じます。
int32_t nlib_atomic_add_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の加算を行います。動作はgccの__atomic_add_fetch()に準じます。
void nlib_atomic_storeptr(void **ptr, void *val, int memorder)
アトミックに値をストアします。動作はgccの__atomic_store_n()に準じます。
void nlib_atomic_thread_fence(int memorder)
指定されたメモリバリアを配置します。
int32_t nlib_atomic_fetch_and32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の論理積の計算を行います。動作はgccの__atomic_fetch_and()に準じます。 ...
pthread_cond_t nlib_cond
条件変数オブジェクトの型です。
#define NLIB_ATOMIC_RELAXED
gccの__ATOMIC_RELAXEDやC++11のstd::memory_order_relaxedに準じます。
pthread_mutex_t nlib_mutex
ミューテックス変数の型です。
int64_t nlib_atomic_xor_fetch64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の排他的論理和の計算を行います。動作はgccの__atomic_xor_fetch()に準じます。 ...
#define NLIB_MEMORY_ORDER_RELEASE
メモリフェンスです。C++11ではatomic_thread_fence(memory_order_release)に一致します。 ...
int64_t nlib_atomic_add_fetch64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の加算を行います。動作はgccの__atomic_add_fetch()に準じます。
int32_t nlib_atomic_and_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の論理積の計算を行います。動作はgccの__atomic_and_fetch()に準じます。 ...
int nlib_atomic_compare_exchange32(int32_t *ptr, int32_t *expected, int32_t desired, int weak, int success_memorder, int failure_memorder)
アトミックな値の比較と入れ替えを行います。動作はgccの__atomic_compare_exchange_n()に準じます。 ...
void nlib_atomic_store64(int64_t *ptr, int64_t val, int memorder)
アトミックに値をストアします。動作はgccの__atomic_store_n()に準じます。
int64_t nlib_atomic_or_fetch64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_or_fetch()に準じます。 ...
#define NLIB_ATOMIC_SEQ_CST
gccの__ATOMIC_SEQ_CSTやC++11のstd::memory_order_seq_cstに準じます。
int32_t nlib_atomic_fetch_or32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_fetch_or()に準じます。 ...
int64_t nlib_atomic_fetch_xor64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の排他的論理和の計算を行います。動作はgccの__atomic_fetch_xor()に準じます。 ...
int32_t nlib_atomic_fetch_add32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の加算を行います。動作はgccの__atomic_fetch_add()に準じます。
void nlib_atomic_store32(int32_t *ptr, int32_t val, int memorder)
アトミックに値をストアします。動作はgccの__atomic_store_n()に準じます。
int32_t nlib_atomic_exchange32(int32_t *ptr, int32_t val, int memorder)
アトミックに値を入れ替えます。動作はgccの__atomic_exchange_n()に準じます。
pthread_t nlib_thread
スレッドを指し示す識別子
int64_t nlib_atomic_load64(const int64_t *ptr, int memorder)
アトミックに値をロードします。動作はgccの__atomic_load_n()に準じます。