@@ -8,7 +8,6 @@ terms of the MIT license. A copy of the license can be found in the file
8
8
#ifndef MI_INTERNAL_H
9
9
#define MI_INTERNAL_H
10
10
11
-
12
11
// --------------------------------------------------------------------------
13
12
// This file contains the internal API's of mimalloc and various utility
14
13
// functions and macros.
@@ -18,6 +17,17 @@ terms of the MIT license. A copy of the license can be found in the file
18
17
#include " track.h"
19
18
#include " bits.h"
20
19
20
+
21
+ // --------------------------------------------------------------------------
22
+ // Compiler defines
23
+ // --------------------------------------------------------------------------
24
+
25
+ #if (MI_DEBUG>0)
26
+ #define mi_trace_message (...) _mi_trace_message(__VA_ARGS__)
27
+ #else
28
+ #define mi_trace_message (...)
29
+ #endif
30
+
21
31
#define mi_decl_cache_align mi_decl_align (64 )
22
32
23
33
#if defined(_MSC_VER)
@@ -26,26 +36,59 @@ terms of the MIT license. A copy of the license can be found in the file
26
36
#define mi_decl_noinline __declspec (noinline)
27
37
#define mi_decl_thread __declspec (thread)
28
38
#define mi_decl_align (a ) __declspec(align(a))
39
+ #define mi_decl_noreturn __declspec(noreturn)
29
40
#define mi_decl_weak
30
41
#define mi_decl_hidden
42
+ #define mi_decl_cold
31
43
#elif (defined(__GNUC__) && (__GNUC__ >= 3)) || defined(__clang__) // includes clang and icc
32
44
#define mi_decl_noinline __attribute__ ((noinline))
33
45
#define mi_decl_thread __thread
34
46
#define mi_decl_align (a ) __attribute__((aligned(a)))
47
+ #define mi_decl_noreturn __attribute__((noreturn))
35
48
#define mi_decl_weak __attribute__ ((weak))
36
49
#define mi_decl_hidden __attribute__ ((visibility(" hidden" )))
50
+ #if (__GNUC__ >= 4) || defined(__clang__)
51
+ #define mi_decl_cold __attribute__ ((cold))
52
+ #else
53
+ #define mi_decl_cold
54
+ #endif
37
55
#elif __cplusplus >= 201103L // c++11
38
56
#define mi_decl_noinline
39
57
#define mi_decl_thread thread_local
40
- #define mi_decl_cache_align alignas (MI_CACHE_LINE)
58
+ #define mi_decl_align (a ) alignas (a)
59
+ #define mi_decl_noreturn [[noreturn]]
41
60
#define mi_decl_weak
42
61
#define mi_decl_hidden
62
+ #define mi_decl_cold
43
63
#else
44
64
#define mi_decl_noinline
45
65
#define mi_decl_thread __thread // hope for the best :-)
46
66
#define mi_decl_align (a )
67
+ #define mi_decl_noreturn
47
68
#define mi_decl_weak
48
69
#define mi_decl_hidden
70
+ #define mi_decl_cold
71
+ #endif
72
+
73
+ #if defined(__GNUC__) || defined(__clang__)
74
+ #define mi_unlikely (x ) (__builtin_expect(!!(x),false ))
75
+ #define mi_likely (x ) (__builtin_expect(!!(x),true ))
76
+ #elif (defined(__cplusplus) && (__cplusplus >= 202002L)) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
77
+ #define mi_unlikely (x ) (x) [[unlikely]]
78
+ #define mi_likely (x ) (x) [[likely]]
79
+ #else
80
+ #define mi_unlikely (x ) (x)
81
+ #define mi_likely (x ) (x)
82
+ #endif
83
+
84
+ #ifndef __has_builtin
85
+ #define __has_builtin (x ) 0
86
+ #endif
87
+
88
+ #if defined(__cplusplus)
89
+ #define mi_decl_externc extern " C"
90
+ #else
91
+ #define mi_decl_externc
49
92
#endif
50
93
51
94
#if (defined(__GNUC__) && (__GNUC__ >= 7)) || defined(__clang__) // includes clang and icc
@@ -67,11 +110,10 @@ terms of the MIT license. A copy of the license can be found in the file
67
110
#define __wasi__
68
111
#endif
69
112
70
- #if (MI_DEBUG>0)
71
- #define mi_trace_message (...) _mi_trace_message(__VA_ARGS__)
72
- #else
73
- #define mi_trace_message (...)
74
- #endif
113
+
114
+ // --------------------------------------------------------------------------
115
+ // Internal functions
116
+ // --------------------------------------------------------------------------
75
117
76
118
77
119
// "libc.c"
@@ -261,7 +303,6 @@ bool _mi_page_is_valid(mi_page_t* page);
261
303
#endif
262
304
263
305
264
-
265
306
/* -----------------------------------------------------------
266
307
Assertions
267
308
----------------------------------------------------------- */
@@ -344,6 +385,32 @@ typedef struct mi_option_desc_s {
344
385
const char * legacy_name; // potential legacy option name
345
386
} mi_option_desc_t ;
346
387
388
+ // ------------------------------------------------------
389
+ // Assertions
390
+ // ------------------------------------------------------
391
+
392
+ #if (MI_DEBUG)
393
+ // use our own assertion to print without memory allocation
394
+ mi_decl_noreturn mi_decl_cold void _mi_assert_fail (const char * assertion, const char * fname, unsigned int line, const char * func) mi_attr_noexcept;
395
+ #define mi_assert (expr ) ((expr) ? (void )0 : _mi_assert_fail(#expr,__FILE__,__LINE__,__func__))
396
+ #else
397
+ #define mi_assert (x )
398
+ #endif
399
+
400
+ #if (MI_DEBUG>1)
401
+ #define mi_assert_internal mi_assert
402
+ #else
403
+ #define mi_assert_internal (x )
404
+ #endif
405
+
406
+ #if (MI_DEBUG>2)
407
+ #define mi_assert_expensive mi_assert
408
+ #else
409
+ #define mi_assert_expensive (x )
410
+ #endif
411
+
412
+
413
+
347
414
/* -----------------------------------------------------------
348
415
Inlined definitions
349
416
----------------------------------------------------------- */
0 commit comments