-
Notifications
You must be signed in to change notification settings - Fork 42
/
set-lock.c
69 lines (58 loc) · 1.57 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
/*
* File: set-lock.c
* Author: Vasileios Trigonakis <[email protected]>
* Description:
* set-lock.c is part of ASCYLIB
*
* Copyright (c) 2015 Vasileios Trigonakis <[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;
map_t*
map_new_l(size_t size)
{
map_t* map = ssalloc_aligned(CACHE_LINE_SIZE, sizeof(map_t));
assert(map != NULL);
map->size = size;
map->array = (key_val_t*) ssalloc_aligned(CACHE_LINE_SIZE, size * sizeof(key_val_t));
assert(map->array != NULL);
memset(map->array, 0, size * sizeof(key_val_t));
map->lock = (volatile optik_t*) ssalloc_aligned(CACHE_LINE_SIZE, sizeof(optik_t));
if (map->lock == NULL)
{
perror("malloc");
exit(1);
}
optik_init(map->lock);
MEM_BARRIER;
return map;
}
void map_delete_l(map_t *map)
{
ssfree(map->array);
ssfree((void*) map->lock);
ssfree(map);
}
int map_size_l(map_t *map)
{
int size = 0;
int i;
for (i = 0; i < map->size; i++)
{
size += (map->array[i].key != 0);
}
return size;
}