INNER CODE UNIT · C

off

Cateners/tiny_container · app/src/main/cpp/tiny_audio_jni.c:91

    uint32_t off = w % RING_SIZE, c0 = RING_SIZE - off;
    if (c0 > n) c0 = n;
    memcpy(r->buf + off, src, c0);
    if (n > c0) memcpy(r->buf, src + c0, n - c0);
    atomic_store_explicit(&r->write_idx, w + n, memory_order_release);
    return n;
}

static uint32_t ring_read(ring_t *r, uint8_t *dst, uint32_t n)
{
    uint32_t rd = atomic_load_explicit(&r->read_idx,  memory_order_relaxed);
    uint32_t w  = atomic_load_explicit(&r->write_idx, memory_order_acquire);
    uint32_t avail = w - rd;
    if (n > avail) n = avail;
    if (!n) return 0;
    uint32_t off = rd % RING_SIZE, c0 = RING_SIZE - off;
    if (c0 > n) c0 = n;
    memcpy(dst, r->buf + off, c0);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…