From 7bc62935c61184d874ef5ee0e9e0974da472e1dd Mon Sep 17 00:00:00 2001 From: Shane Snyder Date: Mon, 18 Apr 2016 12:40:23 -0500 Subject: [PATCH] reorg margo timers using internal header file --- Makefile.am | 2 +- include/margo.h | 9 +++++-- src/Makefile.subdir | 1 + src/margo-timer.c | 41 -------------------------------- {include => src}/margo-timer.h | 7 ------ src/margo.c | 43 ++++++++++++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 51 deletions(-) rename {include => src}/margo-timer.h (89%) diff --git a/Makefile.am b/Makefile.am index d1d0084..67db084 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,7 @@ CLEANFILES = $(bin_SCRIPTS) MAINTAINERCLEANFILES = EXTRA_DIST = BUILT_SOURCES = -include_HEADERS = include/margo.h include/margo-timer.h +include_HEADERS = include/margo.h EXTRA_DIST += \ prepare.sh diff --git a/include/margo.h b/include/margo.h index 2509612..6c0c4d6 100644 --- a/include/margo.h +++ b/include/margo.h @@ -17,8 +17,6 @@ extern "C" { #include #include -#include "margo-timer.h" - struct margo_instance; typedef struct margo_instance* margo_instance_id; @@ -156,6 +154,13 @@ hg_return_t margo_addr_lookup( const char *name, hg_addr_t *addr); +/** + * Suspends the calling ULT for a specified time duration + * @param [in] timeout_ms timeout duration in milliseconds + */ +void margo_thread_sleep( + double timeout_ms); + /** * Retrive the Margo instance that has been associated with a Mercury class * @param [in] cl Mercury class diff --git a/src/Makefile.subdir b/src/Makefile.subdir index 652f392..00043c8 100644 --- a/src/Makefile.subdir +++ b/src/Makefile.subdir @@ -1,3 +1,4 @@ src_libmargo_a_SOURCES += \ src/margo.c \ + src/margo-timer.h \ src/margo-timer.c diff --git a/src/margo-timer.c b/src/margo-timer.c index 5fcb423..3cf4edc 100644 --- a/src/margo-timer.c +++ b/src/margo-timer.c @@ -49,47 +49,6 @@ void margo_timer_sys_shutdown() return; } -typedef struct -{ - ABT_mutex mutex; - ABT_cond cond; -} margo_thread_sleep_cb_dat; - -static void margo_thread_sleep_cb(void *arg) -{ - margo_thread_sleep_cb_dat *sleep_cb_dat = - (margo_thread_sleep_cb_dat *)arg; - - /* wake up the sleeping thread */ - ABT_mutex_lock(sleep_cb_dat->mutex); - ABT_cond_signal(sleep_cb_dat->cond); - ABT_mutex_unlock(sleep_cb_dat->mutex); - - return; -} - -void margo_thread_sleep( - double timeout_ms) -{ - margo_timer_t sleep_timer; - margo_thread_sleep_cb_dat sleep_cb_dat; - - /* set data needed for sleep callback */ - ABT_mutex_create(&(sleep_cb_dat.mutex)); - ABT_cond_create(&(sleep_cb_dat.cond)); - - /* initialize the sleep timer */ - margo_timer_init(&sleep_timer, margo_thread_sleep_cb, - &sleep_cb_dat, timeout_ms); - - /* yield thread for specified timeout */ - ABT_mutex_lock(sleep_cb_dat.mutex); - ABT_cond_wait(sleep_cb_dat.cond, sleep_cb_dat.mutex); - ABT_mutex_unlock(sleep_cb_dat.mutex); - - return; -} - void margo_timer_init( margo_timer_t *timer, margo_timer_cb_fn cb_fn, diff --git a/include/margo-timer.h b/src/margo-timer.h similarity index 89% rename from include/margo-timer.h rename to src/margo-timer.h index 13841b3..1998262 100644 --- a/include/margo-timer.h +++ b/src/margo-timer.h @@ -34,13 +34,6 @@ void margo_timer_sys_init( void margo_timer_sys_shutdown( void); -/** - * Suspends the calling ULT for a specified time duration - * @param [in] timeout_ms timeout duration in milliseconds - */ -void margo_thread_sleep( - double timeout_ms); - /** * Initializes a margo timer object which will perform some action * after a specified time duration diff --git a/src/margo.c b/src/margo.c index c4cb9f0..c94cd86 100644 --- a/src/margo.c +++ b/src/margo.c @@ -14,6 +14,7 @@ #include #include "margo.h" +#include "margo-timer.h" #include "utlist.h" /* TODO: including core.h for cancel definition, presumably this will be @@ -455,6 +456,48 @@ hg_return_t margo_bulk_transfer( return(hret); } +typedef struct +{ + ABT_mutex mutex; + ABT_cond cond; +} margo_thread_sleep_cb_dat; + +static void margo_thread_sleep_cb(void *arg) +{ + margo_thread_sleep_cb_dat *sleep_cb_dat = + (margo_thread_sleep_cb_dat *)arg; + + /* wake up the sleeping thread */ + ABT_mutex_lock(sleep_cb_dat->mutex); + ABT_cond_signal(sleep_cb_dat->cond); + ABT_mutex_unlock(sleep_cb_dat->mutex); + + return; +} + +void margo_thread_sleep( + double timeout_ms) +{ + margo_timer_t sleep_timer; + margo_thread_sleep_cb_dat sleep_cb_dat; + + /* set data needed for sleep callback */ + ABT_mutex_create(&(sleep_cb_dat.mutex)); + ABT_cond_create(&(sleep_cb_dat.cond)); + + /* initialize the sleep timer */ + margo_timer_init(&sleep_timer, margo_thread_sleep_cb, + &sleep_cb_dat, timeout_ms); + + /* yield thread for specified timeout */ + ABT_mutex_lock(sleep_cb_dat.mutex); + ABT_cond_wait(sleep_cb_dat.cond, sleep_cb_dat.mutex); + ABT_mutex_unlock(sleep_cb_dat.mutex); + + return; +} + + margo_instance_id margo_hg_class_to_instance(hg_class_t *cl) { int i; -- 2.26.2