From 364501a2cde9bfe446fb763c054692bcbcf18beb Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 13 Dec 2013 22:26:09 +0900 Subject: [PATCH] Get rid of magic value NGHTTP2_PRI_DECAY For now we just double the priority value on each DATA frame transmission. If priority is 0, it becomes to 1 and goes all the way to (1 << 30) - 1. --- lib/nghttp2_session.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index ef9ef039..63a734fa 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1389,24 +1389,27 @@ nghttp2_outbound_item* nghttp2_session_pop_next_ob_item } } -#define NGHTTP2_PRI_DECAY (1 << 26) /* - * Adjust priority of the |item|. In order to prevent the low priority - * streams from starving, lower the priority of the |item| by a - * constant value. If the resulting priority exceeds - * NGHTTP2_PRI_DEFAULT, back to the original priority. + * Adjust priority of the DATA frame |item|. In order to prevent the + * low priority streams from starving, lower the priority of the + * |item|. If the resulting priority exceeds NGHTTP2_PRI_DEFAULT, + * back to the original priority. */ -static void adjust_pri(nghttp2_outbound_item *item) +static void adjust_data_pri(nghttp2_outbound_item *item) { if(item->pri == NGHTTP2_PRI_LOWEST) { item->pri = item->inipri; return; } - if(item->pri > (int32_t)(NGHTTP2_PRI_LOWEST - NGHTTP2_PRI_DECAY)) { + if(item->pri & 0x40000000) { item->pri = NGHTTP2_PRI_LOWEST; return; } - item->pri += NGHTTP2_PRI_DECAY; + if(item->pri == 0) { + item->pri = 1; + } else { + item->pri <<= 1; + } } /* @@ -1587,7 +1590,7 @@ static int nghttp2_session_after_frame_sent(nghttp2_session *session) } else { nghttp2_outbound_item* next_item; next_item = nghttp2_session_get_next_ob_item(session); - adjust_pri(session->aob.item); + adjust_data_pri(session->aob.item); /* If priority of this stream is higher or equal to other stream waiting at the top of the queue, we continue to send this data. */