aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/blockingthreadstackexecutor.h
blob: 49e4c14689cde6870337c410ff316d5a4a0bcb70 (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
// Copyright Vespa.ai. 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 BlockingThreadStackExecutor : public ThreadStackExecutorBase
{
public:
    bool acceptNewTask(unique_lock & guard, std::condition_variable & cond) override;
    void wakeup(unique_lock & guard, std::condition_variable &) override;

    /**
     * Create a new blocking thread stack executor. The task limit specifies
     * the maximum number of tasks that are currently handled by this
     * executor. Trying to execute more tasks will block.
     *
     * @param threads number of worker threads (concurrent tasks)
     * @param taskLimit upper limit on accepted tasks
     **/
    BlockingThreadStackExecutor(uint32_t threads, uint32_t taskLimit);

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

    ~BlockingThreadStackExecutor() override;
};

} // namespace vespalib