MINOR: ring: add the definition of a ring waiting cell

This is what will be used to describe one waiting thread, its message
in the queues, and the aggregation of pending messages after it.
This commit is contained in:
Willy Tarreau 2024-03-11 14:27:42 +01:00
parent 447189f286
commit e3f101a19a
2 changed files with 27 additions and 0 deletions

View File

@ -106,6 +106,25 @@
/* mask used to lock the tail */ /* mask used to lock the tail */
#define RING_TAIL_LOCK (1ULL << ((sizeof(size_t) * 8) - 1)) #define RING_TAIL_LOCK (1ULL << ((sizeof(size_t) * 8) - 1))
/* A cell describing a waiting thread.
* ->next is initialized to 0x1 before the pointer is set, so that any
* leader thread can see that the pointer is not set yet. This allows
* to enqueue all waiting threads very quickly using XCHG() on the head
* without having to rely on a flaky CAS, while threads finish their setup
* in parallel. The pointer will turn to NULL again once the thread is
* released.
*/
struct ring_wait_cell {
size_t to_send_self; // size needed to serialize this msg
size_t needed_tot; // size needed to serialize pending msgs
size_t maxlen; // msg truncated to this size
const struct ist *pfx; // prefixes
size_t npfx; // #prefixes
const struct ist *msg; // message parts
size_t nmsg; // #message parts
struct ring_wait_cell *next; // next waiting thread
};
/* this is the mmapped part */ /* this is the mmapped part */
struct ring_storage { struct ring_storage {
size_t size; // storage size size_t size; // storage size
@ -126,6 +145,13 @@ struct ring {
uint flags; // RING_FL_* uint flags; // RING_FL_*
uint pending; // new writes that have not yet been subject to a wakeup uint pending; // new writes that have not yet been subject to a wakeup
uint waking; // indicates a thread is currently waking up readers uint waking; // indicates a thread is currently waking up readers
/* keep the queue in a separate cache line below */
THREAD_PAD(64 - 3*sizeof(void*) - 4*sizeof(int));
struct ring_wait_cell *queue; // wait queue
/* and leave a spacer after it to avoid false sharing */
THREAD_PAD(64 - sizeof(void*));
}; };
#endif /* _HAPROXY_RING_T_H */ #endif /* _HAPROXY_RING_T_H */

View File

@ -51,6 +51,7 @@ void ring_init(struct ring *ring, void *area, size_t size, int reset)
ring->storage = area; ring->storage = area;
ring->pending = 0; ring->pending = 0;
ring->waking = 0; ring->waking = 0;
ring->queue = NULL;
if (reset) { if (reset) {
ring->storage->size = size - sizeof(*ring->storage); ring->storage->size = size - sizeof(*ring->storage);