Hello,

On Sat, 7 Nov 2026 15:29:21 Samuel Thibault wrote:

> > > Ok, then you can use a local struct port_bucket* variable to store the > > > pointer while you are unsure whether the function will succeed, and then > > > either store to the global variable on success, or deallocate the bucket
> > > on failure.
> >
> > We can keep the check on pager_port_bucket by first saving the result of
> > ports_create_bucket into a static variable, tmp_port_bucket.
>
> Why should that variable be static?

This avoids the need to allocate and deallocate a new port_bucket every time,
if pager_start_workers returns an error.

> static variables local to functions really pose maintainability issues.

Since the function is protected by a mutex, there shouldn't be any issues
when it’s called from multiple threads (if I’ve understood the issues).

Then again, if the operations to allocate and deallocate a port_bucket aren't
particularly resource-intensive, perhaps such optimizations aren't
necessary...  In any case, code is written once but read many times.
Also, what is the correct way to deallocate a port_bucket? Judging by
create-bucket.c, a single call to free (port_bucket) is not sufficient.
Perhaps it would be worth adding a dedicated function for this in libports?

Thanks,

--
Mikhail Karpov


Reply via email to