1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00
Zygo Blaxell 3ce00a5ebe lib: introduce Pool, a class for storing reusable anonymous objects
Pool is a place to store shared_ptrs to generated objects (T) that are
too expensive to create and destroy between individual uses, such as
temporary files.  Objects in a Pool have no distinct identity
(contrast with Cache or NamedPtr).

Users of the Pool invoke the Pool function call overload and "check out"
a shared_ptr<T> for a T object from the Pool.  When the last referencing
shared_otr<T> is destroyed, the T object is "checked in" to the Pool.

Each call of the Pool function overload checks out a shared_ptr<T> to a T
object that is not currently referenced by any other public shared_ptr<T>.

If there are no existing T objects in the Pool, a new T is constructed
by calling the generator function.

The clear() method destroys all checked in T objects owned by the Pool
at the time the method is called.  T objects that are checked out are
not affected by clear(), and they will be stored in the Pool when they
are checked in.

If the checkout function is provided, it is called on a shared_ptr<T>
during checkout, before returning to the caller.

If the checkin function is provided, it is called on a shared_ptr<T>
before returning it to the Pool.  The checkin function must not throw
exceptions.

The Pool may be destroyed while T objects are checked out of the Pool.
In that case, when the T objects are checked in, the T object is
immediately destroyed without calling the checkin function.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
2020-12-17 17:54:51 -05:00
..
2018-02-07 23:14:38 -05:00
2018-01-18 23:41:29 +01:00
2019-06-12 22:48:06 -04:00
2018-01-15 11:07:48 -05:00
2016-12-13 12:52:26 +11:00
2018-12-09 23:45:52 -05:00
2017-01-18 22:17:02 -05:00