]> pd.if.org Git - liblfds/blob - liblfds/liblfds6.1.0/liblfds610/src/lfds610_liblfds/lfds610_liblfds_abstraction_test_helpers.c
Initial import (all versions, including the new 7.1.0)
[liblfds] / liblfds / liblfds6.1.0 / liblfds610 / src / lfds610_liblfds / lfds610_liblfds_abstraction_test_helpers.c
1 #include "lfds610_liblfds_internal.h"
2
3
4
5
6
7 /****************************************************************************/
8 void lfds610_liblfds_abstraction_test_helper_increment_non_atomic( lfds610_atom_t *shared_counter )
9 {
10   /* TRD : lfds610_atom_t must be volatile or the compiler
11            optimizes it away into a single store
12   */
13
14   volatile lfds610_atom_t
15     count = 0;
16
17   assert( shared_counter != NULL );
18
19   while( count++ < 10000000 )
20     (*(lfds610_atom_t *) shared_counter)++;
21
22   return;
23 }
24
25
26
27
28
29 /****************************************************************************/
30 void lfds610_liblfds_abstraction_test_helper_increment_atomic( volatile lfds610_atom_t *shared_counter )
31 {
32   lfds610_atom_t
33     count = 0;
34
35   assert( shared_counter != NULL );
36
37   while( count++ < 10000000 )
38     lfds610_abstraction_increment( shared_counter );
39
40   return;
41 }
42
43
44
45
46
47 /****************************************************************************/
48 void lfds610_liblfds_abstraction_test_helper_cas( volatile lfds610_atom_t *shared_counter, lfds610_atom_t *local_counter )
49 {
50   lfds610_atom_t
51     loop = 0,
52     original_destination;
53
54   LFDS610_ALIGN(LFDS610_ALIGN_SINGLE_POINTER) lfds610_atom_t
55     exchange,
56     compare;
57
58   assert( shared_counter != NULL );
59   assert( local_counter != NULL );
60
61   while( loop++ < 1000000 )
62   {
63     do
64     {
65       compare = *shared_counter;
66       exchange = compare + 1;
67
68       original_destination = lfds610_abstraction_cas( shared_counter, exchange, compare );
69     }
70     while( original_destination != compare );
71
72     (*local_counter)++;
73   }
74
75   return;
76 }
77
78
79
80
81
82 /****************************************************************************/
83 void lfds610_liblfds_abstraction_test_helper_dcas( volatile lfds610_atom_t *shared_counter, lfds610_atom_t *local_counter )
84 {
85   lfds610_atom_t
86     loop = 0;
87
88   LFDS610_ALIGN(LFDS610_ALIGN_DOUBLE_POINTER) lfds610_atom_t
89     exchange[2],
90     compare[2];
91
92   assert( shared_counter != NULL );
93   assert( local_counter != NULL );
94
95   while( loop++ < 1000000 )
96   {
97     compare[0] = *shared_counter;
98     compare[1] = *(shared_counter+1);
99
100     do
101     {
102       exchange[0] = compare[0] + 1;
103       exchange[1] = compare[1];
104     }
105     while( 0 == lfds610_abstraction_dcas(shared_counter, exchange, compare) );
106
107     (*local_counter)++;
108   }
109
110   return;
111 }
112