struct ring {
struct ring_storage *storage; // the mapped part
struct mt_list waiters; // list of waiters, for now, CLI "show event"
- __decl_thread(HA_RWLOCK_T lock);
int readers_count;
uint flags; // RING_FL_*
};
*/
void ring_init(struct ring *ring, void *area, size_t size, int reset)
{
- HA_RWLOCK_INIT(&ring->lock);
MT_LIST_INIT(&ring->waiters);
ring->readers_count = 0;
ring->flags = 0;
struct mt_list *elt1, elt2;
struct appctx *appctx;
- HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock);
mt_list_for_each_entry_safe(appctx, &ring->waiters, wait_entry, elt1, elt2)
appctx_wakeup(appctx);
- HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock);
}
leave:
if (!ring)
return;
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
HA_ATOMIC_DEC(&ring->readers_count);
if (ofs != ~0) {
} while ((readers > RING_MAX_READERS ||
!_HA_ATOMIC_CAS(area + ofs, &readers, readers - 1)) && __ha_cpu_relax());
}
- HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
}
/* Tries to attach CLI handler <appctx> as a new reader on ring <ring>. This is
if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE))
return 1;
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_DELETE(&appctx->wait_entry);
- HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
ret = ring_dispatch_messages(ring, appctx, &ctx->ofs, &last_ofs, ctx->flags, applet_append_line);
*/
if (!sc_oc(sc)->output && !(sc->flags & SC_FL_SHUT_DONE)) {
/* let's be woken up once new data arrive */
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_APPEND(&ring->waiters, &appctx->wait_entry);
ofs = ring_tail(ring);
- 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
goto close;
}
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_DELETE(&appctx->wait_entry);
- HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
ret = ring_dispatch_messages(ring, appctx, &sft->ofs, &last_ofs, 0, applet_append_line);
if (ret) {
/* let's be woken up once new data arrive */
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_APPEND(&ring->waiters, &appctx->wait_entry);
ofs = ring_tail(ring);
- 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
goto close;
}
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_DELETE(&appctx->wait_entry);
- HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock);
ret = ring_dispatch_messages(ring, appctx, &sft->ofs, &last_ofs, 0, syslog_applet_append_event);
if (ret) {
/* let's be woken up once new data arrive */
- HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock);
MT_LIST_APPEND(&ring->waiters, &appctx->wait_entry);
ofs = ring_tail(ring);
- 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
if (!sink)
return;
- HA_RWLOCK_WRLOCK(RING_LOCK, &sink->ctx.ring->lock);
MT_LIST_DELETE(&sft->appctx->wait_entry);
- HA_RWLOCK_WRUNLOCK(RING_LOCK, &sink->ctx.ring->lock);
sft->appctx = NULL;
task_wakeup(sink->forward_task, TASK_WOKEN_MSG);