Commit 0948ea23 authored by Matthieu Dorier's avatar Matthieu Dorier

added method to free user arguments

parent 76c47a56
......@@ -71,7 +71,7 @@ int main(int argc, char** argv)
// create migration class
ret = remi_provider_register_migration_class(remi_prov,
"my_migration_class", my_migration_callback, NULL);
"my_migration_class", my_migration_callback, NULL, NULL);
if(ret != REMI_SUCCESS) {
fprintf(stderr, "ERROR: remi_provider_register_migration_class() returned %d\n", ret);
ret = -1;
......
......@@ -30,6 +30,13 @@ typedef struct remi_provider* remi_provider_t;
typedef void (*remi_migration_callback_t)(remi_fileset_t, void*);
#define REMI_MIGRATION_CALLBACK_NULL ((remi_migration_callback_t)0)
/**
* @brief Type of callback called on void* user arguments when the
* provider is destroyed.
*/
typedef void (*remi_uarg_free_t)(void*);
/**
* @brief Registers a new REMI provider. The provider will be
* automatically destroyed upon finalizing the margo instance.
......@@ -54,6 +61,7 @@ int remi_provider_register(
* @param[in] provider Provider in which to register a migration class.
* @param[in] class_name Migration class name.
* @param[in] callback Callback to call after migration of a fileset of this class.
* @param[in] free_fn Function to call on uargs when the provider is destroyed.
* @param[in] uargs User-argument to pass to the callback.
*
* @return REMI_SUCCESS or error code defined in remi-common.h.
......@@ -62,6 +70,7 @@ int remi_provider_register_migration_class(
remi_provider_t provider,
const char* class_name,
remi_migration_callback_t callback,
remi_uarg_free_t free_fn,
void* uargs);
#if defined(__cplusplus)
......
......@@ -163,7 +163,9 @@ extern "C" int remi_fileset_migrate(
}
// expose the segments for bulk operations
auto localBulk = ph->m_client->m_engine->expose(theData, tl::bulk_mode::read_only);
tl::bulk localBulk;
if(theData.size() != 0)
localBulk = ph->m_client->m_engine->expose(theData, tl::bulk_mode::read_only);
// send the RPC
auto localRoot = fileset->m_root;
......
......@@ -22,6 +22,7 @@ namespace tl = thallium;
struct migration_class {
remi_migration_callback_t m_callback;
remi_uarg_free_t m_free;
void* m_uargs;
};
......@@ -148,7 +149,13 @@ struct remi_provider : public tl::provider<remi_provider> {
static void on_finalize(void* uargs) {
auto provider = static_cast<remi_provider_t>(uargs);
for(auto& klass : provider->m_migration_classes) {
if(klass.second.m_free != nullptr) {
klass.second.m_free(klass.second.m_uargs);
}
}
delete provider->m_engine;
delete provider;
}
extern "C" int remi_provider_register(
......@@ -169,6 +176,7 @@ extern "C" int remi_provider_register_migration_class(
remi_provider_t provider,
const char* class_name,
remi_migration_callback_t callback,
remi_uarg_free_t free_fn,
void* uargs)
{
if(provider == REMI_PROVIDER_NULL || class_name == NULL)
......@@ -178,5 +186,6 @@ extern "C" int remi_provider_register_migration_class(
auto& klass = provider->m_migration_classes[class_name];
klass.m_callback = callback;
klass.m_uargs = uargs;
klass.m_free = free_fn;
return REMI_SUCCESS;
}
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