summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/thread_bundle.cpp
blob: 9f953abfce7291c6df7d0b8152e52c4f94c4d5f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "thread_bundle.h"
#include "exceptions.h"

namespace vespalib {

ThreadBundle &
ThreadBundle::trivial() {
    struct TrivialThreadBundle : ThreadBundle {
        size_t size() const override { return 1; }
        void run(const std::vector<Runnable*> &targets) override {
            if (targets.size() == 1) {
                targets[0]->run();
            } else if (targets.size() > 1) {
                throw IllegalArgumentException("too many targets");
            }
        };
    };
    static TrivialThreadBundle trivial_thread_bundle;
    return trivial_thread_bundle;
}

} // namespace vespalib