|
|
| version 1.4.4.1, 2026/02/10 15:49:08 | version 1.5.2.1, 2026/02/10 18:23:53 |
|---|---|
| Line 284 lrb_purge(lrbuf_t *lrb) | Line 284 lrb_purge(lrbuf_t *lrb) |
| atomic_store_explicit((atomic_int*) &lrb->lrb_head, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &lrb->lrb_head, 0, memory_order_relaxed); |
| atomic_store_explicit((atomic_int*) &lrb->lrb_tail, 0, memory_order_relaxed); | atomic_store_explicit((atomic_int*) &lrb->lrb_tail, 0, memory_order_relaxed); |
| atomic_store_explicit((atomic_int*) &lrb->lrb_full, 0, memory_order_relaxed); | |
| } | } |
| /* | /* |
| Line 298 lrb_isempty(lrbuf_t *lrb) | Line 299 lrb_isempty(lrbuf_t *lrb) |
| if (!lrb) | if (!lrb) |
| return -1; | return -1; |
| return (atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire) == | return (!atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire) && |
| atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire)); | (atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire) == |
| atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire))); | |
| } | } |
| /* | /* |
| Line 318 lrb_isfull(lrbuf_t *lrb) | Line 320 lrb_isfull(lrbuf_t *lrb) |
| if (!lrb->lrb_size) | if (!lrb->lrb_size) |
| return 1; | return 1; |
| t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); | if (!atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire)) |
| h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_relaxed) + 1; | return 0; |
| if (h >= lrb->lrb_size) | |
| h ^= h; | |
| t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); | |
| h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire); | |
| return (h == t); | return (h == t); |
| } | } |
| Line 338 lrb_isfull(lrbuf_t *lrb) | Line 340 lrb_isfull(lrbuf_t *lrb) |
| int | int |
| lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int lost) | lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int lost) |
| { | { |
| int h, t, n, t2, unused, drop = 0; | int h, t = 0, n, t2 = 0, unused, drop = 0; |
| if (!lrb || !lrb->lrb_data) | if (!lrb || !lrb->lrb_data) |
| return -1; | return -1; |
| Line 370 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int | Line 372 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int |
| n = len - n; | n = len - n; |
| } | } |
| atomic_store_explicit((atomic_int*) &lrb->lrb_head, n, memory_order_release); | h = n; |
| atomic_store_explicit((atomic_int*) &lrb->lrb_head, h, memory_order_release); | |
| if (drop > 0) | if (drop > 0) |
| while (42) { | while (42) { |
| n = t; | n = t; |
| Line 380 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int | Line 383 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int |
| t = n; | t = n; |
| t2 = (t + drop) % lrb->lrb_size; | t2 = (t + drop) % lrb->lrb_size; |
| } | } |
| else | |
| t2 = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); | |
| atomic_store_explicit((atomic_int*) &lrb->lrb_full, (h == t2), memory_order_release); | |
| return 0; | return 0; |
| } | } |
| Line 394 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int | Line 400 lrb_enqueue(lrbuf_t *lrb, void *data, size_t len, int |
| int | int |
| lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) | lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) |
| { | { |
| int h, t, t2, n, l; | int h, t, t2, n, l, f; |
| if (!lrb) | if (!lrb) |
| return -1; | return -1; |
| Line 406 lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) | Line 412 lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) |
| while (42) { | while (42) { |
| t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); | t = atomic_load_explicit((atomic_int*) &lrb->lrb_tail, memory_order_acquire); |
| h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire); | h = atomic_load_explicit((atomic_int*) &lrb->lrb_head, memory_order_acquire); |
| f = atomic_load_explicit((atomic_int*) &lrb->lrb_full, memory_order_acquire); | |
| l = h - t; | l = h - t; |
| if (l < 0) | if (l < 0) |
| l += lrb->lrb_size; | l += lrb->lrb_size; |
| if (!l) | if (!l) { |
| return 0; | if (!f) |
| return 0; | |
| l = lrb->lrb_size; | |
| } | |
| if (l > len) | if (l > len) |
| l = len; | l = len; |
| Line 430 lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) | Line 440 lrb_dequeue(lrbuf_t *lrb, void *data, size_t len) |
| n = t; | n = t; |
| if (atomic_compare_exchange_weak_explicit((atomic_int*) &lrb->lrb_tail, | if (atomic_compare_exchange_weak_explicit((atomic_int*) &lrb->lrb_tail, |
| &n, t2, memory_order_release, memory_order_relaxed)) | &n, t2, memory_order_release, memory_order_relaxed)) { |
| atomic_store_explicit((atomic_int*) &lrb->lrb_full, 0, memory_order_release); | |
| return l; | return l; |
| } | |
| } | } |
| return 0; | return 0; |