[syslog-ng] Per-thread scratch buffers
Gergely Nagy
algernon at balabit.hu
Mon Oct 31 10:16:28 CET 2011
Balazs Scheidler <bazsi at balabit.hu> writes:
> The alternative idea I was playing with was to create a new API for
> managing per-thread scratch buffers that could be reused even between
> multiple independent portions of syslog-ng.
>
> The way it would work:
> - scratch buffers are a numbered array of GString buffers, allocated
> for _each_ thread.
Any reason we want per-thread scratch buffers? Apart from not needing to
use a lock in this case..
As a first step in implementing this, I had something like the following
in mind:
static GTrashStack *scratch_buffers;
GString *scratch_buffer_acquite (void)
{
GString *s;
s = g_trash_stack_pop (scratch_buffers);
if (!s)
s = g_string_new (NULL);
else
g_string_set_size (s, 0);
return s;
}
void scratch_buffer_release (GString *s)
{
g_trash_stack_push (s);
}
void scratch_buffers_reset (void)
{
GString *s;
while ((s = g_trash_stack_pop (scratch_buffers)) != NULL)
g_string_free (s, TRUE);
}
The expected usage is to acquire a buffer when needed, and release it
whenever we don't need it anymore.
Spice it up with some __tls_deref & similar, and we're pretty much done,
I think.
What do you think? (Meanwhile, I'll go ahead and see if this works)
--
|8]
More information about the syslog-ng
mailing list