ofs = 0;
/* going to the end means looking at tail-1 */
- if (flags & RING_WF_SEEK_NEW)
- ofs += b_data(&buf) - 1;
+ ofs = (flags & RING_WF_SEEK_NEW) ? buf.data - 1 : 0;
//HA_ATOMIC_INC(b_peek(&buf, ofs));
- ofs += ring->ofs;
}
while (1) {
//HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
- /* we were already there, adjust the offset to be relative to
- * the buffer's head and remove us from the counter.
- */
- ofs -= ring->ofs;
if (ofs >= buf.size) {
fprintf(stderr, "FATAL error at %d\n", __LINE__);
return 1;
}
//HA_ATOMIC_INC(b_peek(&buf, ofs));
- ofs += ring->ofs;
//HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
if (!(flags & RING_WF_WAIT_MODE))
if (unlikely(ofs == ~0)) {
ofs = 0;
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
}
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
out:
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
ns->dgram->ofs_req = ofs;
HA_RWLOCK_RDUNLOCK(DNS_LOCK, &ring->lock);
HA_SPIN_UNLOCK(DNS_LOCK, &dgram->lock);
ofs = 0;
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
}
/* in this loop, ofs always points to the counter byte that precedes
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
}
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
ds->ofs = ofs;
}
HA_RWLOCK_RDUNLOCK(DNS_LOCK, &ring->lock);
if (unlikely(ofs == ~0)) {
ofs = 0;
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
}
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
}
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
dss->ofs_req = ofs;
HA_RWLOCK_RDUNLOCK(DNS_LOCK, &ring->lock);
/* context used to dump the contents of a ring via "show events" or "show errors" */
struct show_ring_ctx {
struct ring *ring; /* ring to be dumped */
- size_t ofs; /* offset to restart from, ~0 = end */
+ size_t ofs; /* storage offset to restart from; ~0=oldest */
uint flags; /* set of RING_WF_* */
};
return 1;
}
-/* detach an appctx from a ring. The appctx is expected to be waiting at
- * offset <ofs>. Nothing is done if <ring> is NULL.
+/* detach an appctx from a ring. The appctx is expected to be waiting at offset
+ * <ofs> relative to the beginning of the storage, or ~0 if not waiting yet.
+ * Nothing is done if <ring> is NULL.
*/
void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs)
{
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
if (ofs != ~0) {
/* reader was still attached */
- ofs -= ring->ofs;
+ if (ofs < b_head_ofs(&ring->buf))
+ ofs += b_size(&ring->buf) - b_head_ofs(&ring->buf);
+ else
+ ofs -= b_head_ofs(&ring->buf);
+
BUG_ON(ofs >= b_size(&ring->buf));
LIST_DEL_INIT(&appctx->wait_entry);
HA_ATOMIC_DEC(b_peek(&ring->buf, ofs));
struct stconn *sc = appctx_sc(appctx);
struct ring *ring = ctx->ring;
struct buffer *buf = &ring->buf;
- size_t ofs = ctx->ofs;
+ size_t ofs;
size_t last_ofs;
uint64_t msg_len;
size_t len, cnt;
* existing messages before grabbing a reference to a location. This
* value cannot be produced after initialization.
*/
- if (unlikely(ofs == ~0)) {
- ofs = 0;
-
+ if (unlikely(ctx->ofs == ~0)) {
/* going to the end means looking at tail-1 */
- if (ctx->flags & RING_WF_SEEK_NEW)
- ofs += b_data(buf) - 1;
-
- HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
+ ctx->ofs = b_peek_ofs(buf, (ctx->flags & RING_WF_SEEK_NEW) ? b_data(buf) - 1 : 0);
+ HA_ATOMIC_INC(b_orig(buf) + ctx->ofs);
}
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
+ ofs = ctx->ofs - b_head_ofs(buf);
+ if (ctx->ofs < b_head_ofs(buf))
+ ofs += b_size(buf);
+
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
}
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
- last_ofs = ring->ofs;
- ctx->ofs = ofs;
+ last_ofs = b_tail_ofs(buf);
+ ctx->ofs = b_peek_ofs(buf, ofs);
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
if (ret && (ctx->flags & RING_WF_WAIT_MODE)) {
/* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
- ofs = ring->ofs;
+ ofs = b_tail_ofs(&ring->buf);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
if (ofs != last_ofs) {
/* more data was added into the ring between the
*/
if (unlikely(ofs == ~0)) {
ofs = 0;
-
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
}
/* in this loop, ofs always points to the counter byte that precedes
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
}
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
+ last_ofs = b_tail_ofs(buf);
sft->ofs = ofs;
- last_ofs = ring->ofs;
}
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
/* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
- ofs = ring->ofs;
+ ofs = b_tail_ofs(buf);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
if (ofs != last_ofs) {
/* more data was added into the ring between the
*/
if (unlikely(ofs == ~0)) {
ofs = 0;
-
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
}
/* in this loop, ofs always points to the counter byte that precedes
/* we were already there, adjust the offset to be relative to
* the buffer's head and remove us from the counter.
*/
- ofs -= ring->ofs;
BUG_ON(ofs >= buf->size);
HA_ATOMIC_DEC(b_peek(buf, ofs));
}
HA_ATOMIC_INC(b_peek(buf, ofs));
- ofs += ring->ofs;
sft->ofs = ofs;
}
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);