diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-09-20 09:21:54 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-09-20 09:21:54 +0000 |
commit | b572b42a0f757e282a4b063ee75c5d21b25d55bd (patch) | |
tree | 2ca7e4589f817e16aecb258dd7890dfc9603d3bc /vespalib | |
parent | e32c2ccebb0a25df0f26f487ffc8b1a281166e48 (diff) |
Refactor code to make object lifetime easier to follow.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/simple_thread_bundle.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h index 536474d9300..70dbfbffb84 100644 --- a/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h +++ b/vespalib/src/vespa/vespalib/util/simple_thread_bundle.h @@ -103,9 +103,21 @@ public: std::vector<SimpleThreadBundle*> _bundles; public: + class Guard { + public: + Guard(Pool & pool) : _bundle(pool.obtain()), _pool(pool) {} + Guard(const Guard &) = delete; + Guard & operator =(const Guard &) = delete; + ~Guard() { _pool.release(std::move(_bundle)); } + SimpleThreadBundle & bundle() { return *_bundle; } + private: + SimpleThreadBundle::UP _bundle; + Pool &_pool; + }; Pool(size_t bundleSize, init_fun_t init_fun); Pool(size_t bundleSize) : Pool(bundleSize, Runnable::default_init_function) {} ~Pool(); + Guard getBundle() { return Guard(*this); } SimpleThreadBundle::UP obtain(); void release(SimpleThreadBundle::UP bundle); }; |