# HG changeset patch # User Thomas Klausner # Date 1511792562 -3600 # Node ID 81af4f5a517ad3b35c1bfe6a2371cdde432d9b2e # Parent 82b386714795608a34cb77fcb949abf5e7ca4485 Improve shutdown. Should generate less messages that can not get sent out. diff -r 82b386714795 -r 81af4f5a517a libfdcore/routing_dispatch.c --- a/libfdcore/routing_dispatch.c Mon Nov 27 15:21:20 2017 +0100 +++ b/libfdcore/routing_dispatch.c Mon Nov 27 15:22:42 2017 +0100 @@ -1074,20 +1074,6 @@ do { struct msg * msg; - /* Test the current order */ - { - int must_stop; - CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */ - must_stop = (order_val == STOP); - CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } ); - if (must_stop) - goto end; - - pthread_testcancel(); - } - - /* Ok, we are allowed to run */ - /* Get the next message from the queue */ { int ret; @@ -1097,9 +1083,21 @@ ts.tv_sec += 1; ret = fd_fifo_timedget ( queue, &msg, &ts ); - if (ret == ETIMEDOUT) - /* loop, check if the thread must stop now */ + if (ret == ETIMEDOUT) { + /* Test the current order */ + { + int must_stop; + CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */ + must_stop = (order_val == STOP); + CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } ); + if (must_stop) + goto end; + + pthread_testcancel(); + } + /* Ok, we are allowed to continue */ continue; + } if (ret == EPIPE) /* The queue was destroyed, we are probably exiting */ goto end;