diff --git a/examples/multiplex/svc1.c b/examples/multiplex/svc1.c index 12f06203f3369e5532e6556776d3e566f725cd7c..0ee59a8bc11b087a6c758d366de124ec0d56c61d 100644 --- a/examples/multiplex/svc1.c +++ b/examples/multiplex/svc1.c @@ -134,11 +134,7 @@ int svc1_register(margo_instance_id mid, ABT_pool pool, uint32_t mplex_id) return(ret); } - /* TODO: for each function: - * - register with margo - * - this will put into hash table in mid that can map to - * , checking for duplicate first - * + /* TODO: * - elsewhere: * - new variant of DEFINE_MARGO_RPC_HANDLER that: * - looks up registered margo thing diff --git a/src/margo.c b/src/margo.c index d5c4daf88874e9a06a8e9b540bfca542e21dc4a7..6bace3b2a661b27f1fb7f9a93b9a6a3a15d36b3e 100644 --- a/src/margo.c +++ b/src/margo.c @@ -16,9 +16,23 @@ #include "margo.h" #include "margo-timer.h" #include "utlist.h" +#include "uthash.h" #define MERCURY_PROGRESS_TIMEOUT_UB 100 /* 100 milliseconds */ +struct mplex_key +{ + hg_id_t id; + uint32_t mplex_id; +}; + +struct mplex_element +{ + struct mplex_key key; + ABT_pool pool; + UT_hash_handle hh; +}; + struct margo_instance { /* provided by caller */ @@ -43,6 +57,9 @@ struct margo_instance ABT_cond finalize_cond; int table_index; + + /* hash table to track multiplexed rpcs registered with margo */ + struct mplex_element *mplex_table; }; struct margo_handler_mapping @@ -787,5 +804,24 @@ static int margo_xstream_is_in_progress_pool(margo_instance_id mid) int margo_register_mplex(margo_instance_id mid, hg_id_t id, uint32_t mplex_id, ABT_pool pool) { - return(-1); + struct mplex_key key; + struct mplex_element *element; + + memset(&key, 0, sizeof(key)); + key.id = id; + key.mplex_id = mplex_id; + + HASH_FIND(hh, mid->mplex_table, &key, sizeof(key), element); + if(element) + return(0); + + element = malloc(sizeof(*element)); + if(!element) + return(-1); + element->key = key; + element->pool = pool; + + HASH_ADD(hh, mid->mplex_table, key, sizeof(key), element); + + return(0); }