X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=buffer_tree.c;h=907bd812617900edfa9fb0882b7c3512d79b85e7;hp=2a78959c5ad569bc6c950be20f6b0def1d801772;hb=6a7f2b1e141f17bdc66c4eb9f43e1f115679943f;hpb=49fe9fc6200ec91f7feb811d7aacda44216828ec diff --git a/buffer_tree.c b/buffer_tree.c index 2a78959c..907bd812 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -756,12 +756,15 @@ void btr_splice_out_node(struct btr_node *btrn) assert(list_empty(&btrn->children)); } -/* - * Return the size of the largest input queue. +/** + * Return number of queued output bytes of a buffer tree node. + * + * \param btrn The node whose output queue size should be computed. * - * Iterates over all children of the given node. + * This function iterates over all children of the given node and returns the + * size of the largest input queue. */ -static size_t btr_bytes_pending(struct btr_node *btrn) +size_t btr_get_output_queue_size(struct btr_node *btrn) { size_t max_size = 0; struct btr_node *ch; @@ -851,7 +854,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) struct btr_buffer_reference *br, *wbr = NULL; int num_refs; /* including wrap buffer */ char *buf, *buf1 = NULL, *buf2 = NULL; - size_t sz, sz1 = 0, sz2 = 0, wsz; + size_t sz, sz1 = 0, sz2 = 0, wb_consumed = 0; br = get_first_input_br(btrn); if (!br || br_available_bytes(br) >= dest_size) @@ -868,6 +871,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) wbr = br; if (sz >= dest_size) return; + wb_consumed = br->consumed; continue; } if (!buf1) { @@ -887,7 +891,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) assert(buf2 + sz2 == buf); sz2 += sz; next: - if (sz1 + sz2 >= dest_size) + if (sz1 + sz2 >= dest_size + wb_consumed) break; } if (!buf2) /* nothing to do */ @@ -919,7 +923,6 @@ next: * We already have a wrap buffer, but it is too small. It might be * partially used. */ - wsz = br_available_bytes(wbr); if (wbr->wrap_count == sz1 && wbr->btrb->size >= sz1 + sz2) /* nothing we can do about it */ return; sz = sz1 + sz2 - wbr->btrb->size; /* amount of new data */ @@ -1103,7 +1106,7 @@ int btr_node_status(struct btr_node *btrn, size_t min_iqs, if (type != BTR_NT_LEAF) { if (btr_no_children(btrn)) return -E_BTR_NO_CHILD; - if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING) + if (btr_get_output_queue_size(btrn) > BTRN_MAX_PENDING) return 0; } if (type != BTR_NT_ROOT) {