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 mutable LT lock;
99 };
100
101 template <typename T>
105
107 T **lastlink_within_pri; // for O(1) append
109#ifdef DEBUG_REALM_LISTS
110 // actual type is IntrusivePriorityList<T, ...>, but that would be a
111 // circular definition...
112 void *current_list;
113#endif
114 };
115
116 template <typename T, typename PT,
118 REALM_PMTA_DECL(T, PT, PRI), typename LT>
120 public:
121 typedef T ITEMTYPE;
122 typedef PT PRITYPE;
123 typedef LT LOCKTYPE;
124
127
128 // "copying" a list is only allowed if both lists are empty (this is most
129 // useful when creating lists inside of containers)
133
134 template <typename LT2>
136
137 // sucks the contents of 'take_from' into the end of the current list
138 template <typename LT2>
140
141 // places new item at front or back of its priority level
142 void push_back(T *new_entry);
143 void push_front(T *new_entry);
144
145 bool empty(void) const;
146 bool empty(PT min_priority) const;
147
148 // this call isn't thread safe - the pointer returned may be accessed only
149 // if the caller can guarantee no concurrent pops have occurred
150 T *front(void) const;
151
152 T *pop_front(void);
153 T *pop_front(PT min_priority);
154
155 // calls callback for each element in list
156 template <typename CALLABLE>
157 void foreach(CALLABLE &cb);
158
159 // we don't maintain the size, so this is slow - use only for debugging
160 size_t size(void) const;
161
162 mutable LT lock;
164 // TODO: consider indexing if many priorities exists simultaneously?
165 };
166
167 template <typename T, typename PT,
169 REALM_PMTA_DECL(T, PT, PRI), typename LT>
170 std::ostream &operator<<(std::ostream &os,
172
173}; // namespace Realm
174
175#include "realm/lists.inl"
176
177#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:96
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:97
T * front(void) const
IntrusiveList(const IntrusiveList< T, LINK, LT > &copy_from)
T ITEMTYPE
Definition lists.h:68
IntrusiveListLink< T > * lastlink
Definition lists.h:98
LT LOCKTYPE
Definition lists.h:69
size_t erase(T *entry)
Definition lists.h:119
T ITEMTYPE
Definition lists.h:121
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:123
PT PRITYPE
Definition lists.h:122
T * head
Definition lists.h:163
LT lock
Definition lists.h:162
#define REALM_PMTA_DECL(structtype, membertype, name)
Definition lists.h:35
Definition activemsg.h:38
std::ostream & operator<<(std::ostream &os, const DenseRectangleList< N, T > &drl)