-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdlmset_headers.h
135 lines (86 loc) · 3.03 KB
/
dlmset_headers.h
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
/**
* @file dlmset_headers.h
* @brief MSet function prototypes. An MSet, or multi-set, is an iset which
* stores a large range of elements in a shared ptr array between threads.
* However, each thread has its own set (and items cannot be in multiple sets).
*
* @author Dominique LaSalle <[email protected]>
* Copyright (c) 2013-2015, Dominique LaSalle
* @version 1
* @date 2013-10-05
*/
/* prefixing ugliness */
#define DLMSET_PRE2(prefix,suffix) prefix ## _ ## suffix
#define DLMSET_PRE1(prefix,suffix) DLMSET_PRE2(prefix,suffix)
#define DLMSET_PUB(name) DLMSET_PRE1(DLMSET_PREFIX,name)
#define DLMSET_PRI(name) DLMSET_PRE1(_,DLMSET_PRE1(DLMSET_PREFIX,name))
#include "dlthread.h"
/******************************************************************************
* TYPES ***********************************************************************
******************************************************************************/
typedef struct DLMSET_PRI(mset_info_t) {
size_t size;
DLMSET_TYPE_T * ind;
/* ensure the structure is 64 bytes to avoid false sharing */
char _padding[CACHE_LINE_SIZE - (sizeof(size_t)+sizeof(DLMSET_TYPE_T*))];
} DLMSET_PRI(mset_info_t);
DL_STATIC_ASSERT(sizeof(DLMSET_PRI(mset_info_t)) == CACHE_LINE_SIZE);
typedef struct DLMSET_PUB(mset_t) {
DLMSET_TYPE_T min;
DLMSET_TYPE_T max;
DLMSET_PRI(mset_info_t) * info;
DLMSET_TYPE_T * __DL_RESTRICT ptr;
dlthread_comm_t comm;
} DLMSET_PUB(mset_t);
#ifndef DLMSET_STATIC
/******************************************************************************
* FUNCTION PROTOTYPES *********************************************************
******************************************************************************/
/**
* @brief Allocate and initialize an MSet with a minimum and maximum element
* value. The minimum and maximum are only used from the thread with id 0.
*
* @param min The minimum element (inclusive).
* @param max The maximum element (exclusive).
* @param size The maximum number of elements this thread will have in the set.
* @param comm The thread communicator.
*
* @return The MSet.
*/
DLMSET_PUB(mset_t) * DLMSET_PUB(mset_create)(
DLMSET_TYPE_T min,
DLMSET_TYPE_T max,
size_t size,
dlthread_comm_t comm);
DLMSET_TYPE_T DLMSET_PUB(mset_get)(
size_t i,
DLMSET_PUB(mset_t) const * set);
int DLMSET_PUB(mset_contains)(
DLMSET_TYPE_T item,
DLMSET_PUB(mset_t) const * set);
int DLMSET_PUB(mset_add)(
DLMSET_TYPE_T item,
DLMSET_PUB(mset_t) * set);
int DLMSET_PUB(mset_remove)(
DLMSET_TYPE_T item,
DLMSET_PUB(mset_t) * set);
DLMSET_TYPE_T DLMSET_PUB(mset_remove_index)(
size_t idx,
DLMSET_PUB(mset_t) * set);
size_t DLMSET_PUB(mset_clear)(
DLMSET_PUB(mset_t) * set);
void DLMSET_PUB(mset_free)(
DLMSET_PUB(mset_t) * ptr);
#undef DLMSET_PRE2
#undef DLMSET_PRE1
#undef DLMSET_PRI
#undef DLMSET_PUB
#else
#undef DLMSET_PRE2
#undef DLMSET_PRE1
#undef DLMSET_PRI
#undef DLMSET_PUB
#define DLMSET_VISIBILITY static
#include "dlmset_funcs.h"
#undef DLMSET_VISIBILITY
#endif