Commit 91e9c0b4 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added functions to get the finalize and prefinalize callbacks

parent a4e8db81
......@@ -34,6 +34,7 @@ struct margo_instance;
typedef struct margo_instance* margo_instance_id;
typedef struct margo_data* margo_data_ptr;
typedef struct margo_request_struct* margo_request;
typedef void(*margo_finalize_callback_t)(void*);
#define MARGO_INSTANCE_NULL ((margo_instance_id)NULL)
#define MARGO_REQUEST_NULL ((margo_request)NULL)
......@@ -191,6 +192,20 @@ void margo_push_prefinalize_callback(
int margo_pop_prefinalize_callback(
margo_instance_id mid);
/**
* @brief Get the last pre-finalize callback that was pushed into the margo instance
* as well as its argument. If a callback is found, this function returns 1, otherwise
* it returns 0.
*
* @param mid Margo instance.
* @param cb Returned callback.
* @param uargs Uargs.
*/
int margo_top_prefinalize_callback(
margo_instance_id mid,
margo_finalize_callback_t *cb,
void** uargs);
/**
* @brief Installs a callback to be called before the margo instance is finalized,
* and before the Mercury progress loop is terminated.
......@@ -211,7 +226,7 @@ int margo_pop_prefinalize_callback(
void margo_provider_push_prefinalize_callback(
margo_instance_id mid,
void* owner,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs);
/**
......@@ -226,6 +241,22 @@ int margo_provider_pop_prefinalize_callback(
margo_instance_id mid,
void* owner);
/**
* @brief Get the last prefinalize callback that was pushed into the margo instance
* by the specified owner. If a callback is found, this function returns 1, otherwise
* it returns 0.
*
* @param mid Margo instance.
* @param owner Owner of the callback.
* @param cb Returned callback.
* @param uargs Returned user arguments.
*/
int margo_provider_top_prefinalize_callback(
margo_instance_id mid,
void* owner,
margo_finalize_callback_t *cb,
void** uargs);
/**
* Installs a callback to be called before the margo instance is finalize.
* Callbacks installed will be called in reverse ordered than they have been
......@@ -244,7 +275,7 @@ int margo_provider_pop_prefinalize_callback(
*/
void margo_push_finalize_callback(
margo_instance_id mid,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs);
/**
......@@ -257,6 +288,21 @@ void margo_push_finalize_callback(
int margo_pop_finalize_callback(
margo_instance_id mid);
/**
* @brief Returns the last finalize callback that was pushed into the margo instance,
* along with its argument. If successful, this function returns 1. Otherwise it returns 0.
*
* @param mid Margo instance
* @param cb Returned callback
* @param uargs Returned user arguments
*
* @return 1 if successful, 0 otherwise.
*/
int margo_top_finalize_callback(
margo_instance_id mid,
margo_finalize_callback_t *cb,
void** uargs);
/**
* @brief Installs a callback to be called before the margo instance is finalized.
* The owner pointer allows to identify callbacks installed by particular providers.
......@@ -276,7 +322,7 @@ int margo_pop_finalize_callback(
void margo_provider_push_finalize_callback(
margo_instance_id mid,
void* owner,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs);
/**
......@@ -291,6 +337,24 @@ int margo_provider_pop_finalize_callback(
margo_instance_id mid,
void* owner);
/**
* @brief Gets the last finalize callback that was pushed into the margo instance
* by the specified owner. If successful, this function returns 1, otherwise it
* returns 0.
*
* @param mid Margo instance
* @param owner Owner of the callback.
* @param cb Returned callback.
* @param uargs Returned user agument.
*
* @return 1 if successful, 0 otherwise.
*/
int margo_provider_top_finalize_callback(
margo_instance_id mid,
void* owner,
margo_finalize_callback_t *cb,
void** uargs);
/**
* Allows the passed Margo instance to be shut down remotely
* using margo_shutdown_remote_instance().
......
......@@ -712,7 +712,7 @@ hg_bool_t margo_is_listening(
void margo_push_prefinalize_callback(
margo_instance_id mid,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs)
{
margo_provider_push_prefinalize_callback(
......@@ -728,10 +728,18 @@ int margo_pop_prefinalize_callback(
return margo_provider_pop_prefinalize_callback(mid, NULL);
}
int margo_top_prefinalize_callback(
margo_instance_id mid,
margo_finalize_callback_t *cb,
void** uargs)
{
return margo_provider_top_prefinalize_callback(mid, NULL, cb, uargs);
}
void margo_provider_push_prefinalize_callback(
margo_instance_id mid,
void* owner,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs)
{
if(cb == NULL) return;
......@@ -747,6 +755,29 @@ void margo_provider_push_prefinalize_callback(
mid->prefinalize_cb = fcb;
}
int margo_provider_top_prefinalize_callback(
margo_instance_id mid,
void* owner,
margo_finalize_callback_t *cb,
void** uargs)
{
struct margo_finalize_cb* prev = NULL;
struct margo_finalize_cb* fcb = mid->prefinalize_cb;
while(fcb != NULL && fcb->owner != owner) {
prev = fcb;
fcb = fcb->next;
}
if(fcb == NULL) return 0;
if(prev == NULL) {
mid->prefinalize_cb = fcb->next;
} else {
prev->next = fcb->next;
}
*cb = fcb->callback;
*uargs = fcb->uargs;
return 1;
}
int margo_provider_pop_prefinalize_callback(
margo_instance_id mid,
void* owner)
......@@ -769,7 +800,7 @@ int margo_provider_pop_prefinalize_callback(
void margo_push_finalize_callback(
margo_instance_id mid,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs)
{
margo_provider_push_finalize_callback(
......@@ -785,10 +816,18 @@ int margo_pop_finalize_callback(
return margo_provider_pop_finalize_callback(mid, NULL);
}
int margo_top_finalize_callback(
margo_instance_id mid,
margo_finalize_callback_t *cb,
void** uargs)
{
return margo_provider_top_finalize_callback(mid, NULL, cb, uargs);
}
void margo_provider_push_finalize_callback(
margo_instance_id mid,
void* owner,
void(*cb)(void*),
margo_finalize_callback_t cb,
void* uargs)
{
if(cb == NULL) return;
......@@ -824,6 +863,29 @@ int margo_provider_pop_finalize_callback(
return 1;
}
int margo_provider_top_finalize_callback(
margo_instance_id mid,
void* owner,
margo_finalize_callback_t *cb,
void** uargs)
{
struct margo_finalize_cb* prev = NULL;
struct margo_finalize_cb* fcb = mid->finalize_cb;
while(fcb != NULL && fcb->owner != owner) {
prev = fcb;
fcb = fcb->next;
}
if(fcb == NULL) return 0;
if(prev == NULL) {
mid->finalize_cb = fcb->next;
} else {
prev->next = fcb->next;
}
*cb = fcb->callback;
*uargs = fcb->uargs;
return 1;
}
void margo_enable_remote_shutdown(margo_instance_id mid)
{
mid->enable_remote_shutdown = 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment