summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/thread_bundle.h
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/vespa/vespalib/util/thread_bundle.h')
-rw-r--r--vespalib/src/vespa/vespalib/util/thread_bundle.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/vespalib/src/vespa/vespalib/util/thread_bundle.h b/vespalib/src/vespa/vespalib/util/thread_bundle.h
index 699fd8e27a0..830d7c76e7c 100644
--- a/vespalib/src/vespa/vespalib/util/thread_bundle.h
+++ b/vespalib/src/vespa/vespalib/util/thread_bundle.h
@@ -27,7 +27,34 @@ struct ThreadBundle {
* their completion. This function cannot be called with more
* targets than the size of this bundle.
**/
- virtual void run(const std::vector<Runnable*> &targets) = 0;
+ virtual void run(Runnable* const* targets, size_t cnt) = 0;
+
+ // convenience run wrapper
+ void run(const std::vector<Runnable*> &targets) {
+ run(targets.data(), targets.size());
+ }
+
+ // convenience run wrapper
+ void run(const std::vector<Runnable::UP> &targets) {
+ static_assert(sizeof(Runnable::UP) == sizeof(Runnable*));
+ run(reinterpret_cast<Runnable* const*>(targets.data()), targets.size());
+ }
+
+ template <typename T>
+ static constexpr bool is_runnable_ptr() {
+ return (std::is_same_v<T,Runnable*> || std::is_same_v<T,Runnable::UP>);
+ }
+
+ // convenience run wrapper
+ template <typename Item>
+ std::enable_if_t<!is_runnable_ptr<Item>(),void> run(std::vector<Item> &items) {
+ std::vector<Runnable*> targets;
+ targets.reserve(items.size());
+ for (auto &item: items) {
+ targets.push_back(resolve(item));
+ }
+ run(targets);
+ }
/**
* Empty virtual destructor to enable subclassing.
@@ -36,7 +63,11 @@ struct ThreadBundle {
// a thread bundle that can only run things in the current thread.
static ThreadBundle &trivial();
+
+private:
+ Runnable *resolve(Runnable &target) { return &target; }
+ template <typename T>
+ Runnable *resolve(const std::unique_ptr<T> &target) { return target.get(); }
};
} // namespace vespalib
-