-
Notifications
You must be signed in to change notification settings - Fork 42
/
linkedlist-lock.c
134 lines (110 loc) · 2.83 KB
/
linkedlist-lock.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
/*
* File: linkedlist-lock.c
* Author: Vincent Gramoli <[email protected]>,
* Vasileios Trigonakis <[email protected]>
* Description:
* linkedlist-lock.c is part of ASCYLIB
*
* Copyright (c) 2014 Vasileios Trigonakis <[email protected]>,
* Tudor David <[email protected]>
* Distributed Programming Lab (LPD), EPFL
*
* ASCYLIB 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, version 2
* of the License.
*
* 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.
*
*/
#include "intset.h"
#include "utils.h"
__thread ssmem_allocator_t* alloc;
node_l_t*
new_node_l(skey_t key, sval_t val, node_l_t* next, int initializing)
{
volatile node_l_t *node;
#if GC == 1
if (initializing) /* for initialization AND the coupling algorithm */
{
node = (volatile node_l_t *) ssalloc(sizeof(node_l_t));
}
else
{
node = (volatile node_l_t *) ssmem_alloc(alloc, sizeof(node_l_t));
}
#else
node = (volatile node_l_t *) ssalloc(sizeof(node_l_t));
#endif
if (node == NULL)
{
perror("malloc @ new_node");
exit(1);
}
node->key = key;
node->val = val;
node->next = next;
#if defined(__tile__)
/* on tilera you may have store reordering causing the pointer to a new node
to become visible, before the contents of the node are visible */
MEM_BARRIER;
#endif /* __tile__ */
return (node_l_t*) node;
}
intset_l_t *set_new_l()
{
intset_l_t *set;
node_l_t *min, *max;
if ((set = (intset_l_t *)ssalloc_aligned(CACHE_LINE_SIZE, sizeof(intset_l_t))) == NULL)
{
perror("malloc");
exit(1);
}
max = new_node_l(KEY_MAX, 0, NULL, 1);
/* ssalloc_align_alloc(0); */
min = new_node_l(KEY_MIN, 0, max, 1);
set->head = min;
set->lock = (volatile ptlock_t*) ssalloc_aligned(CACHE_LINE_SIZE, sizeof(ptlock_t));
if (set->lock == NULL)
{
perror("malloc");
exit(1);
}
INIT_LOCK_A(set->lock);
MEM_BARRIER;
return set;
}
void
node_delete_l(node_l_t *node)
{
}
void set_delete_l(intset_l_t *set)
{
node_l_t *node, *next;
node = set->head;
while (node != NULL)
{
next = node->next;
DESTROY_LOCK(&node->lock);
/* free(node); */
ssfree((void*) node); /* TODO : fix with ssmem */
node = next;
}
ssfree(set);
}
int set_size_l(intset_l_t *set)
{
int size = 0;
node_l_t *node;
/* We have at least 2 elements */
node = set->head->next;
while (node->next != NULL)
{
size++;
node = node->next;
}
return size;
}