nlib
Platform_win32.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_WIN32_H_
17 #define INCLUDE_NN_NLIB_PLATFORM_WIN32_H_
18 #ifndef INCLUDE_NN_NLIB_PLATFORM_H_
19 # error do not include directly
20 #endif
21 
22 #if defined(_MSC_VER)
23 
24 #if !defined(_M_IX86) && !defined(_M_X64) && !defined(_M_AMD64)
25 #error Sorry, not supported
26 #endif
27 
28 #if _MSC_VER < 1800
29 # error Use Visual Studio 2013 or later
30 #endif
31 
32 #ifndef WIN32_LEAN_AND_MEAN
33 # pragma message(__FILE__ ": WIN32_LEAN_AND_MEAN not defined, compile may fail")
34 # define WIN32_LEAN_AND_MEAN
35 #endif
36 
37 #ifndef NOMINMAX
38 # pragma message(__FILE__ ": NOMINMAX not defined, compile may fail")
39 # define NOMINMAX
40 #endif
41 
42 #ifndef _USE_MATH_DEFINES
43 # pragma message(__FILE__ ": _USE_MATH_DEFINES not defined, compile may fail")
44 # define _USE_MATH_DEFINES
45 #endif
46 
47 #ifdef _WIN64
48 # define NLIB_64BIT
49 #endif
50 
51 #include <intrin.h>
52 
53 #pragma intrinsic(_BitScanReverse)
54 #pragma intrinsic(_BitScanForward)
55 #ifdef NLIB_64BIT
56 # pragma intrinsic(_BitScanReverse64)
57 # pragma intrinsic(_BitScanForward64)
58 #endif
59 
60 #include <stdlib.h> // for malloc, free, calloc, realloc
61 #include <limits.h> // for RSIZE_MAX
62 #include <WinSock2.h>
63 #include <MSWsock.h>
64 #include <Windows.h> // for HANDLE, CONDITION_VARIABLE, ....
65 #include <fcntl.h> // for O_RDONLY, O_RDWR, O_CREAT, ....
66 
67 #include <in6addr.h>
68 #include <ws2ipdef.h>
69 
70 #if WINVER < 0x0603
71 # pragma message(__FILE__ ": Please update your Windows SDK")
72 #endif
73 
74 #if (!defined(_M_IX86_FP) || _M_IX86_FP < 2) && !defined(_M_X64) && !defined(_M_AMD64)
75 # error /arch:SSE2 or higher must be set
76 #endif
77 
78 #ifndef NLIB_SSE41
79 # define NLIB_SSE41
80 #endif
81 
82 #ifndef NLIB_SSE42
83 # define NLIB_SSE42
84 #endif
85 
86 // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0096r3.html
87 // http://en.cppreference.com/w/cpp/compiler_support
88 // http://en.cppreference.com/w/User:D41D8CD98F/feature_testing_macros
89 // https://blogs.msdn.microsoft.com/vcblog/2016/01/22/vs-2015-update-2s-stl-is-c17-so-far-feature-complete/
90 #ifdef __cplusplus
91 #define NLIB_CXX11_SWAPHEADER
92 #define NLIB_CXX11_STDLIB_CHRONO
93 #define NLIB_CXX11_STDLIB_ATOMIC
94 #define NLIB_CXX11_STDLIB_ARRAY
95 #define NLIB_CXX11_STDLIB_UNORDERED
96 #define NLIB_CXX11_STDLIB_TUPLE
97 #define NLIB_HAS_NATIVE_TYPETRAITS
98 #define NLIB_CXX11_UNIQUEPTR
99 #define NLIB_CXX11_EXPLICIT_VIRTUAL_OVERRIDES
100 #define NLIB_CXX11_EXPLICIT_CONVERSION_OPERATORS
101 #define NLIB_CXX11_STDLIB_RANDOM
102 #define NLIB_CXX11_DEFAULT_TEMPLATE_ARGUMENT_FOR_FUNCTION_TEMPLATES
103 #define NLIB_CXX11_NULL_POINTER_CONSTANT
104 
105 #define NLIB_CXX11_STATIC_ASSERTIONS
106 #ifndef __cpp_static_assert
107 #define __cpp_static_assert 200410L // N1720
108 #endif
109 
110 #define NLIB_CXX11_RVALUE_REFERENCES
111 #ifndef __cpp_rvalue_references
112 #define __cpp_rvalue_references 200610L // N2118
113 #endif
114 
115 #define NLIB_CXX11_LAMBDAS
116 #ifndef __cpp_lambdas
117 #define __cpp_lambdas 200907L // N2927
118 #endif
119 
120 #define NLIB_CXX11_RANGE_BASED_FOR
121 #ifndef __cpp_range_based_for
122 #define __cpp_range_based_for 200907L // N2930
123 #endif
124 
125 #define NLIB_CXX11_TEMPLATE_ALIAS
126 #ifndef __cpp_alias_templates
127 #define __cpp_alias_templates 200704L // N2258
128 #endif
129 
130 #define NLIB_CXX11_VARIADIC_TEMPLATES
131 #ifndef __cpp_variadic_templates
132 #define __cpp_variadic_templates 200704L // N2242
133 #endif
134 
135 #define NLIB_CXX11_DELEGATING_CONSTRUCTORS
136 #ifndef __cpp_delegating_constructors
137 #define __cpp_delegating_constructors 200604L // N1986
138 #endif
139 
140 #ifndef __cpp_lib_make_unique
141 #define __cpp_lib_make_unique 201304L // N3656
142 #endif
143 #ifndef __cpp_lib_transparent_operators
144 #define __cpp_lib_transparent_operators 201210L // N3421
145 #endif
146 #ifndef __cpp_lib_transformation_trait_aliases
147 #define __cpp_lib_transformation_trait_aliases 201304L // N3655
148 #endif
149 #ifndef __cpp_lib_incomplete_container_elements
150 #define __cpp_lib_incomplete_container_elements 201505L // N4510
151 #endif
152 
153 #if _MSC_VER >= 1900
154 #define NLIB_CXX11_NOEXCEPT
155 #define NLIB_CXX11_ALIGNMENT_SUPPORT
156 #define NLIB_CXX11_DEFAULTED_AND_DELETED_FUNCTIONS
157 
158 #define NLIB_CXX11_CONSTEXPR
159 #ifndef __cpp_constexpr
160 #define __cpp_constexpr 200704 // N2235
161 #endif
162 
163 #define NLIB_CXX11_NEW_CHARACTER_TYPES
164 #ifndef __cpp_unicode_characters
165 #define __cpp_unicode_characters 200704L // N2249
166 #endif
167 
168 // C++11
169 #ifndef __cpp_raw_strings
170 #define __cpp_raw_strings 200710L // N2442
171 #endif
172 #ifndef __cpp_unicode_literals
173 #define __cpp_unicode_literals 200710L // N2442
174 #endif
175 #ifndef __cpp_user_defined_literals
176 #define __cpp_user_defined_literals 200809L // N2765
177 #endif
178 #ifndef __cpp_decltype
179 #define __cpp_decltype 200707L // N2343
180 #endif
181 #ifndef __cpp_attributes
182 #define __cpp_attributes 200809L // N2761
183 #endif
184 #ifndef __cpp_initializer_lists
185 #define __cpp_initializer_lists 200806L // N2672
186 #endif
187 #ifndef __cpp_nsdmi
188 #define __cpp_nsdmi 200809L // N2756
189 #endif
190 #ifndef __cpp_inheriting_constructors
191 #define __cpp_inheriting_constructors 200802L // N2540
192 #endif
193 #ifndef __cpp_ref_qualifiers
194 #define __cpp_ref_qualifiers 200710L // N2439
195 #endif
196 
197 // C++14
198 #ifndef __cpp_binary_literals
199 #define __cpp_binary_literals 201304L // N3472
200 #endif
201 #ifndef __cpp_init_captures
202 #define __cpp_init_captures 201304L // N3648
203 #endif
204 #ifndef __cpp_generic_lambdas
205 #define __cpp_generic_lambdas 201304L // N3649
206 #endif
207 #ifndef __cpp_sized_deallocation
208 #define __cpp_sized_deallocation 201309L // N3778
209 #endif
210 #ifndef __cpp_decltype_auto
211 #define __cpp_decltype_auto 201304L // N3638
212 #endif
213 #ifndef __cpp_return_type_deduction
214 #define __cpp_return_type_deduction 201304L // N3638
215 #endif
216 #ifndef __cpp_variable_templates
217 #define __cpp_variable_templates 201304L // N3651
218 #endif
219 #ifndef __cpp_lib_is_null_pointer
220 #define __cpp_lib_is_null_pointer 201309L // LWG2247
221 #endif
222 #ifndef __cpp_lib_integer_sequence
223 #define __cpp_lib_integer_sequence 201304L // N3658
224 #endif
225 #ifndef __cpp_lib_exchange_function
226 #define __cpp_lib_exchange_function 201304L // N3668
227 #endif
228 #ifndef __cpp_lib_tuples_by_type
229 #define __cpp_lib_tuples_by_type 201304L // N3670
230 #endif
231 #ifndef __cpp_lib_tuple_element_t
232 #define __cpp_lib_tuple_element_t 201402L // N3887
233 #endif
234 #ifndef __cpp_lib_integral_constant_callable
235 #define __cpp_lib_integral_constant_callable 201304L // N3545
236 #endif
237 #ifndef __cpp_lib_result_of_sfinae
238 #define __cpp_lib_result_of_sfinae 201210L // N3642
239 #endif
240 #ifndef __cpp_lib_is_final
241 #define __cpp_lib_is_final 201402L // LWG2112
242 #endif
243 #ifndef __cpp_lib_chrono_udls
244 #define __cpp_lib_chrono_udls 201304L // N3642
245 #endif
246 #ifndef __cpp_lib_string_udls
247 #define __cpp_lib_string_udls 201304L // N3642
248 #endif
249 #ifndef __cpp_lib_generic_associative_lookup
250 #define __cpp_lib_generic_associative_lookup 201304L // N3657
251 #endif
252 #ifndef __cpp_lib_null_iterators
253 #define __cpp_lib_null_iterators 201304L // N3644
254 #endif
255 #ifndef __cpp_lib_make_reverse_iterator
256 #define __cpp_lib_make_reverse_iterator 201402L // LWG2285
257 #endif
258 #ifndef __cpp_lib_robust_nonmodifying_seq_ops
259 #define __cpp_lib_robust_nonmodifying_seq_ops 201304L // N3671
260 #endif
261 #ifndef __cpp_lib_complex_udls
262 #define __cpp_lib_complex_udls 201309L // N3779
263 #endif
264 #ifndef __cpp_lib_quoted_string_io
265 #define __cpp_lib_quoted_string_io 201304L // N3654
266 #endif
267 #ifndef __cpp_lib_shared_timed_mutex
268 #define __cpp_lib_shared_timed_mutex 201402L // N3891
269 #endif
270 #if _MSVC_LANG > 201402L
271 #ifndef __cpp_namespace_attributes
272 #define __cpp_namespace_attributes 201411L // N4266
273 #endif
274 #ifndef __cpp_enumerator_attributes
275 #define __cpp_enumerator_attributes 201411L // N4266
276 #endif
277 #ifndef __cpp_lib_type_trait_variable_templates
278 #define __cpp_lib_type_trait_variable_templates // P0006R0
279 #endif
280 #ifndef __cpp_lib_logical_traits
281 #define __cpp_lib_logical_traits 201510 // P0013R1
282 #endif
283 #ifndef __cpp_lib_as_const
284 #define __cpp_lib_as_const 201510 // P0007R1
285 #endif
286 #ifndef __cpp_lib_transparent_operators
287 #define __cpp_lib_transparent_operators 201510L // P0074R0
288 #endif
289 #ifndef __cpp_lib_chrono
290 #define __cpp_lib_chrono 201510 // P0092R1
291 #endif
292 #ifndef __cpp_lib_lock_guard_variadic
293 #define __cpp_lib_lock_guard_variadic 201510L // P0156R0
294 #endif
295 #ifndef __cpp_lib_uncaught_exceptions
296 #define __cpp_lib_uncaught_exceptions 201411L // N4259
297 #endif
298 #ifndef __cpp_lib_shared_mutex
299 #define __cpp_lib_shared_mutex 201505L // N4508
300 #endif
301 #endif
302 
303 #endif
304 #if _MSC_VER >= 1910
305 #define NLIB_CXX14_CONSTEXPR
306 #undef __cpp_constexpr
307 #define __cpp_constexpr 201304L // N3652
308 #ifndef __cpp_aggregate_nsdmi
309 #define __cpp_aggregate_nsdmi 201304L // N3653
310 #endif
311 #if _MSVC_LANG > 201402L
312 // #define __cpp_hex_float 201603L // P0245R1
313 // #define __cpp_noexcept_function_type 201510L // P0012R1
314 // #define __cpp_fold_expressions 201411L // N4295
315 // #ifndef __cpp_capture_star_this
316 // #define __cpp_capture_star_this 201603L // P0018R3
317 // #endif
318 // #undef __cpp_constexpr
319 // #define __cpp_constexpr 201603L // P0170R1
320 #undef __cpp_range_based_for
321 #define __cpp_range_based_for 201603L // P0184R0
322 #undef __cpp_static_assert
323 #define __cpp_static_assert 201411L // N3928
324 #ifndef __cpp_nested_namespace_definitions
325 #define __cpp_nested_namespace_definitions 201411L // N4230
326 #endif
327 // #define __cpp_inheriting_constructors 201511L // P0136R1
328 // #define __cpp_aggregate_bases 201603L // P0017R1
329 // #define __cpp_nontype_template_args 201411L // N4268
330 // #define __cpp_fold_expressions 201603L // P0036R0
331 // #define __cpp_lib_hardware_interference_size 201603L // P0154R1
332 #endif
333 #endif
334 #endif
335 
336 #include <stdint.h>
337 #include <inttypes.h>
338 #if (_MSC_VER < 1900)
339 # ifndef __func__
340 # define __func__ __FUNCTION__
341 # endif
342 #endif
343 
344 #ifdef __cplusplus
345 extern "C" {
346 #endif
347 
348 #ifndef va_copy
349 # define va_copy(dest, src) (dest = src)
350 #endif
351 #define NLIB_ALWAYS_INLINE __forceinline
352 #define NLIB_NEVER_INLINE __declspec(noinline)
353 #define NLIB_LIKELY(x) (x)
354 #define NLIB_UNLIKELY(x) (x)
355 #define NLIB_EXPECT(var, exp_value) (var)
356 #define NLIB_CHECK_RESULT
357 #if defined(__cplusplus) && _MSC_VER >= 1900
358 #define NLIB_NORETURN [[noreturn]] // NOLINT
359 #else
360 #define NLIB_NORETURN
361 #endif
362 #if defined(__cplusplus) && _MSC_VER >= 1910 && _MSVC_LANG > 201402L
363 #define NLIB_FALLTHROUGH [[fallthrough]] // NOLINT
364 #else
365 #define NLIB_FALLTHROUGH
366 #endif
367 #define NLIB_NONNULL
368 #define NLIB_NONNULL_1
369 #define NLIB_NONNULL_2
370 #define NLIB_NONNULL_3
371 #define NLIB_NONNULL_4
372 #define NLIB_NONNULL_5
373 #define NLIB_ATTRIBUTE_MALLOC
374 #define NLIB_ATTRIBUTE_PURE
375 #define NLIB_ATTRIBUTE_CONST
376 #define NLIB_ATTRIBUTE_ALLOC_SIZE1(n)
377 #define NLIB_ATTRIBUTE_ALLOC_SIZE2(n0, n1)
378 #define NLIB_ATTRIBUTE_ALLOC_ALIGN(algn)
379 #define NLIB_ATTRIBUTE_ASSUME_ALIGNED(n)
380 #ifndef NLIB_DEPRECATED
381 #if defined(__cplusplus) && _MSC_VER >= 1910
382 #define NLIB_DEPRECATED [[deprecated]] // NOLINT
383 #else
384 #define NLIB_DEPRECATED __declspec(deprecated)
385 #endif
386 #endif
387 #ifndef NLIB_DEPRECATED_MSG
388 #if defined(__cplusplus) && _MSC_VER >= 1910
389 #define NLIB_DEPRECATED_MSG(msg) [[deprecated(msg)]] // NOLINT
390 #else
391 #define NLIB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
392 #endif
393 #endif
394 #define NLIB_WEAKSYMBOL
395 #define NLIB_VIS_HIDDEN
396 #ifdef NLIB_WINDLL
397 # define NLIB_EXPIMP_TEMPLATE_(x) template class NLIB_VIS_PUBLIC x
398 # define NLIB_WINEXPORT __declspec(dllexport)
399 # define NLIB_WINIMPORT __declspec(dllimport)
400 # define NLIB_VIS_PUBLIC NLIB_WINIMPORT
401 # define NLIB_EXPIMP_TEMPLATE(x) extern NLIB_EXPIMP_TEMPLATE_(x)
402 #else
403 # define NLIB_VIS_PUBLIC
404 # define NLIB_EXPIMP_TEMPLATE(x)
405 #endif
406 
407 #if defined(n_EXPORTS)
408 # undef NLIB_VIS_PUBLIC
409 # define NLIB_VIS_PUBLIC NLIB_WINEXPORT
410 #elif defined(nx_misc_EXPORTS)
411 # undef NLIB_EXPIMP_TEMPLATE
412 # define NLIB_EXPIMP_TEMPLATE(x) NLIB_EXPIMP_TEMPLATE_(x)
413 #endif
414 
415 #define NLIB_VIS_PUBLIC_ALT
416 
417 #define NLIB_LITTLE_ENDIAN
418 
419 // NOTE:
420 // _WriteBarrier() for the compiler, _mm_sfence() for the processor, ...
421 // NOTE:
422 // You have to comment out error lines in intrin.h if you use VC++2005.
423 // See:
424 // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=262047
425 // http://www.hydrogenaudio.org/forums/index.php?showtopic=50972
426 #define NLIB_MEMORY_ORDER_RELEASE \
427  __pragma(warning(push)) \
428  __pragma(warning(disable:4127)) \
429  do { _WriteBarrier(); _mm_sfence(); } while (0) \
430  __pragma(warning(pop))
431 #define NLIB_MEMORY_ORDER_ACQUIRE \
432  __pragma(warning(push)) \
433  __pragma(warning(disable:4127)) \
434  do { _ReadBarrier(); _mm_lfence(); } while (0) \
435  __pragma(warning(pop))
436 #define NLIB_MEMORY_ORDER_ACQ_REL \
437  __pragma(warning(push)) \
438  __pragma(warning(disable:4127)) \
439  do { _ReadWriteBarrier(); _mm_mfence(); } while (0) \
440  __pragma(warning(pop))
441 #define NLIB_MEMORY_ORDER_SEQ_CST NLIB_MEMORY_ORDER_ACQ_REL
442 
443 // because "%zu" not supported ...
444 #ifdef NLIB_64BIT
445 # define __PRIS_PREFIX "ll"
446 #else
447 # define __PRIS_PREFIX
448 #endif
449 #define NLIB_WARN__(x) #x
450 #define NLIB_WARN_(x) NLIB_WARN__(x)
451 #define NLIB_WARN(exp) (__FILE__ "(" NLIB_WARN_(__LINE__) ") : WARNING: " exp)
452 
453 typedef unsigned int nlib_tls;
454 
455 #if _MSC_VER >= 1900
456 #define NLIB_TIMESPEC_HAS_NATIVE
457 #endif
458 
459 #pragma pack(push, 8)
460 typedef struct nlib_mutex_ {
461  int32_t mark;
462  uint32_t cat;
463  union {
464  HANDLE h;
465  CRITICAL_SECTION cs;
466  } data;
467 } nlib_mutex;
468 #pragma pack(pop)
469 #define NLIB_MUTEX_INITIALIZER { 0x6768696AU, 0 }
470 #define NLIB_RECURSIVE_MUTEX_INITIALIZER { 0x6768696AU, 1 }
471 #define NLIB_RECURSIVE_TIMED_MUTEX_INITIALIZER { 0x6768696AU, 2 }
472 
473 typedef HANDLE nlib_semaphore;
474 
475 typedef struct nlib_cond_ {
476  CONDITION_VARIABLE cond;
477  nlib_mutex mutex;
478 } nlib_cond;
479 #define NLIB_COND_INITIALIZER { 0, NLIB_MUTEX_INITIALIZER }
480 
481 typedef HANDLE nlib_thread;
482 
483 #define NLIB_ATTRIBUTE_PRINTF(x, y)
484 
485 #define NLIB_ASSUME(cond) __assume(cond)
486 
487 #define NLIB_RWLOCK_HAS_NATIVE
488 #ifdef NLIB_RWLOCK_HAS_NATIVE
489 typedef SRWLOCK nlib_rwlock;
490 #define NLIB_RWLOCK_INITIALIZER SRWLOCK_INIT
491 #endif
492 #define NLIB_TIMER_HAS_NATIVE
493 #define NLIB_ONCE_HAS_NATIVE
494 
495 NLIB_VIS_PUBLIC void nlib_free_size_(void* ptr, size_t size);
496 
497 #define NLIB_LIBC_nlib_memcmp
498 #define NLIB_LIBC_nlib_strlen
499 #define NLIB_LIBC_nlib_strnlen
500 #define NLIB_LIBC_nlib_wcslen
501 #define NLIB_LIBC_nlib_wcsnlen
502 #define NLIB_LIBC_nlib_strcpy
503 #define NLIB_LIBC_nlib_strncpy
504 #define NLIB_LIBC_nlib_wcscpy
505 #define NLIB_LIBC_nlib_wcsncpy
506 #define NLIB_LIBC_nlib_strchr
507 #define NLIB_LIBC_nlib_strrchr
508 
509 #if !defined(__INTELLISENSE__)
510 #define NLIB_ATOMIC_RELAXED (0)
511 #define NLIB_ATOMIC_ACQUIRE (1)
512 #define NLIB_ATOMIC_RELEASE (2)
513 #define NLIB_ATOMIC_ACQ_REL (3)
514 #define NLIB_ATOMIC_SEQ_CST (7)
515 
516 //
517 // NOTE:
518 // Windows 8 has xxxNoFence version
519 //
520 
521 static __inline int32_t nlib_atomic_load32(const int32_t* ptr, int memorder) {
522  int32_t result;
523  _ReadWriteBarrier();
524  result = *ptr;
525  (void)memorder;
526  // if (memorder & NLIB_ATOMIC_ACQUIRE)
527  // NLIB_MEMORY_ORDER_ACQUIRE;
528  _ReadWriteBarrier();
529  return result;
530 }
531 
532 static __inline void nlib_atomic_store32(int32_t* ptr, int32_t val, int memorder) {
533  _ReadWriteBarrier();
534  if (memorder != NLIB_ATOMIC_SEQ_CST) {
535  // if (memorder & NLIB_ATOMIC_RELEASE)
536  // NLIB_MEMORY_ORDER_RELEASE;
537  *ptr = val;
538  } else {
539  _InterlockedExchange((volatile long*)ptr, val); // NOLINT
540  }
541  _ReadWriteBarrier();
542 }
543 
544 static __inline int32_t nlib_atomic_exchange32(int32_t* ptr, int32_t val,
545  int memorder) {
546  int32_t result;
547  (void)memorder;
548  _ReadWriteBarrier();
549  result = (int32_t)_InterlockedExchange((volatile long*)ptr, val); // NOLINT
550  _ReadWriteBarrier();
551  return result;
552 }
553 
554 static __inline int nlib_atomic_compare_exchange32(int32_t* ptr, int32_t* expected,
555  int32_t desired, int weak,
556  int success_memorder, int failure_memorder) {
557  int32_t result;
558  _ReadWriteBarrier();
559  result = _InterlockedCompareExchange((volatile long*)ptr, desired, *expected); // NOLINT
560  _ReadWriteBarrier();
561  (void)weak;
562  (void)success_memorder;
563  (void)failure_memorder;
564  if (result == *expected) {
565  return 1;
566  } else {
567  *expected = result;
568  return 0;
569  }
570 }
571 
572 static __inline int32_t nlib_atomic_add_fetch32(int32_t* ptr, int32_t val,
573  int memorder) {
574  int32_t result;
575  (void)memorder;
576  _ReadWriteBarrier();
577  result = _InterlockedExchangeAdd((volatile long*)ptr, val) + val; // NOLINT
578  _ReadWriteBarrier();
579  return result;
580 }
581 
582 static __inline int32_t nlib_atomic_sub_fetch32(int32_t* ptr, int32_t val,
583  int memorder) {
584  int32_t result;
585  (void)memorder;
586  _ReadWriteBarrier();
587  result = _InterlockedExchangeAdd((volatile long*)ptr, -val) - val; // NOLINT
588  _ReadWriteBarrier();
589  return result;
590 }
591 
592 static __inline int32_t nlib_atomic_and_fetch32(int32_t* ptr, int32_t val,
593  int memorder) {
594  int32_t result;
595  (void)memorder;
596  _ReadWriteBarrier();
597  result = _InterlockedAnd((volatile long*)ptr, val) & val; // NOLINT
598  _ReadWriteBarrier();
599  return result;
600 }
601 
602 static __inline int32_t nlib_atomic_xor_fetch32(int32_t* ptr, int32_t val,
603  int memorder) {
604  int32_t result;
605  (void)memorder;
606  _ReadWriteBarrier();
607  result = _InterlockedXor((volatile long*)ptr, val) ^ val; // NOLINT
608  _ReadWriteBarrier();
609  return result;
610 }
611 
612 static __inline int32_t nlib_atomic_or_fetch32(int32_t* ptr, int32_t val,
613  int memorder) {
614  int32_t result;
615  (void)memorder;
616  _ReadWriteBarrier();
617  result = _InterlockedOr((volatile long*)ptr, val) | val; // NOLINT
618  _ReadWriteBarrier();
619  return result;
620 }
621 
622 static __inline int32_t nlib_atomic_fetch_add32(int32_t* ptr, int32_t val,
623  int memorder) {
624  int32_t result;
625  (void)memorder;
626  _ReadWriteBarrier();
627  result = _InterlockedExchangeAdd((volatile long*)ptr, val); // NOLINT
628  _ReadWriteBarrier();
629  return result;
630 }
631 
632 static __inline int32_t nlib_atomic_fetch_sub32(int32_t* ptr, int32_t val,
633  int memorder) {
634  int32_t result;
635  (void)memorder;
636  _ReadWriteBarrier();
637  result = _InterlockedExchangeAdd((volatile long*)ptr, -val); // NOLINT
638  _ReadWriteBarrier();
639  return result;
640 }
641 
642 static __inline int32_t nlib_atomic_fetch_and32(int32_t* ptr, int32_t val,
643  int memorder) {
644  int32_t result;
645  (void)memorder;
646  _ReadWriteBarrier();
647  result = _InterlockedAnd((volatile long*)ptr, val); // NOLINT
648  _ReadWriteBarrier();
649  return result;
650 }
651 
652 static __inline int32_t nlib_atomic_fetch_xor32(int32_t* ptr, int32_t val,
653  int memorder) {
654  int32_t result;
655  (void)memorder;
656  _ReadWriteBarrier();
657  result = _InterlockedXor((volatile long*)ptr, val); // NOLINT
658  _ReadWriteBarrier();
659  return result;
660 }
661 
662 static __inline int32_t nlib_atomic_fetch_or32(int32_t* ptr, int32_t val,
663  int memorder) {
664  int32_t result;
665  (void)memorder;
666  _ReadWriteBarrier();
667  result = _InterlockedOr((volatile long*)ptr, val); // NOLINT
668  _ReadWriteBarrier();
669  return result;
670 }
671 
672 static __inline int64_t nlib_atomic_load64(const int64_t* ptr, int memorder) {
673  int64_t result;
674  _ReadWriteBarrier();
675  result = *ptr;
676  _ReadWriteBarrier();
677  (void)memorder;
678  // if (memorder & NLIB_ATOMIC_ACQUIRE)
679  // NLIB_MEMORY_ORDER_ACQUIRE;
680  return result;
681 }
682 
683 static __inline void nlib_atomic_store64(int64_t* ptr, int64_t val, int memorder) {
684  _ReadWriteBarrier();
685  if (memorder != NLIB_ATOMIC_SEQ_CST) {
686  // if (memorder & NLIB_ATOMIC_RELEASE)
687  // NLIB_MEMORY_ORDER_RELEASE;
688  *ptr = val;
689  } else {
690 #ifndef NLIB_64BIT
691  InterlockedExchange64((volatile long long*)ptr, val); // NOLINT
692 #else
693  _InterlockedExchange64((volatile long long*)ptr, val); // NOLINT
694 #endif
695  }
696  _ReadWriteBarrier();
697 }
698 
699 static __inline int64_t nlib_atomic_exchange64(int64_t* ptr, int64_t val,
700  int memorder) {
701  int64_t result;
702  (void)memorder;
703  _ReadWriteBarrier();
704 #ifndef NLIB_64BIT
705  result = (int64_t)InterlockedExchange64((volatile long long*)ptr, val); // NOLINT
706 #else
707  result = (int64_t)_InterlockedExchange64((volatile long long*)ptr, val); // NOLINT
708 #endif
709  _ReadWriteBarrier();
710  return result;
711 }
712 
713 static __inline void* nlib_atomic_exchangeptr(void** ptr, void* val, int memorder) {
714 #ifndef NLIB_64BIT
715  return (void*)nlib_atomic_exchange32((int32_t*)ptr, (int32_t)val, memorder); // NOLINT
716 #else
717  return (void*)nlib_atomic_exchange64((int64_t*)ptr, (int64_t)val, memorder); // NOLINT
718 #endif
719 }
720 
721 static __inline int nlib_atomic_compare_exchange64(int64_t* ptr, int64_t* expected,
722  int64_t desired, int weak,
723  int success_memorder, int failure_memorder) {
724  int64_t result;
725  _ReadWriteBarrier();
726 #ifndef NLIB_64BIT
727  result = InterlockedCompareExchange64((volatile long long*)ptr, desired, *expected); // NOLINT
728 #else
729  result = _InterlockedCompareExchange64((volatile long long*)ptr, desired, *expected); // NOLINT
730 #endif
731  _ReadWriteBarrier();
732  (void)weak;
733  (void)success_memorder;
734  (void)failure_memorder;
735  if (result == *expected) {
736  return 1;
737  } else {
738  *expected = result;
739  return 0;
740  }
741 }
742 
743 static __inline int64_t nlib_atomic_add_fetch64(int64_t* ptr, int64_t val,
744  int memorder) {
745  int64_t result;
746  (void)memorder;
747  _ReadWriteBarrier();
748 #ifndef NLIB_64BIT
749  result = InterlockedExchangeAdd64((volatile long long*)ptr, val) + val; // NOLINT
750 #else
751  result = _InterlockedExchangeAdd64((volatile long long*)ptr, val) + val; // NOLINT
752 #endif
753  _ReadWriteBarrier();
754  return result;
755 }
756 
757 static __inline int64_t nlib_atomic_sub_fetch64(int64_t* ptr, int64_t val,
758  int memorder) {
759  int64_t result;
760  (void)memorder;
761  _ReadWriteBarrier();
762 #ifndef NLIB_64BIT
763  result = InterlockedExchangeAdd64((volatile long long*)ptr, -val) - val; // NOLINT
764 #else
765  result = _InterlockedExchangeAdd64((volatile long long*)ptr, -val) - val; // NOLINT
766 #endif
767  _ReadWriteBarrier();
768  return result;
769 }
770 
771 static __inline int64_t nlib_atomic_and_fetch64(int64_t* ptr, int64_t val,
772  int memorder) {
773  int64_t result;
774  (void)memorder;
775  _ReadWriteBarrier();
776 #ifndef NLIB_64BIT
777  result = InterlockedAnd64((volatile long long*)ptr, val) & val; // NOLINT
778 #else
779  result = _InterlockedAnd64((volatile long long*)ptr, val) & val; // NOLINT
780 #endif
781  _ReadWriteBarrier();
782  return result;
783 }
784 
785 static __inline int64_t nlib_atomic_xor_fetch64(int64_t* ptr, int64_t val,
786  int memorder) {
787  int64_t result;
788  (void)memorder;
789  _ReadWriteBarrier();
790 #ifndef NLIB_64BIT
791  result = InterlockedXor64((volatile long long*)ptr, val) ^ val; // NOLINT
792 #else
793  result = _InterlockedXor64((volatile long long*)ptr, val) ^ val; // NOLINT
794 #endif
795  _ReadWriteBarrier();
796  return result;
797 }
798 
799 static __inline int64_t nlib_atomic_or_fetch64(int64_t* ptr, int64_t val,
800  int memorder) {
801  int64_t result;
802  (void)memorder;
803  _ReadWriteBarrier();
804 #ifndef NLIB_64BIT
805  result = InterlockedOr64((volatile long long*)ptr, val) | val; // NOLINT
806 #else
807  result = _InterlockedOr64((volatile long long*)ptr, val) | val; // NOLINT
808 #endif
809  _ReadWriteBarrier();
810  return result;
811 }
812 
813 static __inline int64_t nlib_atomic_fetch_add64(int64_t* ptr, int64_t val,
814  int memorder) {
815  int64_t result;
816  (void)memorder;
817  _ReadWriteBarrier();
818 #ifndef NLIB_64BIT
819  result = InterlockedExchangeAdd64((volatile long long*)ptr, val); // NOLINT
820 #else
821  result = _InterlockedExchangeAdd64((volatile long long*)ptr, val); // NOLINT
822 #endif
823  _ReadWriteBarrier();
824  return result;
825 }
826 
827 static __inline int64_t nlib_atomic_fetch_sub64(int64_t* ptr, int64_t val,
828  int memorder) {
829  int64_t result;
830  (void)memorder;
831  _ReadWriteBarrier();
832 #ifndef NLIB_64BIT
833  result = InterlockedExchangeAdd64((volatile long long*)ptr, -val); // NOLINT
834 #else
835  result = _InterlockedExchangeAdd64((volatile long long*)ptr, -val); // NOLINT
836 #endif
837  _ReadWriteBarrier();
838  return result;
839 }
840 
841 static __inline int64_t nlib_atomic_fetch_and64(int64_t* ptr, int64_t val,
842  int memorder) {
843  int64_t result;
844  (void)memorder;
845  _ReadWriteBarrier();
846 #ifndef NLIB_64BIT
847  result = InterlockedAnd64((volatile long long*)ptr, val); // NOLINT
848 #else
849  result = _InterlockedAnd64((volatile long long*)ptr, val); // NOLINT
850 #endif
851  _ReadWriteBarrier();
852  return result;
853 }
854 
855 static __inline int64_t nlib_atomic_fetch_xor64(int64_t* ptr, int64_t val,
856  int memorder) {
857  int64_t result;
858  (void)memorder;
859  _ReadWriteBarrier();
860 #ifndef NLIB_64BIT
861  result = InterlockedXor64((volatile long long*)ptr, val); // NOLINT
862 #else
863  result = _InterlockedXor64((volatile long long*)ptr, val); // NOLINT
864 #endif
865  _ReadWriteBarrier();
866  return result;
867 }
868 
869 static __inline int64_t nlib_atomic_fetch_or64(int64_t* ptr, int64_t val,
870  int memorder) {
871  int64_t result;
872  (void)memorder;
873  _ReadWriteBarrier();
874 #ifndef NLIB_64BIT
875  result = InterlockedOr64((volatile long long*)ptr, val); // NOLINT
876 #else
877  result = _InterlockedOr64((volatile long long*)ptr, val); // NOLINT
878 #endif
879  _ReadWriteBarrier();
880  return result;
881 }
882 
883 static __inline void* nlib_atomic_loadptr(void* const* ptr, int memorder) {
884  void* result;
885  _ReadWriteBarrier();
886  result = *ptr;
887  _ReadWriteBarrier();
888  (void)memorder;
889  // if (memorder & NLIB_ATOMIC_ACQUIRE)
890  // NLIB_MEMORY_ORDER_ACQUIRE;
891  return result;
892 }
893 
894 static __inline void nlib_atomic_storeptr(void** ptr, void* val, int memorder) {
895  _ReadWriteBarrier();
896  if (memorder != NLIB_ATOMIC_SEQ_CST) {
897  // if (memorder & NLIB_ATOMIC_RELEASE)
898  // NLIB_MEMORY_ORDER_RELEASE;
899  *ptr = val;
900  } else {
901 #if (_MSC_VER == 1800 && !defined(NLIB_64BIT))
902  InterlockedExchangePointer((void* volatile*)ptr, val); // NOLINT
903 #else
904  _InterlockedExchangePointer((void* volatile*)ptr, val); // NOLINT
905 #endif
906  }
907  _ReadWriteBarrier();
908 }
909 
910 static __inline int nlib_atomic_compare_exchangeptr(void** ptr, void** expected,
911  void* desired, int weak,
912  int success_memorder, int failure_memorder) {
913  void* result;
914  _ReadWriteBarrier();
915  result = _InterlockedCompareExchangePointer((void* volatile *)ptr, desired, *expected);
916  _ReadWriteBarrier();
917  (void)weak;
918  (void)success_memorder;
919  (void)failure_memorder;
920  if (result == *expected) {
921  return 1;
922  } else {
923  *expected = result;
924  return 0;
925  }
926 }
927 
928 static __inline void nlib_atomic_thread_fence(int memorder) {
929  switch (memorder) {
930  case NLIB_ATOMIC_RELAXED:
931  break;
932  case NLIB_ATOMIC_ACQUIRE:
934  break;
935  case NLIB_ATOMIC_RELEASE:
937  break;
938  default:
940  break;
941  }
942 }
943 #endif
944 
945 #ifdef __cplusplus
946 }
947 #endif
948 
949 #ifndef _WIN64
950 #define NLIB_ALTNAME(func1, func2) \
951  __pragma(comment(linker, "/alternatename:_" NLIB_STRINGIFY(func1) "=_" NLIB_STRINGIFY(func2)))
952 #else
953 #define NLIB_ALTNAME(func1, func2) \
954  __pragma(comment(linker, "/alternatename:" NLIB_STRINGIFY(func1) "=" NLIB_STRINGIFY(func2)))
955 #endif
956 
957 NLIB_ALTNAME(nlib_malloc, malloc)
958 NLIB_ALTNAME(nlib_free, free)
959 NLIB_ALTNAME(nlib_calloc, calloc)
960 NLIB_ALTNAME(nlib_realloc, realloc)
961 NLIB_ALTNAME(nlib_free_size, nlib_free_size_)
962 
963 #if defined(NLIB_SIMD)
964 # ifndef NLIB_LIBC_nlib_strlen
965 NLIB_ALTNAME(nlib_strlen, nlib_strlen_simd)
966 # endif
967 # ifndef NLIB_LIBC_nlib_strlen
968 NLIB_ALTNAME(nlib_strnlen, nlib_strnlen_simd)
969 # endif
970 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_simd)
971 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_simd)
972 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
973 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
974 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_simd)
975 NLIB_ALTNAME(nlib_strchr, nlib_strchr_simd)
976 NLIB_ALTNAME(nlib_strrchr, strrchr)
977 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_simd)
978 NLIB_ALTNAME(nlib_memcmp, nlib_memcmp_simd)
979 NLIB_ALTNAME(nlib_memchr, nlib_memchr_simd)
980 NLIB_ALTNAME(nlib_memrchr, nlib_memrchr_simd)
981 NLIB_ALTNAME(nlib_memchr_not, nlib_memchr_not_simd)
982 NLIB_ALTNAME(nlib_memchr_range_not, nlib_memchr_range_not_simd)
983 NLIB_ALTNAME(nlib_memchr_lt, nlib_memchr_lt_simd)
984 NLIB_ALTNAME(nlib_memchr_gt, nlib_memchr_gt_simd)
985 NLIB_ALTNAME(nlib_memchr_mb, nlib_memchr_mb_simd)
986 NLIB_ALTNAME(nlib_skipws, nlib_skipws_simd)
987 NLIB_ALTNAME(nlib_swapendian_16, nlib_swapendian_16_simd)
988 NLIB_ALTNAME(nlib_swapendian_32, nlib_swapendian_32_simd)
989 NLIB_ALTNAME(nlib_swapendian_64, nlib_swapendian_64_simd)
990 #else
991 # ifndef NLIB_LIBC_nlib_strlen
992 NLIB_ALTNAME(nlib_strlen, nlib_strlen_generic)
993 # endif
994 # ifndef NLIB_LIBC_nlib_strlen
995 NLIB_ALTNAME(nlib_strnlen, nlib_strnlen_generic)
996 # endif
997 NLIB_ALTNAME(nlib_utf16len_, nlib_utf16len_generic)
998 NLIB_ALTNAME(nlib_utf16nlen_, nlib_utf16nlen_generic)
999 NLIB_ALTNAME(nlib_utf32len_, nlib_utf32len_generic)
1000 NLIB_ALTNAME(nlib_utf32nlen_, nlib_utf32nlen_generic)
1001 NLIB_ALTNAME(nlib_utf16cplen_ex_, nlib_utf16cplen_ex_generic)
1002 NLIB_ALTNAME(nlib_strchr, nlib_strchr_generic)
1003 NLIB_ALTNAME(nlib_strrchr, nlib_strrchr_generic)
1004 NLIB_ALTNAME(nlib_strchr_mb, nlib_strchr_mb_generic)
1005 NLIB_ALTNAME(nlib_memcmp, nlib_memcmp_generic)
1006 NLIB_ALTNAME(nlib_memchr, nlib_memchr_generic)
1007 NLIB_ALTNAME(nlib_memrchr, nlib_memrchr_generic)
1008 NLIB_ALTNAME(nlib_memchr_not, nlib_memchr_not_generic)
1009 NLIB_ALTNAME(nlib_memchr_range_not, nlib_memchr_range_not_generic)
1010 NLIB_ALTNAME(nlib_memchr_lt, nlib_memchr_lt_generic)
1011 NLIB_ALTNAME(nlib_memchr_gt, nlib_memchr_gt_generic)
1012 NLIB_ALTNAME(nlib_memchr_mb, nlib_memchr_mb_generic)
1013 NLIB_ALTNAME(nlib_skipws, nlib_skipws_generic)
1014 NLIB_ALTNAME(nlib_swapendian_16, nlib_swapendian_16_generic)
1015 NLIB_ALTNAME(nlib_swapendian_32, nlib_swapendian_32_generic)
1016 NLIB_ALTNAME(nlib_swapendian_64, nlib_swapendian_64_generic)
1017 #endif
1018 
1019 #endif
1020 #endif // INCLUDE_NN_NLIB_PLATFORM_WIN32_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()に準じます。 ...
const char * nlib_strrchr(const char *s, int c)
文字列の末尾から文字を検索します。
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()に準じます。
void * nlib_calloc(size_t nmemb, size_t size)
C標準関数のcalloc()を呼び出すweak関数です。nlibはこの関数を経由してcalloc()を呼び出します。 ...
int64_t nlib_atomic_fetch_add64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の加算を行います。動作はgccの__atomic_fetch_add()に準じます。
const void * nlib_memchr_lt(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc 未満の文字があるデータへのポインタを返しま...
struct nlib_rwlock_ nlib_rwlock
リードライトロックオブジェクトの型です。
Definition: Platform.h:875
sem_t nlib_semaphore
セマフォオブジェクトの型です。
#define NLIB_MEMORY_ORDER_ACQUIRE
メモリフェンスです。C++11ではatomic_thread_fence(memory_order_acquire)に一致します。 ...
size_t nlib_strnlen(const char *s, size_t maxsize)
N1078のstrnlen_sに相当する実装です。
int nlib_memcmp(const void *buf1, const void *buf2, size_t n)
buf1 とbuf2 を先頭からn バイト分unsigned charとして比較します。
#define NLIB_ATOMIC_RELEASE
gccの__ATOMIC_RELEASEやC++11のstd::memory_order_releaseに準じます。
const void * nlib_memchr_not(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc でないポインタを返します。 ...
int32_t nlib_atomic_or_fetch32(int32_t *ptr, int32_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_or_fetch()に準じます。 ...
const char * nlib_skipws(size_t *cnt_lf, const char **last_lf, const char *s, size_t n)
n 個の文字から成る文字列を探索して最初の空白でない文字へのポインタを返します。
int64_t nlib_atomic_fetch_sub64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の減算を行います。動作はgccの__atomic_fetch_sub()に準じます。
void nlib_free_size(void *ptr, size_t size)
サイズを指定してメモリを解放します。デフォルトではnlib_free()を呼び出します。
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()に準じます。 ...
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
const char * nlib_strchr(const char *s, int c)
文字列の先頭から文字を検索します。
int64_t nlib_atomic_fetch_or64(int64_t *ptr, int64_t val, int memorder)
アトミックな値の論理和の計算を行います。動作はgccの__atomic_fetch_or()に準じます。 ...
const void * nlib_memchr(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc があるポインタを返します。 ...
void * nlib_malloc(size_t size)
C標準関数のmalloc()を呼び出すweak関数です。nlibはこの関数を経由してmalloc()を呼び出します。 ...
#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)に一致します。 ...
const void * nlib_memrchr(const void *s, int c, size_t n)
メモリ領域[s, s + n)の後方からn バイトを検索して、バイトc があるポインタを返します。 ...
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()に準じます。 ...
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
条件変数オブジェクトの型です。
void * nlib_realloc(void *ptr, size_t size)
C標準関数のrealloc()を呼び出すweak関数です。nlibはこの関数を経由してrealloc()を呼び出します。 ...
errno_t nlib_swapendian_32(uint32_t *p, size_t count)
エンディアンを変換します。
#define NLIB_ATOMIC_RELAXED
gccの__ATOMIC_RELAXEDやC++11のstd::memory_order_relaxedに準じます。
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
pthread_mutex_t nlib_mutex
ミューテックス変数の型です。
const void * nlib_memchr_range_not(const void *s, const char *range, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、最初のrange に含まない文字へのポインタを返します。 ...
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()に準じます。
errno_t nlib_swapendian_16(uint16_t *p, size_t count)
エンディアンを変換します。
const void * nlib_memchr_gt(const void *s, int c, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、バイトc より大きいの文字があるデータへのポインタを...
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()に準じます。
void nlib_free(void *ptr)
C標準関数のfree()を呼び出すweak関数です。nlibはこの関数を経由してfree()を呼び出します。 ...
errno_t nlib_swapendian_64(uint64_t *p, size_t count)
エンディアンを変換します。
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()に準じます。 ...
const void * nlib_memchr_mb(const void *s, size_t n)
メモリ領域[s, s + n)の先頭からn バイトを検索して、0x80以上のバイトが格納されている場所へのポインタを...
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()に準じます。