From c41b3e8dff5b24a0884eb131463684edafec3d9c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 2 Mar 2018 10:27:12 +0100 Subject: [PATCH] DOC: buffers: clarify the purpose of the pointer in offer_buffers() This one is only used to compare pointers and NULL is permitted though this is far from being clear. --- include/common/buffer.h | 7 +++++++ src/buffer.c | 1 + 2 files changed, 8 insertions(+) diff --git a/include/common/buffer.h b/include/common/buffer.h index 7ac98bf0d..1a577ca3d 100644 --- a/include/common/buffer.h +++ b/include/common/buffer.h @@ -769,6 +769,13 @@ static inline struct buffer *b_alloc_margin(struct buffer **buf, int margin) } +/* Offer a buffer currently belonging to target to whoever needs one. + * Any pointer is valid for , including NULL. Its purpose is to avoid + * passing a buffer to oneself in case of failed allocations (e.g. need two + * buffers, get one, fail, release it and wake up self again). In case of + * normal buffer release where it is expected that the caller is not waiting + * for a buffer, NULL is fine. + */ void __offer_buffer(void *from, unsigned int threshold); static inline void offer_buffers(void *from, unsigned int threshold) diff --git a/src/buffer.c b/src/buffer.c index 167b75ae7..79cc133cb 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -247,6 +247,7 @@ void buffer_dump(FILE *o, struct buffer *b, int from, int to) fflush(o); } +/* see offer_buffer() for details */ void __offer_buffer(void *from, unsigned int threshold) { struct buffer_wait *wait, *bak;