X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=buffer_tree.c;h=bdcbec8de73c0348ea0a0e223e38b3584bee488a;hp=9be53201f76c9400a320688cde6540c4ca227d05;hb=fd09012ca62c214fb3e2f48935e658b885c967b6;hpb=635ffa801ce0d4f5055ad022a5de935acd83b056 diff --git a/buffer_tree.c b/buffer_tree.c index 9be53201..bdcbec8d 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -1,3 +1,10 @@ +/* + * Copyright (C) 2009-2010 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file buffer_tree.c Buffer tree and buffer pool implementations. */ #include #include @@ -627,7 +634,7 @@ void btr_consume(struct btr_node *btrn, size_t numbytes) numbytes -= br->btrb->size - br->consumed; btr_drop_buffer_reference(br); } - assert(true); + assert(false); } /* * We have a wrap buffer, consume from it. If in total, i.e. including @@ -653,9 +660,10 @@ void btr_consume(struct btr_node *btrn, size_t numbytes) return btr_consume(btrn, sz); } -static void flush_input_queue(struct btr_node *btrn) +void btr_drain(struct btr_node *btrn) { struct btr_buffer_reference *br, *tmp; + FOR_EACH_BUFFER_REF_SAFE(br, tmp, btrn) btr_drop_buffer_reference(br); } @@ -663,6 +671,8 @@ static void flush_input_queue(struct btr_node *btrn) /** * Free all resources allocated by btr_new_node(). * + * \param btrn Pointer to a btr node obtained by \ref btr_new_node(). + * * Like free(3), it is OK to call this with a \p NULL pointer argument. */ void btr_free_node(struct btr_node *btrn) @@ -693,7 +703,7 @@ void btr_remove_node(struct btr_node *btrn) PARA_NOTICE_LOG("removing btr node %s from buffer tree\n", btrn->name); FOR_EACH_CHILD(ch, btrn) ch->parent = NULL; - flush_input_queue(btrn); + btr_drain(btrn); if (btrn->parent) list_del(&btrn->node); } @@ -776,15 +786,6 @@ size_t btr_get_output_queue_size(struct btr_node *btrn) return max_size; } -int btr_exec(struct btr_node *btrn, const char *command, char **value_result) -{ - if (!btrn) - return -ERRNO_TO_PARA_ERROR(EINVAL); - if (!btrn->execute) - return -ERRNO_TO_PARA_ERROR(ENOTSUP); - return btrn->execute(btrn, command, value_result); -} - /** * Execute a inter-node command on a parent node. * @@ -854,7 +855,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; + size_t sz, sz1 = 0, sz2 = 0, wb_consumed = 0; br = get_first_input_br(btrn); if (!br || br_available_bytes(br) >= dest_size) @@ -871,6 +872,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) { @@ -890,7 +892,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 */ @@ -1068,7 +1070,7 @@ struct btr_node *btr_search_node(const char *name, struct btr_node *root) } /** 640K ought to be enough for everybody ;) */ -#define BTRN_MAX_PENDING (640 * 1024) +#define BTRN_MAX_PENDING (96 * 1024) /** * Return the current state of a buffer tree node.