version 1.1.2.1, 2025/09/26 08:58:05
|
version 1.3.2.1, 2025/09/30 11:33:20
|
Line 59 rbuf_init(ringbuf_t *rbuf, int num)
|
Line 59 rbuf_init(ringbuf_t *rbuf, int num)
|
if (!rbuf) |
if (!rbuf) |
return -1; |
return -1; |
|
|
atomic_store_explicit(&rbuf->rb_head, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_head, 0, memory_order_relaxed); |
atomic_store_explicit(&rbuf->rb_tail, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_tail, 0, memory_order_relaxed); |
|
|
rbuf->rb_buffer = e_calloc(num, sizeof(struct iovec)); |
rbuf->rb_buffer = e_calloc(num, sizeof(struct iovec)); |
if (!rbuf->rb_buffer) |
if (!rbuf->rb_buffer) |
Line 90 rbuf_free(ringbuf_t *rbuf)
|
Line 90 rbuf_free(ringbuf_t *rbuf)
|
rbuf->rb_bufnum = 0; |
rbuf->rb_bufnum = 0; |
} |
} |
|
|
atomic_store_explicit(&rbuf->rb_head, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_head, 0, memory_order_relaxed); |
atomic_store_explicit(&rbuf->rb_tail, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_tail, 0, memory_order_relaxed); |
} |
} |
|
|
/* |
/* |
Line 109 rbuf_purge(ringbuf_t *rbuf)
|
Line 109 rbuf_purge(ringbuf_t *rbuf)
|
if (rbuf->rb_buffer) |
if (rbuf->rb_buffer) |
memset(rbuf->rb_buffer, 0, rbuf->rb_bufnum * sizeof(struct iovec)); |
memset(rbuf->rb_buffer, 0, rbuf->rb_bufnum * sizeof(struct iovec)); |
|
|
atomic_store_explicit(&rbuf->rb_head, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_head, 0, memory_order_relaxed); |
atomic_store_explicit(&rbuf->rb_tail, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &rbuf->rb_tail, 0, memory_order_relaxed); |
} |
} |
|
|
/* |
/* |
Line 125 rbuf_isempty(ringbuf_t *rbuf)
|
Line 125 rbuf_isempty(ringbuf_t *rbuf)
|
if (!rbuf) |
if (!rbuf) |
return -1; |
return -1; |
|
|
return (atomic_load_explicit(&rbuf->rb_head, memory_order_acquire) == | return (atomic_load_explicit((atomic_int*) &rbuf->rb_head, memory_order_acquire) == |
atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire)); | atomic_load_explicit((atomic_int*) &rbuf->rb_tail, memory_order_acquire)); |
} |
} |
|
|
/* |
/* |
Line 140 rbuf_isfull(ringbuf_t *rbuf)
|
Line 140 rbuf_isfull(ringbuf_t *rbuf)
|
{ |
{ |
if (!rbuf) |
if (!rbuf) |
return -1; |
return -1; |
|
if (!rbuf->rb_bufnum) |
|
return 1; |
|
|
return (((atomic_load_explicit(&rbuf->rb_head, memory_order_relaxed) + 1) % rbuf->rb_bufnum) == | return (((atomic_load_explicit((atomic_int*) &rbuf->rb_head, memory_order_relaxed) + 1) % rbuf->rb_bufnum) == |
atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire)); | atomic_load_explicit((atomic_int*) &rbuf->rb_tail, memory_order_acquire)); |
} |
} |
|
|
/* |
/* |
Line 159 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
Line 161 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
int h, t, n; |
int h, t, n; |
struct iovec *iov; |
struct iovec *iov; |
|
|
if (!rbuf) | if (!rbuf || !rbuf->rb_buffer) |
return -1; |
return -1; |
|
if (!rbuf->rb_bufnum) |
|
return 1; |
|
|
h = atomic_load_explicit(&rbuf->rb_head, memory_order_relaxed); | h = atomic_load_explicit((atomic_int*) &rbuf->rb_head, memory_order_relaxed); |
t = atomic_load_explicit(&rbuf->rb_tail, memory_order_acquire); | t = atomic_load_explicit((atomic_int*) &rbuf->rb_tail, memory_order_acquire); |
n = (h + 1) % rbuf->rb_bufnum; |
n = (h + 1) % rbuf->rb_bufnum; |
|
|
if (n == t) |
if (n == t) |
Line 173 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
Line 177 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
iov->iov_len = len; |
iov->iov_len = len; |
iov->iov_base = data; |
iov->iov_base = data; |
|
|
atomic_store_explicit(&rbuf->rb_head, n, memory_order_release); | atomic_store_explicit((atomic_int*) &rbuf->rb_head, n, memory_order_release); |
return 0; |
return 0; |
} |
} |
|
|
Line 185 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
Line 189 rbuf_enqueue(ringbuf_t *rbuf, void *data, size_t len)
|
* return: -1 error, 1 buffer is empty or 0 ok |
* return: -1 error, 1 buffer is empty or 0 ok |
*/ |
*/ |
int |
int |
rbuf_dequeue(ringbuf_t *rbuf, struct iovec *out) | rbuf_dequeue(ringbuf_t *rbuf, struct iovec **out) |
{ |
{ |
int h, t, n; |
int h, t, n; |
|
|
if (!rbuf) | if (!rbuf || !rbuf->rb_buffer) |
return -1; |
return -1; |
|
if (!rbuf->rb_bufnum) |
|
return 1; |
|
|
h = atomic_load_explicit(&rbuf->rb_head, memory_order_acquire); | h = atomic_load_explicit((atomic_int*) &rbuf->rb_head, memory_order_acquire); |
t = atomic_load_explicit(&rbuf->rb_tail, memory_order_relaxed); | t = atomic_load_explicit((atomic_int*) &rbuf->rb_tail, memory_order_relaxed); |
n = (t + 1) % rbuf->rb_bufnum; |
n = (t + 1) % rbuf->rb_bufnum; |
|
|
if (h == t) |
if (h == t) |
return 1; |
return 1; |
|
|
if (out) |
if (out) |
out = rbuf->rb_buffer + t; | *out = rbuf->rb_buffer + t; |
|
|
atomic_store_explicit(&rbuf->rb_tail, n, memory_order_release); | atomic_store_explicit((atomic_int*) &rbuf->rb_tail, n, memory_order_release); |
return 0; |
return 0; |
} |
} |