# HG changeset patch # User Sebastien Decugis # Date 1370845635 -28800 # Node ID f40de74bd1c7dcae558008ed5837916858100105 # Parent 436e4342ecd0ab6dde9cb74e96f689f0ef497f2c Don't block PSM during failover diff -r 436e4342ecd0 -r f40de74bd1c7 include/freeDiameter/libfdproto.h --- a/include/freeDiameter/libfdproto.h Mon Jun 10 12:04:50 2013 +0800 +++ b/include/freeDiameter/libfdproto.h Mon Jun 10 14:27:15 2013 +0800 @@ -3121,6 +3121,10 @@ #define fd_fifo_post(queue, item) \ fd_fifo_post_int((queue), (void *)(item)) +/* Similar function but does not block. It can cause the number of items in the queue to exceed the maximum set. Do not use for normal operation, +only for failure recovery for example. */ +int fd_fifo_post_noblock( struct fifo * queue, void ** item ); + /* * FUNCTION: fd_fifo_get * diff -r 436e4342ecd0 -r f40de74bd1c7 libfdcore/p_sr.c --- a/libfdcore/p_sr.c Mon Jun 10 12:04:50 2013 +0800 +++ b/libfdcore/p_sr.c Mon Jun 10 14:27:15 2013 +0800 @@ -326,7 +326,7 @@ fd_hook_call(HOOK_MESSAGE_FAILOVER, sr->req, (struct fd_peer *)srlist->srs.o, NULL, fd_msg_pmdl_get(sr->req)); /* Requeue for sending to another peer */ - CHECK_FCT_DO( ret = fd_fifo_post(fd_g_outgoing, &sr->req), + CHECK_FCT_DO( ret = fd_fifo_post_noblock(fd_g_outgoing, (void *)&sr->req), { char buf[256]; snprintf(buf, sizeof(buf), "Internal error: error while requeuing during failover: %s", strerror(ret)); diff -r 436e4342ecd0 -r f40de74bd1c7 libfdcore/peers.c --- a/libfdcore/peers.c Mon Jun 10 12:04:50 2013 +0800 +++ b/libfdcore/peers.c Mon Jun 10 14:27:15 2013 +0800 @@ -242,7 +242,7 @@ /* Requeue all messages in the "out" queue */ while ( fd_fifo_tryget(peer->p_tosend, &m) == 0 ) { fd_hook_call(HOOK_MESSAGE_FAILOVER, m, peer, NULL, fd_msg_pmdl_get(m)); - CHECK_FCT_DO(fd_fifo_post(fd_g_outgoing, &m), + CHECK_FCT_DO(fd_fifo_post_noblock(fd_g_outgoing, (void *)&m), { /* fallback: destroy the message */ fd_hook_call(HOOK_MESSAGE_DROPPED, m, NULL, "Internal error: unable to requeue this message during failover process", fd_msg_pmdl_get(m)); diff -r 436e4342ecd0 -r f40de74bd1c7 libfdproto/fifo.c --- a/libfdproto/fifo.c Mon Jun 10 12:04:50 2013 +0800 +++ b/libfdproto/fifo.c Mon Jun 10 14:27:15 2013 +0800 @@ -376,24 +376,19 @@ /* Post a new item in the queue */ -int fd_fifo_post_int ( struct fifo * queue, void ** item ) +int fd_fifo_post_internal ( struct fifo * queue, void ** item, int skip_max ) { struct fifo_item * new; int call_cb = 0; struct timespec posted_on, queued_on; - TRACE_ENTRY( "%p %p", queue, item ); - - /* Check the parameters */ - CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); - /* Get the timing of this call */ CHECK_SYS( clock_gettime(CLOCK_REALTIME, &posted_on) ); /* lock the queue */ CHECK_POSIX( pthread_mutex_lock( &queue->mtx ) ); - if (queue->max) { + if ((!skip_max) && (queue->max)) { while (queue->count >= queue->max) { int ret = 0; @@ -461,6 +456,30 @@ return 0; } +/* Post a new item in the queue */ +int fd_fifo_post_int ( struct fifo * queue, void ** item ) +{ + TRACE_ENTRY( "%p %p", queue, item ); + + /* Check the parameters */ + CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); + + return fd_fifo_post_internal ( queue,item, 0 ); + +} + +/* Post a new item in the queue, not blocking */ +int fd_fifo_post_noblock ( struct fifo * queue, void ** item ) +{ + TRACE_ENTRY( "%p %p", queue, item ); + + /* Check the parameters */ + CHECK_PARAMS( CHECK_FIFO( queue ) && item && *item ); + + return fd_fifo_post_internal ( queue,item, 1 ); + +} + /* Pop the first item from the queue */ static void * mq_pop(struct fifo * queue) {