Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
lists.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// templated intrusive linked lists
19
20#ifndef REALM_LISTS_H
21#define REALM_LISTS_H
22
23#include "realm/atomics.h"
24
25#ifdef REALM_ON_WINDOWS
26#define REALM_PMTA_DECL(structtype, membertype, name) typename name
27#define REALM_PMTA_DEFN(structtype, membertype, name) \
28 struct name##_pmta { \
29 static membertype &deref(structtype *obj) { return obj->name; } \
30 static const membertype &deref(const structtype *obj) { return obj->name; } \
31 }
32#define REALM_PMTA_USE(structtype, name) name##_pmta
33#define REALM_PMTA_DEREF(obj, ptrname) (ptrname::deref(obj))
34#else
35#define REALM_PMTA_DECL(structtype, membertype, name) membertype structtype::*name
36#ifdef __PGIC__
37// PGI warns on empty declarations so add a useless typedef
38#define REALM_PMTA_DEFN(structtype, membertype, name) typedef int pgi_appeasement_##name
39#else
40#define REALM_PMTA_DEFN(structtype, membertype, name)
41#endif
42#define REALM_PMTA_USE(structtype, name) &structtype::name
43#define REALM_PMTA_DEREF(obj, ptrname) ((obj)->*(ptrname))
44#endif
45
46namespace Realm {
47
48#ifdef DEBUG_REALM
49// define DEBUG_REALM_LISTS
50#endif
51
52 template <typename T>
56
57 T *next;
58#ifdef DEBUG_REALM_LISTS
59 // actual type is IntrusiveList<T, LINK, LT>, but that would be a
60 // circular definition...
61 void *current_list;
62#endif
63 };
64
65 template <typename T, REALM_PMTA_DECL(T, IntrusiveListLink<T>, LINK), typename LT>
67 public:
68 typedef T ITEMTYPE;
69 typedef LT LOCKTYPE;
70
73
74 // "copying" a list is only allowed if both lists are empty (this is most
75 // useful when creating lists inside of containers)
78
79 template <typename LT2>
81
82 // sucks the contents of 'take_from' into the end of the current list
83 template <typename LT2>
85
86 void push_back(T *new_entry);
87 void push_front(T *new_entry);
88
89 bool empty(void) const;
90
91 T *front(void) const;
92 T *pop_front(void);
93
94 size_t erase(T *entry);
95
96 // O(n) walk - we don't maintain a running size counter, so use this only
97 // when the size is needed (e.g. diagnostics, quiescence reporting)
98 size_t size(void) const;
99
100 mutable LT lock;
103 };
104
105 template <typename T>
109
111 T **lastlink_within_pri; // for O(1) append
113#ifdef DEBUG_REALM_LISTS
114 // actual type is IntrusivePriorityList<T, ...>, but that would be a
115 // circular definition...
116 void *current_list;
117#endif
118 };
119
120 template <typename T, typename PT,
122 REALM_PMTA_DECL(T, PT, PRI), typename LT>
124 public:
125 typedef T ITEMTYPE;
126 typedef PT PRITYPE;
127 typedef LT LOCKTYPE;
128
131
132 // "copying" a list is only allowed if both lists are empty (this is most
133 // useful when creating lists inside of containers)
137
138 template <typename LT2>
140
141 // sucks the contents of 'take_from' into the end of the current list
142 template <typename LT2>
144
145 // places new item at front or back of its priority level
146 void push_back(T *new_entry);
147 void push_front(T *new_entry);
148
149 bool empty(void) const;
150 bool empty(PT min_priority) const;
151
152 // this call isn't thread safe - the pointer returned may be accessed only
153 // if the caller can guarantee no concurrent pops have occurred
154 T *front(void) const;
155
156 T *pop_front(void);
157 T *pop_front(PT min_priority);
158
159 // calls callback for each element in list
160 template <typename CALLABLE>
161 void foreach(CALLABLE &cb);
162
163 // we don't maintain the size, so this is slow - use only for debugging
164 size_t size(void) const;
165
166 mutable LT lock;
168 // TODO: consider indexing if many priorities exists simultaneously?
169 };
170
171 template <typename T, typename PT,
173 REALM_PMTA_DECL(T, PT, PRI), typename LT>
174 std::ostream &operator<<(std::ostream &os,
176
177}; // namespace Realm
178
179#include "realm/lists.inl"
180
181#endif // ifndef REALM_LISTS_H
Definition lists.h:66
IntrusiveList< T, LINK, LT > & operator=(const IntrusiveList< T, LINK, LT > &copy_from)
void swap(IntrusiveList< T, LINK, LT2 > &swap_with)
LT lock
Definition lists.h:100
void push_front(T *new_entry)
bool empty(void) const
void absorb_append(IntrusiveList< T, LINK, LT2 > &take_from)
void push_back(T *new_entry)
IntrusiveListLink< T > head
Definition lists.h:101
T * front(void) const
IntrusiveList(const IntrusiveList< T, LINK, LT > &copy_from)
T ITEMTYPE
Definition lists.h:68
IntrusiveListLink< T > * lastlink
Definition lists.h:102
LT LOCKTYPE
Definition lists.h:69
size_t erase(T *entry)
size_t size(void) const
Definition lists.h:123
T ITEMTYPE
Definition lists.h:125
bool empty(PT min_priority) const
T * pop_front(PT min_priority)
void absorb_append(IntrusivePriorityList< T, PT, LINK, PRI, LT2 > &take_from)
IntrusivePriorityList(const IntrusivePriorityList< T, PT, LINK, PRI, LT > &copy_from)
void push_back(T *new_entry)
void push_front(T *new_entry)
void swap(IntrusivePriorityList< T, PT, LINK, PRI, LT2 > &swap_with)
size_t size(void) const
IntrusivePriorityList< T, PT, LINK, PRI, LT > & operator=(const IntrusivePriorityList< T, PT, LINK, PRI, LT > &copy_from)
LT LOCKTYPE
Definition lists.h:127
PT PRITYPE
Definition lists.h:126
T * head
Definition lists.h:167
LT lock
Definition lists.h:166
#define REALM_PMTA_DECL(structtype, membertype, name)
Definition lists.h:35
Definition activemsg.h:42
std::ostream & operator<<(std::ostream &os, const DenseRectangleList< N, T > &drl)