-
Notifications
You must be signed in to change notification settings - Fork 42
/
queue-lock.c
96 lines (81 loc) · 1.97 KB
/
queue-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
/*
* File: skiplist-lock.c
* Author: Vincent Gramoli <[email protected]>,
* Vasileios Trigonakis <[email protected]>
* Description:
* skiplist-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 "queue-lock.h"
#include "utils.h"
__thread ssmem_allocator_t* alloc;
queue_node_t*
queue_new_node(skey_t key, sval_t val, queue_node_t* next)
{
#if GC == 1
queue_node_t* node = ssmem_alloc(alloc, sizeof(*node));
#else
queue_node_t* node = ssalloc(sizeof(*node));
#endif
node->key = key;
node->val = val;
node->next = next;
#ifdef __tile__
MEM_BARRIER;
#endif
return node;
}
void
queue_delete_node(queue_node_t *n)
{
#if GC == 1
ssmem_free(alloc, (void*) n);
#endif
}
queue_t*
queue_new()
{
queue_t *set;
if ((set = (queue_t*) ssalloc_aligned(CACHE_LINE_SIZE, sizeof(queue_t))) == NULL)
{
perror("malloc");
exit(1);
}
queue_node_t* node = (queue_node_t*) ssalloc_aligned(CACHE_LINE_SIZE, sizeof(queue_node_t));
node->next = NULL;
set->head = node;
set->tail = node;
return set;
}
void
queue_delete(queue_t *set)
{
printf("queue_delete - implement me\n");
}
int queue_size(queue_t *set)
{
int size = 0;
queue_node_t *node;
/* We have at least 2 elements */
node = set->head;
while (node->next != NULL)
{
size++;
node = node->next;
}
return size;
}