comparison libfdcore/routing_dispatch.c @ 1328:81af4f5a517a

Improve shutdown. Should generate less messages that can not get sent out.
author Thomas Klausner <tk@giga.or.at>
date Mon, 27 Nov 2017 15:22:42 +0100
parents 50fb308e84f7
children 239ba25870d8
comparison
equal deleted inserted replaced
1327:82b386714795 1328:81af4f5a517a
1072 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), ); 1072 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), );
1073 1073
1074 do { 1074 do {
1075 struct msg * msg; 1075 struct msg * msg;
1076 1076
1077 /* Test the current order */
1078 {
1079 int must_stop;
1080 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */
1081 must_stop = (order_val == STOP);
1082 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } );
1083 if (must_stop)
1084 goto end;
1085
1086 pthread_testcancel();
1087 }
1088
1089 /* Ok, we are allowed to run */
1090
1091 /* Get the next message from the queue */ 1077 /* Get the next message from the queue */
1092 { 1078 {
1093 int ret; 1079 int ret;
1094 struct timespec ts; 1080 struct timespec ts;
1095 1081
1096 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), goto fatal_error ); 1082 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), goto fatal_error );
1097 ts.tv_sec += 1; 1083 ts.tv_sec += 1;
1098 1084
1099 ret = fd_fifo_timedget ( queue, &msg, &ts ); 1085 ret = fd_fifo_timedget ( queue, &msg, &ts );
1100 if (ret == ETIMEDOUT) 1086 if (ret == ETIMEDOUT) {
1101 /* loop, check if the thread must stop now */ 1087 /* Test the current order */
1088 {
1089 int must_stop;
1090 CHECK_POSIX_DO( pthread_mutex_lock(&order_state_lock), { ASSERT(0); } ); /* we lock to flush the caches */
1091 must_stop = (order_val == STOP);
1092 CHECK_POSIX_DO( pthread_mutex_unlock(&order_state_lock), { ASSERT(0); } );
1093 if (must_stop)
1094 goto end;
1095
1096 pthread_testcancel();
1097 }
1098 /* Ok, we are allowed to continue */
1102 continue; 1099 continue;
1100 }
1103 if (ret == EPIPE) 1101 if (ret == EPIPE)
1104 /* The queue was destroyed, we are probably exiting */ 1102 /* The queue was destroyed, we are probably exiting */
1105 goto end; 1103 goto end;
1106 1104
1107 /* check if another error occurred */ 1105 /* check if another error occurred */
"Welcome to our mercurial repository"