• Philippe Gerum's avatar
    include: add 'tube' data path · 08592109
    Philippe Gerum authored
    A lighweight, lockless multi-reader/multi-writer FIFO with a
    base-offset variant which can work over a memory segment shared
    between processes. Scalar data or simple (small!) aggregates are
    conveyed though a tube inside canisters which exactly fit their type.
    By design, a tube is meant to be a basic, spartan mechanism: it
    imposes no usage policy whatsoever on users.
    
    As a result, a tube is strictly non-blocking, it solely detects and
    notifies the caller on return about empty input (no message in) and
    output contention (no buffer space for output). If required, the
    caller can implement blocking states, typically with a pair of EVL
    semaphores, e.g. setting up a tube conveying integers which supports
    blocking mode:
    
        DECLARE_EVL_TUBE_CANISTER(canister_type, int); /* defines struct canister_type */
        DECLARE_EVL_TUBE(tube_type, cannister_type) tube;
        struct cannister_type items[1024];
    
        evl_init_tube(&tube, items, 1024);
        evl_new_sem(&in, ...);
        evl_new_sem_any(&out, CLOCK_MONOTONIC, tube.max_items, ...);
    
        evl_get_sem(&in, ...);           @      evl_get_sem(&out);
        evl_tube_receive(&tube, ...);    @      evl_tube_send(&tube, ...);
        evl_put_sem(&out);               @      evl_put_sem(&in, ...);
    08592109
tube.h 8.3 KB