aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/threadstackexecutor.h
blob: 9011799ece4da90454854eceff351da35e73ecbc (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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "threadstackexecutorbase.h"

namespace vespalib {

/**
 * An executor service that executes tasks in multiple threads.
 **/
class ThreadStackExecutor : public ThreadStackExecutorBase
{
public:
    bool acceptNewTask(unique_lock &, std::condition_variable &) override;
    void wakeup(unique_lock &, std::condition_variable &) override;

    /**
     * Create a new thread stack executor. The task limit specifies
     * the maximum number of tasks that are currently handled by this
     * executor. Both the number of threads and the task limit must be
     * greater than 0.
     *
     * @param threads number of worker threads (concurrent tasks)
     * @param taskLimit upper limit on accepted tasks
     **/
    ThreadStackExecutor(uint32_t threads, uint32_t taskLimit);
    ThreadStackExecutor(uint32_t threads);

    // same as above, but enables you to specify a custom function
    // used to wrap the main loop of all worker threads
    ThreadStackExecutor(uint32_t threads, init_fun_t init_function, uint32_t taskLimit);
    ThreadStackExecutor(uint32_t threads, init_fun_t init_function);

    ~ThreadStackExecutor() override;
};

} // namespace vespalib