forked from LPD-EPFL/ASCYLIB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-lock.c
71 lines (60 loc) · 1.72 KB
/
set-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
/*
* 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;
intset_l_t*
set_new_l(size_t size)
{
intset_l_t* set = ssalloc_aligned(CACHE_LINE_SIZE, sizeof(intset_l_t));
assert(set != NULL);
set->size = size;
set->array = (key_val_t*) ssalloc_aligned(CACHE_LINE_SIZE, size * sizeof(key_val_t));
assert(set->array != NULL);
memset(set->array, 0, size * sizeof(key_val_t));
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 set_delete_l(intset_l_t *set)
{
ssfree(set->array);
ssfree((void*) set->lock);
ssfree(set);
}
int set_size_l(intset_l_t *set)
{
int size = 0;
int i;
for (i = 0; i < set->size; i++)
{
size += (set->array[i].key != 0);
}
return size;
}