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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2016 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, LLC. All rights reserved
* Copyright (c) 2015-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2020 IBM Corporation. All rights reserved.
* Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file
*
* This file provides a "hotel" class:
*
* - A hotel has a fixed number of rooms (i.e., storage slots)
* - An arbitrary data pointer can check into an empty room at any time
* - The occupant of a room can check out at any time
* - Optionally, the occupant of a room can be forcibly evicted at a
* given time (i.e., when an pmix timer event expires).
* - The hotel has finite occupancy; if you try to checkin a new
* occupant and the hotel is already full, it will gracefully fail
* to checkin.
*
* One use case for this class is for ACK-based network retransmission
* schemes (NACK-based retransmission schemes probably can use
* pmix_ring_buffer).
*
* For ACK-based retransmission schemes, a hotel might be used
* something like this:
*
* - when a message is sent, check it in to a hotel with a timer
* - if an ACK is received, check it out of the hotel (which also cancels
* the timer)
* - if an ACK isn't received in time, the timer will expire and the
* upper layer will get a callback with the message
* - if an ACK is received late (i.e., after its timer has expired),
* then checkout will gracefully fail
*
* Note that this class intentionally provides pretty minimal
* functionality. It is intended to be used in performance-critical
* code paths -- extra functionality would simply add latency.
*
* There is an pmix_hotel_init() function to create a hotel, but no
* corresponding finalize; the destructor will handle all finalization
* issues. Note that when a hotel is destroyed, it will delete all
* pending events from the event base (i.e., all pending eviction
* callbacks); no further eviction callbacks will be invoked.
*/
;
/* User-supplied function to be invoked when an occupant is evicted. */
typedef void ;
/* Note that this is an internal data structure; it is not part of the
public pmix_hotel interface. Public consumers of pmix_hotel
shouldn't need to use this struct at all (we only have it here in
this .h file because some functions are inlined for speed, and need
to get to the internals of this struct).
The room struct should be as small as possible to be cache
friendly. Specifically: it would be great if multiple rooms could
fit in a single cache line because we'll always allocate a
contiguous set of rooms in an array. */
typedef struct pmix_hotel_room_t;
/* Note that this is an internal data structure; it is not part of the
public pmix_hotel interface. Public consumers of pmix_hotel
shouldn't need to use this struct at all (we only have it here in
this .h file because some functions are inlined for speed, and need
to get to the internals of this struct).
Use a unique struct for holding the arguments for eviction
callbacks. We *could* make the to-be-evicted pmix_hotel_room_t
instance as the argument, but we don't, for 2 reasons:
1. We want as many pmix_hotel_room_t's to fit in a cache line as
possible (i.e., to be as cache-friendly as possible). The
common/fast code path only needs to access the data in the
pmix_hotel_room_t (and not the callback argument data).
2. Evictions will be uncommon, so we don't mind penalizing them a
bit by making the data be in a separate cache line.
*/
typedef struct pmix_hotel_room_eviction_callback_arg_t;
typedef struct pmix_hotel_t pmix_hotel_t;
PMIX_EXPORT ;
/**
* Initialize the hotel.
*
* @param hotel Pointer to a hotel (IN)
* @param num_rooms The total number of rooms in the hotel (IN)
* @param evbase Pointer to event base used for eviction timeout
* @param eviction_timeout Max length of a stay at the hotel before
* the eviction callback is invoked (in seconds)
* @param evict_callback_fn Callback function invoked if an occupant
* does not check out before the eviction_timeout.
*
* NOTE: If the callback function is NULL, then no eviction timer
* will be set - occupants will remain checked into the hotel until
* explicitly checked out.
*
* Also note: the eviction_callback_fn should absolutely not call any
* of the hotel checkout functions. Specifically: the occupant has
* already been ("forcibly") checked out *before* the
* eviction_callback_fn is invoked.
*
* @return PMIX_SUCCESS if all initializations were successful. Otherwise,
* the error indicate what went wrong in the function.
*/
PMIX_EXPORT pmix_status_t ;
/**
* Check in an occupant to the hotel.
*
* @param hotel Pointer to hotel (IN)
* @param occupant Occupant to check in (opaque to the hotel) (IN)
* @param room The room number that identifies this occupant in the
* hotel (OUT).
*
* If there is room in the hotel, the occupant is checked in and the
* timer for that occupant is started. The occupant's room is
* returned in the "room" param.
*
* Note that once a room's checkout_expire timer expires, the occupant
* is forcibly checked out, and then the eviction callback is invoked.
*
* @return PMIX_SUCCESS if the occupant is successfully checked in,
* and the room parameter will contain a valid value.
* @return PMIX_ERR_TEMP_OUT_OF_RESOURCE is the hotel is full. Try
* again later.
*/
static inline pmix_status_t
/**
* Same as pmix_hotel_checkin(), but slightly optimized for when the
* caller *knows* that there is a room available.
*/
static inline void
/**
* Check the specified occupant out of the hotel.
*
* @param hotel Pointer to hotel (IN)
* @param room Room number to checkout (IN)
*
* If there is an occupant in the room, their timer is canceled and
* they are checked out.
*
* Nothing is returned (as a minor optimization).
*/
static inline void
/**
* Check the specified occupant out of the hotel and return the occupant.
*
* @param hotel Pointer to hotel (IN)
* @param room Room number to checkout (IN)
* @param void * occupant (OUT)
* If there is an occupant in the room, their timer is canceled and
* they are checked out.
*
* Use this checkout and when caller needs the occupant
*/
static inline void
/**
* Returns true if the hotel is empty (no occupant)
* @param hotel Pointer to hotel (IN)
* @return bool true if empty false if there is a occupant(s)
*
*/
static inline bool
/**
* Access the occupant of a room, but leave them checked into their room.
*
* @param hotel Pointer to hotel (IN)
* @param room Room number to checkout (IN)
* @param void * occupant (OUT)
*
* This accessor function is typically used to cycle across the occupants
* to check for someone already present that matches a description.
*/
static inline void
/* PMIX_HOTEL_H */