From 3c2ca1526e272cbf8c8ae543a8789aa41b69cc4a Mon Sep 17 00:00:00 2001 From: Phil Carns Date: Thu, 31 Mar 2016 10:07:07 -0400 Subject: [PATCH] logic to find operations to cancel --- src/margo.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/margo.c b/src/margo.c index 0f35b69..d91f7dd 100644 --- a/src/margo.c +++ b/src/margo.c @@ -199,6 +199,8 @@ static void hg_progress_fn(void* foo) unsigned int actual_count; struct margo_instance *mid = (struct margo_instance *)foo; size_t size; + struct timespec now; + struct timed_element *cur; while(!mid->hg_progress_shutdown_flag) { @@ -225,6 +227,23 @@ static void hg_progress_fn(void* foo) } } + clock_gettime(clk_id, &now); + + ABT_mutex_lock(mid->timer_mutex); + while(mid->timer_head && + (mid->timer_head->expiration.tv_sec < now.tv_sec || + (mid->timer_head->expiration.tv_sec == now.tv_sec && + mid->timer_head->expiration.tv_nsec < now.tv_nsec))) + { + cur = mid->timer_head; + DL_DELETE(mid->timer_head, cur); + cur->next = NULL; + cur->prev = NULL; + /* TODO: actually cancel here, of course */ + printf("FOO: I would like to cancel operation with tv_sec %ld, tv_nsec %ld\n", (long)cur->expiration.tv_sec, cur->expiration.tv_nsec); + } + ABT_mutex_unlock(mid->timer_mutex); + /* TODO: check for timeouts here. If timer_head not null, then check * current time and compare against first element. Keep walking list * cancelling operations until we find non-expired element. @@ -326,9 +345,10 @@ hg_return_t margo_forward_timed( hret = *waited_hret; } - /* remove timer */ + /* remove timer if it is still in place */ ABT_mutex_lock(mid->timer_mutex); - DL_DELETE(mid->timer_head, &el); + if(el.prev || el.next) + DL_DELETE(mid->timer_head, &el); ABT_mutex_unlock(mid->timer_mutex); ABT_eventual_free(&eventual); -- 2.26.2