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.
This commit is contained in:
Tatsuhiro Tsujikawa 2013-12-13 22:26:09 +09:00
parent f4ae707bf2
commit 364501a2cd
1 changed files with 12 additions and 9 deletions

View File

@ -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 * Adjust priority of the DATA frame |item|. In order to prevent the
* streams from starving, lower the priority of the |item| by a * low priority streams from starving, lower the priority of the
* constant value. If the resulting priority exceeds * |item|. If the resulting priority exceeds NGHTTP2_PRI_DEFAULT,
* NGHTTP2_PRI_DEFAULT, back to the original priority. * 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) { if(item->pri == NGHTTP2_PRI_LOWEST) {
item->pri = item->inipri; item->pri = item->inipri;
return; return;
} }
if(item->pri > (int32_t)(NGHTTP2_PRI_LOWEST - NGHTTP2_PRI_DECAY)) { if(item->pri & 0x40000000) {
item->pri = NGHTTP2_PRI_LOWEST; item->pri = NGHTTP2_PRI_LOWEST;
return; 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 { } else {
nghttp2_outbound_item* next_item; nghttp2_outbound_item* next_item;
next_item = nghttp2_session_get_next_ob_item(session); 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 /* If priority of this stream is higher or equal to other stream
waiting at the top of the queue, we continue to send this waiting at the top of the queue, we continue to send this
data. */ data. */