Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
/*
|
2016-01-08 06:22:35 +03:00
|
|
|
* Copyright (c) 2012-2016 Cisco Systems, Inc. All rights reserved.
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
* Copyright (c) 2012 Los Alamos National Security, LLC. All rights reserved
|
2015-07-11 16:42:23 +03:00
|
|
|
* Copyright (c) 2015 Intel, Inc. All rights reserved
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opal_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "opal/mca/event/event.h"
|
|
|
|
#include "opal/class/opal_hotel.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void local_eviction_callback(int fd, short flags, void *arg)
|
|
|
|
{
|
2015-06-24 06:59:57 +03:00
|
|
|
opal_hotel_room_eviction_callback_arg_t *eargs =
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
(opal_hotel_room_eviction_callback_arg_t*) arg;
|
|
|
|
void *occupant = eargs->hotel->rooms[eargs->room_num].occupant;
|
|
|
|
|
2016-01-08 06:22:35 +03:00
|
|
|
/* Remove the occurpant from the room.
|
|
|
|
|
|
|
|
Do not change this logic without also changing the same logic
|
|
|
|
in opal_hotel_checkout() and
|
|
|
|
opal_hotel_checkout_and_return_occupant(). */
|
|
|
|
opal_hotel_t *hotel = eargs->hotel;
|
|
|
|
opal_hotel_room_t *room = &(hotel->rooms[eargs->room_num]);
|
|
|
|
room->occupant = NULL;
|
|
|
|
hotel->last_unoccupied_room++;
|
|
|
|
assert(hotel->last_unoccupied_room < hotel->num_rooms);
|
|
|
|
hotel->unoccupied_rooms[hotel->last_unoccupied_room] = eargs->room_num;
|
|
|
|
|
|
|
|
/* Invoke the user callback to tell them that they were evicted */
|
|
|
|
hotel->evict_callback_fn(hotel,
|
|
|
|
eargs->room_num,
|
|
|
|
occupant);
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int opal_hotel_init(opal_hotel_t *h, int num_rooms,
|
2015-07-11 16:42:23 +03:00
|
|
|
opal_event_base_t *evbase,
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
uint32_t eviction_timeout,
|
|
|
|
int eviction_event_priority,
|
|
|
|
opal_hotel_eviction_callback_fn_t evict_callback_fn)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Bozo check */
|
|
|
|
if (num_rooms <= 0 ||
|
|
|
|
NULL == evict_callback_fn) {
|
|
|
|
return OPAL_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
h->num_rooms = num_rooms;
|
2015-07-11 16:42:23 +03:00
|
|
|
h->evbase = evbase;
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
h->eviction_timeout.tv_usec = eviction_timeout % 1000000;
|
|
|
|
h->eviction_timeout.tv_sec = eviction_timeout / 1000000;
|
|
|
|
h->evict_callback_fn = evict_callback_fn;
|
|
|
|
h->rooms = (opal_hotel_room_t*)malloc(num_rooms * sizeof(opal_hotel_room_t));
|
|
|
|
if (NULL != evict_callback_fn) {
|
2015-06-24 06:59:57 +03:00
|
|
|
h->eviction_args =
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
(opal_hotel_room_eviction_callback_arg_t*)malloc(num_rooms * sizeof(opal_hotel_room_eviction_callback_arg_t));
|
|
|
|
}
|
|
|
|
h->unoccupied_rooms = (int*) malloc(num_rooms * sizeof(int));
|
|
|
|
h->last_unoccupied_room = num_rooms - 1;
|
|
|
|
|
|
|
|
for (i = 0; i < num_rooms; ++i) {
|
|
|
|
/* Mark this room as unoccupied */
|
|
|
|
h->rooms[i].occupant = NULL;
|
|
|
|
|
|
|
|
/* Setup this room in the unoccupied index array */
|
|
|
|
h->unoccupied_rooms[i] = i;
|
|
|
|
|
|
|
|
/* Setup the eviction callback args */
|
|
|
|
h->eviction_args[i].hotel = h;
|
|
|
|
h->eviction_args[i].room_num = i;
|
|
|
|
|
|
|
|
/* Create this room's event (but don't add it) */
|
2015-07-11 16:42:23 +03:00
|
|
|
if (NULL != h->evbase) {
|
|
|
|
opal_event_set(h->evbase,
|
|
|
|
&(h->rooms[i].eviction_timer_event),
|
|
|
|
-1, 0, local_eviction_callback,
|
|
|
|
&(h->eviction_args[i]));
|
|
|
|
|
|
|
|
/* Set the priority so it gets serviced properly */
|
|
|
|
opal_event_set_priority(&(h->rooms[i].eviction_timer_event),
|
|
|
|
eviction_event_priority);
|
|
|
|
}
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return OPAL_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void constructor(opal_hotel_t *h)
|
|
|
|
{
|
|
|
|
h->num_rooms = 0;
|
2015-07-11 16:42:23 +03:00
|
|
|
h->evbase = NULL;
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
h->eviction_timeout.tv_sec = 0;
|
|
|
|
h->eviction_timeout.tv_usec = 0;
|
|
|
|
h->evict_callback_fn = NULL;
|
|
|
|
h->rooms = NULL;
|
|
|
|
h->eviction_args = NULL;
|
|
|
|
h->unoccupied_rooms = NULL;
|
|
|
|
h->last_unoccupied_room = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destructor(opal_hotel_t *h)
|
|
|
|
{
|
2012-11-02 18:00:54 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Go through all occupied rooms and destroy their events */
|
2015-07-11 16:42:23 +03:00
|
|
|
if (NULL != h->evbase) {
|
|
|
|
for (i = 0; i < h->num_rooms; ++i) {
|
|
|
|
if (NULL != h->rooms[i].occupant) {
|
|
|
|
opal_event_del(&(h->rooms[i].eviction_timer_event));
|
|
|
|
}
|
2012-11-02 18:00:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add new "opal_hotel" class. Abstractly speaking, this class does the
following:
* Provides a fixed number of resource slots (i.e., "hotel rooms").
* Allows one thing to occupy a resource slot at a time (i.e., each
hotel room can have an occupant check in to that room).
* Resource slots can be vacated at any time (i.e., occupants can
voluntarily check out of their hotel room).
* Resource slots can be occupied for a specific maximum amount of
time. If that time expires, the occupant is forcibly evicted and
the upper layer is notified via (libevent) callback (i.e., the maid
will kick an occupant of out of their room when their reservation
is over).
This class can be to be used for things like retransmission schemes
for unreliable transports. For example, a message sent on an
unreliable transport can be checked in to a hotel room. If an ACK for
that message is received, the message can be checked out. But if the
ACK is never received, the message will eventually be evicted from its
room and the upper layer will be notified that the message failed to
check out in time (i.e., that an ACK for that message was not received
in time).
Code using this class is currently being developed off-trunk, but will
be coming to SVN soon.
This commit was SVN r27067.
2012-08-16 21:29:55 +04:00
|
|
|
if (NULL != h->rooms) {
|
|
|
|
free(h->rooms);
|
|
|
|
}
|
|
|
|
if (NULL != h->eviction_args) {
|
|
|
|
free(h->eviction_args);
|
|
|
|
}
|
|
|
|
if (NULL != h->unoccupied_rooms) {
|
|
|
|
free(h->unoccupied_rooms);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_CLASS_INSTANCE(opal_hotel_t,
|
|
|
|
opal_object_t,
|
|
|
|
constructor,
|
|
|
|
destructor);
|