diff options
Diffstat (limited to 'alloc.c')
-rw-r--r-- | alloc.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -193,3 +193,30 @@ void *mog_fsbuf_get(size_t *size) return ptr; } + +/* + * attempts to reattach an rbuf belonging to a previously-idle client + * if it makes sense to reattach. + * + * We want to favor rbufs attached to clients if they are bigger than + * the thread-local one. + */ +void mog_rbuf_reattach_and_null(struct mog_rbuf **ptrptr) +{ + struct mog_rbuf *rbuf = *ptrptr; + + if (!rbuf) + return; + *ptrptr = NULL; + + assert(rbuf != tls_rbuf && "cannot reattach, already attached"); + if (tls_rbuf) { + /* we never want to swap a small buffer for a big buffer */ + if (rbuf->rcapa < tls_rbuf->rcapa) { + mog_rbuf_free(rbuf); + return; + } + free(tls_rbuf); + } + tls_rbuf = rbuf; +} |