~pbatch/patchwerk

2200eea491278f2e69c071f922109bca232609fe — paul 8 months ago 2f4e1f2
added global code to pw_patch. attempt to stop the world when the buffer pool fills up after node_set_block.

FossilOrigin-Name: e22e9987c9ef27912444fb593cb928b3cb35722c74281fa260f85ae41e58ad4c
2 files changed, 43 insertions(+), 3 deletions(-)

M node.w
M patch.w
M node.w => node.w +15 -2
@@ 273,20 273,33 @@ int pw_node_blksize(pw_node *node)
@ The function |pw_node_set_block| sets a cable internal to the node to be
an audio signal using the node's internal block size.
It returns |PW_OK| on sucess, and |PW_INVALID_CABLE| on failure.

@<Header@>+=
int pw_node_set_block(pw_node *node, int id);

@ @<Node Top@>+=
@ This error code rarely gets checked in practice. Many have
considered this a bad idea. A global error flag is set
in place to attempt patchwerk from moving further down
the line.

@<Node Top@>+=
int pw_node_set_block(pw_node *node, int id)
{
    int rc;
    if(id > node->ncables) {
        return PW_INVALID_CABLE; /* fail on out-of-range cable ID */
    }

    return pw_cable_make_block(
    rc = pw_cable_make_block(
        &node->cables[id],
        pw_patch_stack(node->patch),
        node->blksize);

    if (rc != PW_OK) {
        pw_patch_err(node->patch, PW_POOL_FULL);
    }

    return rc;
}

@ The function |pw_node_get_ncables| returns the number of cables in a node.

M patch.w => patch.w +28 -1
@@ 78,6 78,14 @@ by nodes. In the Runt interface, this is the Soundpipe data struct.
@<Variables in Patch Data@>+=
void *ud;

@ A global error code |err| can be used to notify patchwerk
that something has gone wrong, even if the user hasn't
explicitly checked for it. For example, |pw_node_set_block|
returns an error code that is rarely (if ever) checked.

@<Variables in Patch Data@>+=
int err;

@* Functions.

@ The function |pw_patch_init| initializes and zeros out variables inside of


@@ 163,6 171,8 @@ void pw_patch_reinit(pw_patch *patch)

    pw_stack_reset(&patch->stack);
    pw_bufferpool_reset(&patch->pool);

    patch->err = PW_OK;
}

@ The function |pw_patch_clear| will partially reset a |pw_patch|. Clearing


@@ 334,6 344,8 @@ int pw_patch_new_node(pw_patch *patch, pw_node **node)

    if(patch == NULL) return PW_NULL_VALUE;

    if(patch->err != PW_OK) return patch->err;

    rc = pw_memory_alloc(patch, sizeof(pw_node), (void **)&tmp);

    if(rc != PW_OK) return rc;


@@ 576,4 588,19 @@ int pw_patch_bunhold(pw_patch *patch, pw_buffer *b)
    if(rc != PW_OK) return rc;

    return PW_OK;
}
\ No newline at end of file
}

@ The function |pw_patch_err| sets the global error code.
By setting this error code, this will force patchwerk to
shutdown next time a new node is created.

@<Header@>+=
void pw_patch_err(pw_patch *patch, int rc);

@

@<Patch Top@>+=
void pw_patch_err(pw_patch *patch, int rc)
{
    patch->err = rc;
}