-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_gecos.c
207 lines (188 loc) · 3.87 KB
/
list_gecos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright (c) 2014 Mohamed L. Karaoui.
* Copyright (c) 2014 Sorbonne Universités, UPMC Univ Paris 06.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <assert.h>
#include <pthread.h>
#include "lock.h"
#include "test.h"
#include "allocator_malloc.h"
#ifdef GECOS_B
int search(int key, node_t** head, lock_t* lock)
{
node_t *cur;
node_t *next;
node_t *prev;
gc_t cur_gc;
gc_t next_gc;
gc_t prev_gc;
int cur_key;
retry:
cur = ACCESS_ONCE(*head);
if(cur == NULL) return 0;
cur_gc = ACCESS_ONCE(cur->gc);
compiler_barrier();
if(cur != ACCESS_ONCE(*head)) goto retry;
while(cur) {
cur_key = cur->key;
relink:
next = ACCESS_ONCE(cur->next);
if(next != NULL) next_gc = ACCESS_ONCE(next->gc);
compiler_barrier();
if(next != ACCESS_ONCE(cur->next))
{
nbrelink++;
goto relink;
}
if(cur_gc != ACCESS_ONCE(cur->gc))
{
if(prev_gc == ACCESS_ONCE(prev->gc))
{
cur = prev;
cur_gc = prev_gc;
nbreprev++;
continue;
}
nbretry++;
goto retry;
}
read_compute();
if (cur_key >= key)
return (cur_key == key);
prev = cur;
cur = next;
prev_gc = cur_gc;
cur_gc = next_gc;
}
return 0;
}
#elif GECOS_R
int search(int key, node_t** head, lock_t* lock)
{
node_t *cur;
node_t *next;
gc_t cur_gc;
gc_t next_gc;
int cur_key;
retry:
cur = ACCESS_ONCE(*head);
if(cur == NULL) return 0;
cur_gc = ACCESS_ONCE(cur->gc);
compiler_barrier();
if(cur != ACCESS_ONCE(*head)) goto retry;
while(cur) {
cur_key = cur->key;
relink:
next = ACCESS_ONCE(cur->next);
if(next != NULL) next_gc = ACCESS_ONCE(next->gc);
compiler_barrier();
if(next != ACCESS_ONCE(cur->next))
{
nbrelink++;
goto relink;
}
if(cur_gc != ACCESS_ONCE(cur->gc))
{
nbretry++;
goto retry;
}
read_compute();
if (cur_key >= key)
return (cur_key == key);
cur = next;
cur_gc = next_gc;
}
return 0;
}
#else
int search(int key, node_t** head, lock_t* lock)
{
node_t *cur;
node_t *next;
gc_t cur_gc;
gc_t next_gc;
int cur_key;
#ifdef CHECK_CCRT
int l, t;
int prev_key;
t=0;
#endif
retry:
#ifdef CHECK_CCRT
l=0;
prev_key = 0;
#endif
cur = ACCESS_ONCE(*head);
if(cur == NULL) return 0;
cur_gc = ACCESS_ONCE(cur->gc);
compiler_barrier();
if(cur != ACCESS_ONCE(*head)) goto retry;
while(cur) {
cur_key = cur->key;
next = ACCESS_ONCE(cur->next);
if(next != NULL) next_gc = ACCESS_ONCE(next->gc);
compiler_barrier();
if((next != ACCESS_ONCE(cur->next)) || (cur_gc != ACCESS_ONCE(cur->gc)))
{
nbretry++;
goto retry;
}
read_compute();
if (cur_key >= key)
return (cur_key == key);
cur_gc = next_gc;
cur = next;
#ifdef CHECK_CCRT
if(prev_key > cur_key)
printf("loop %d, try %d, cur_key %d, prev_key %d", l, t, cur_key, prev_key);
assert(prev_key <= cur_key);
prev_key = cur_key;
l++;t++;
#endif
}
return 0;
}
#endif
#ifdef OSA_BEST
__thread node_t* free_later;
void free_node_later(int thread, node_t* n)
{
if(free_later)
{
free_node(free_later);
n->gc++;//last moment
//write_barrier();
}
free_later = n;
}
#else
void free_node_later(int thread, node_t* n)
{
n->gc++;//last moment
free_node(n);
}
#endif
inline
node_t* osa_new_node()
{
return new_node();
}
node_t* init_new_node()
{
return osa_new_node();
}