]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - buffer_tree.c
Introduce btr_node_status() and add btr support to the file writer.
[paraslash.git] / buffer_tree.c
index 5d8e33fc17748dc1347af4f1ec57f15a8b662741..3b00154183d9c19ba0e4895c6fcdec2e03010a96 100644 (file)
@@ -119,6 +119,11 @@ void btr_add_output(char *buf, size_t size, struct btr_node *btrn)
 {
        struct btr_buffer *btrb;
 
+       assert(size != 0);
+       if (list_empty(&btrn->children)) {
+               free(buf);
+               return;
+       }
        btrb = new_btrb(buf, size);
        add_btrb_to_children(btrb, btrn, 0);
 }
@@ -137,6 +142,17 @@ void btr_pushdown(struct btr_node *btrn)
                btr_pushdown_br(br, btrn);
 }
 
+int btr_pushdown_one(struct btr_node *btrn)
+{
+       struct btr_buffer_reference *br;
+
+       if (list_empty(&btrn->input_queue))
+               return 0;
+       br = list_first_entry(&btrn->input_queue, struct btr_buffer_reference, node);
+       btr_pushdown_br(br, btrn);
+       return 1;
+}
+
 /* Return true if this node has no children. */
 bool btr_no_children(struct btr_node *btrn)
 {
@@ -388,3 +404,22 @@ void btr_log_tree(struct btr_node *btrn, int loglevel)
 {
        return log_tree_recursively(btrn, loglevel, 0);
 }
+
+/** 640K ought to be enough for everybody ;) */
+#define BTRN_MAX_PENDING (640 * 1024)
+
+int btr_node_status(struct btr_node *btrn, size_t min_iqs)
+{
+       size_t iqs;
+
+       if (btr_eof(btrn))
+               return -E_BTR_EOF;
+       if (btr_bytes_pending(btrn) > BTRN_MAX_PENDING)
+               return 0;
+       iqs = btr_get_input_queue_size(btrn);
+       if (iqs == 0) /* we have a parent, because not eof */
+               return 0;
+       if (iqs < min_iqs && !btr_no_parent(btrn))
+               return 0;
+       return 1;
+}