]> pd.if.org Git - liblfds/blob - liblfds/liblfds7.0.0/liblfds700/src/liblfds700_internal.h
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds7.0.0 / liblfds700 / src / liblfds700_internal.h
1 /***** public prototypes *****/
2 #include "../inc/liblfds700.h"
3
4 /***** defines *****/
5 #define and &&
6 #define or  ||
7
8 #define NO_FLAGS 0x0
9
10 #define LFDS700_ABSTRACTION_BACKOFF_LIMIT  (0x1 << 10)
11
12 #if( defined _KERNEL_MODE )
13   #define MODE_TYPE_STRING "kernel-mode"
14 #endif
15
16 #if( !defined _KERNEL_MODE )
17   #define MODE_TYPE_STRING "user-mode"
18 #endif
19
20 #if( defined NDEBUG && !defined COVERAGE && !defined TSAN )
21   #define BUILD_TYPE_STRING "release"
22 #endif
23
24 #if( !defined NDEBUG && !defined COVERAGE && !defined TSAN )
25   #define BUILD_TYPE_STRING "debug"
26 #endif
27
28 #if( !defined NDEBUG && defined COVERAGE && !defined TSAN )
29   #define BUILD_TYPE_STRING "coverage"
30 #endif
31
32 #if( !defined NDEBUG && !defined COVERAGE && defined TSAN )
33   #define BUILD_TYPE_STRING "threadsanitizer"
34 #endif
35
36 // TRD : lfds700_pal_atom_t volatile *destination, lfds700_pal_atom_t *compare, lfds700_pal_atom_t new_destination, enum lfds700_misc_cas_strength cas_strength, char unsigned result, lfds700_pal_uint_t *backoff_iteration
37 #define LFDS700_PAL_ATOMIC_CAS_WITH_BACKOFF( pointer_to_destination, pointer_to_compare, new_destination, cas_strength, result, backoff_iteration, ps )              \
38 {                                                                                                                                                                    \
39   LFDS700_PAL_ATOMIC_CAS( pointer_to_destination, pointer_to_compare, new_destination, cas_strength, result );                                                       \
40                                                                                                                                                                      \
41   if( result == 0 )                                                                                                                                                  \
42   {                                                                                                                                                                  \
43     lfds700_pal_uint_t                                                                                                                                               \
44       endloop;                                                                                                                                                       \
45                                                                                                                                                                      \
46     lfds700_pal_uint_t volatile                                                                                                                                      \
47       loop;                                                                                                                                                          \
48                                                                                                                                                                      \
49     if( (backoff_iteration) == LFDS700_ABSTRACTION_BACKOFF_LIMIT )                                                                                                   \
50       (backoff_iteration) = LFDS700_MISC_ABSTRACTION_BACKOFF_INITIAL_VALUE;                                                                                          \
51                                                                                                                                                                      \
52     if( (backoff_iteration) == LFDS700_MISC_ABSTRACTION_BACKOFF_INITIAL_VALUE )                                                                                      \
53       (backoff_iteration) = 1;                                                                                                                                       \
54     else                                                                                                                                                             \
55     {                                                                                                                                                                \
56       endloop = ( LFDS700_MISC_PRNG_GENERATE(ps) % (backoff_iteration) ) * ps->local_copy_of_global_exponential_backoff_timeslot_length_in_loop_iterations_for_cas;  \
57       for( loop = 0 ; loop < endloop ; loop++ );                                                                                                                     \
58     }                                                                                                                                                                \
59                                                                                                                                                                      \
60     (backoff_iteration) <<= 1;                                                                                                                                       \
61   }                                                                                                                                                                  \
62 }
63
64 // TRD : lfds700_pal_atom_t volatile (*destination)[2], lfds700_pal_atom_t (*compare)[2], lfds700_pal_atom_t (*new_destination)[2], enum lfds700_misc_cas_strength cas_strength, char unsigned result, lfds700_pal_uint_t *backoff_iteration
65 #define LFDS700_PAL_ATOMIC_DWCAS_WITH_BACKOFF( pointer_to_destination, pointer_to_compare, pointer_to_new_destination, cas_strength, result, backoff_iteration, ps )   \
66 {                                                                                                                                                                      \
67   LFDS700_PAL_ATOMIC_DWCAS( pointer_to_destination, pointer_to_compare, pointer_to_new_destination, cas_strength, result );                                            \
68                                                                                                                                                                        \
69   if( result == 0 )                                                                                                                                                    \
70   {                                                                                                                                                                    \
71     lfds700_pal_uint_t                                                                                                                                                 \
72       endloop;                                                                                                                                                         \
73                                                                                                                                                                        \
74     lfds700_pal_uint_t volatile                                                                                                                                        \
75       loop;                                                                                                                                                            \
76                                                                                                                                                                        \
77     if( (backoff_iteration) == LFDS700_ABSTRACTION_BACKOFF_LIMIT )                                                                                                     \
78       (backoff_iteration) = LFDS700_MISC_ABSTRACTION_BACKOFF_INITIAL_VALUE;                                                                                            \
79                                                                                                                                                                        \
80     if( (backoff_iteration) == LFDS700_MISC_ABSTRACTION_BACKOFF_INITIAL_VALUE )                                                                                        \
81       (backoff_iteration) = 1;                                                                                                                                         \
82     else                                                                                                                                                               \
83     {                                                                                                                                                                  \
84       endloop = ( LFDS700_MISC_PRNG_GENERATE(ps) % (backoff_iteration) ) * ps->local_copy_of_global_exponential_backoff_timeslot_length_in_loop_iterations_for_dwcas;  \
85       for( loop = 0 ; loop < endloop ; loop++ );                                                                                                                       \
86     }                                                                                                                                                                  \
87                                                                                                                                                                        \
88     (backoff_iteration) <<= 1;                                                                                                                                         \
89   }                                                                                                                                                                    \
90 }
91
92 /***** library-wide prototypes *****/
93