Skip to content

Commit

Permalink
CLEANUP: ring: rename the ring lock "RING_LOCK" instead of "LOGSRV_LOCK"
Browse files Browse the repository at this point in the history
The ring lock was initially mostly used for the logs and used to inherit
its name in lock stats. Now that it's exclusively used by rings, let's
rename it accordingly.
  • Loading branch information
wtarreau committed Sep 20, 2023
1 parent cec8b42 commit cbbee15
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions dev/haring/haring.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int dump_ring(struct ring *ring, size_t ofs, int flags)
}

while (1) {
//HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
//HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock);

if (ofs >= buf.size) {
fprintf(stderr, "FATAL error at %d\n", __LINE__);
Expand Down Expand Up @@ -199,7 +199,7 @@ int dump_ring(struct ring *ring, size_t ofs, int flags)
}

//HA_ATOMIC_INC(b_peek(&buf, ofs));
//HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
//HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock);

if (!(flags & RING_WF_WAIT_MODE))
break;
Expand Down
8 changes: 4 additions & 4 deletions include/haproxy/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ static inline ssize_t sink_write(struct sink *sink, size_t maxlen,
* so that the dropped event arrives exactly at the right
* position.
*/
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &sink->ctx.lock);
sent = sink_announce_dropped(sink, facility);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &sink->ctx.lock);

if (!sent) {
/* we failed, we don't try to send our log as if it
Expand All @@ -70,9 +70,9 @@ static inline ssize_t sink_write(struct sink *sink, size_t maxlen,
}
}

HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &sink->ctx.lock);
HA_RWLOCK_RDLOCK(RING_LOCK, &sink->ctx.lock);
sent = __sink_write(sink, maxlen, msg, nmsg, level, facility, metadata);
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &sink->ctx.lock);
HA_RWLOCK_RDUNLOCK(RING_LOCK, &sink->ctx.lock);

fail:
if (unlikely(sent <= 0))
Expand Down
2 changes: 1 addition & 1 deletion include/haproxy/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ enum lock_label {
PIPES_LOCK,
TLSKEYS_REF_LOCK,
AUTH_LOCK,
LOGSRV_LOCK,
RING_LOCK,
DICT_LOCK,
PROTO_LOCK,
QUEUE_LOCK,
Expand Down
24 changes: 12 additions & 12 deletions src/ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct ring *ring_resize(struct ring *ring, size_t size)
if (!area)
return NULL;

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);

/* recheck the buffer's size, it may have changed during the malloc */
if (b_size(&ring->buf) < size) {
Expand All @@ -143,7 +143,7 @@ struct ring *ring_resize(struct ring *ring, size_t size)
ring->buf.size = size;
}

HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);

free(area);
return ring;
Expand Down Expand Up @@ -200,7 +200,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz

lenlen = varint_bytes(totlen);

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
if (lenlen + totlen + 1 + 1 > b_size(buf))
goto done_buf;

Expand Down Expand Up @@ -254,7 +254,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz
appctx_wakeup(appctx);

done_buf:
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
return sent;
}

Expand Down Expand Up @@ -285,7 +285,7 @@ void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs)
if (!ring)
return;

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
if (ofs != ~0) {
/* reader was still attached */
if (ofs < b_head_ofs(&ring->buf))
Expand All @@ -298,7 +298,7 @@ void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs)
HA_ATOMIC_DEC(b_peek(&ring->buf, ofs));
}
HA_ATOMIC_DEC(&ring->readers_count);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
}

/* Tries to attach CLI handler <appctx> as a new reader on ring <ring>. This is
Expand Down Expand Up @@ -353,11 +353,11 @@ int cli_io_handler_show_ring(struct appctx *appctx)
if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE))
return 1;

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_DEL_INIT(&appctx->wait_entry);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);

HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock);

/* explanation for the initialization below: it would be better to do
* this in the parsing function but this would occasionally result in
Expand Down Expand Up @@ -417,18 +417,18 @@ int cli_io_handler_show_ring(struct appctx *appctx)
HA_ATOMIC_INC(b_peek(buf, ofs));
last_ofs = b_tail_ofs(buf);
ctx->ofs = b_peek_ofs(buf, ofs);
HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock);

if (ret && (ctx->flags & RING_WF_WAIT_MODE)) {
/* we've drained everything and are configured to wait for more
* data or an event (keypress, close)
*/
if (!sc_oc(sc)->output && !(sc->flags & SC_FL_SHUT_DONE)) {
/* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
ofs = b_tail_ofs(&ring->buf);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
if (ofs != last_ofs) {
/* more data was added into the ring between the
* unlock and the lock, and the writer might not
Expand Down
28 changes: 14 additions & 14 deletions src/sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ static void sink_forward_io_handler(struct appctx *appctx)
goto close;
}

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_DEL_INIT(&appctx->wait_entry);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);

HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock);

/* explanation for the initialization below: it would be better to do
* this in the parsing function but this would occasionally result in
Expand Down Expand Up @@ -409,14 +409,14 @@ static void sink_forward_io_handler(struct appctx *appctx)
last_ofs = b_tail_ofs(buf);
sft->ofs = b_peek_ofs(buf, ofs);

HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock);

if (ret) {
/* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
ofs = b_tail_ofs(buf);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
if (ofs != last_ofs) {
/* more data was added into the ring between the
* unlock and the lock, and the writer might not
Expand Down Expand Up @@ -478,11 +478,11 @@ static void sink_forward_oc_io_handler(struct appctx *appctx)
goto close;
}

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_DEL_INIT(&appctx->wait_entry);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);

HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock);

/* explanation for the initialization below: it would be better to do
* this in the parsing function but this would occasionally result in
Expand Down Expand Up @@ -544,13 +544,13 @@ static void sink_forward_oc_io_handler(struct appctx *appctx)
HA_ATOMIC_INC(b_peek(buf, ofs));
sft->ofs = b_peek_ofs(buf, ofs);

HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock);

if (ret) {
/* let's be woken up once new data arrive */
HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
LIST_APPEND(&ring->waiters, &appctx->wait_entry);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
applet_have_no_more_data(appctx);
}
HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock);
Expand All @@ -574,9 +574,9 @@ void __sink_forward_session_deinit(struct sink_forward_target *sft)
if (!sink)
return;

HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
HA_RWLOCK_WRLOCK(RING_LOCK, &sink->ctx.ring->lock);
LIST_DEL_INIT(&sft->appctx->wait_entry);
HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock);
HA_RWLOCK_WRUNLOCK(RING_LOCK, &sink->ctx.ring->lock);

sft->appctx = NULL;
task_wakeup(sink->forward_task, TASK_WOKEN_MSG);
Expand Down
2 changes: 1 addition & 1 deletion src/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static const char *lock_label(enum lock_label label)
case PIPES_LOCK: return "PIPES";
case TLSKEYS_REF_LOCK: return "TLSKEYS_REF";
case AUTH_LOCK: return "AUTH";
case LOGSRV_LOCK: return "LOGSRV";
case RING_LOCK: return "RING";
case DICT_LOCK: return "DICT";
case PROTO_LOCK: return "PROTO";
case QUEUE_LOCK: return "QUEUE";
Expand Down

0 comments on commit cbbee15

Please sign in to comment.