aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/shared_threading_service.h
blob: a436c3a8006b26d04304916da5af9662db2c9707 (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
40
41
42
43
44
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "i_shared_threading_service.h"
#include "shared_threading_service_config.h"
#include <vespa/vespalib/util/threadexecutor.h>
#include <vespa/vespalib/util/syncable.h>
#include <memory>

namespace vespalib {
    class IDestructorCallback;
}
namespace proton {

/**
 * Class containing the thread executors that are shared across all document dbs.
 */
class SharedThreadingService : public ISharedThreadingService {
private:
    using Registration = std::unique_ptr<vespalib::IDestructorCallback>;
    FNET_Transport                                  & _transport;
    std::shared_ptr<vespalib::SyncableThreadExecutor> _shared;
    std::unique_ptr<vespalib::ISequencedTaskExecutor> _field_writer;
    std::unique_ptr<vespalib::InvokeService>          _invokeService;
    std::vector<Registration>                         _invokeRegistrations;
    storage::spi::BucketExecutor&                     _bucket_executor;
public:
    SharedThreadingService(const SharedThreadingServiceConfig& cfg,
                           FNET_Transport& transport,
                           storage::spi::BucketExecutor& bucket_executor);
    ~SharedThreadingService() override;

    std::shared_ptr<vespalib::Executor> shared_raw() { return _shared; }
    void sync_all_executors();

    vespalib::ThreadExecutor& shared() override { return *_shared; }
    vespalib::ISequencedTaskExecutor& field_writer() override { return *_field_writer; }
    vespalib::InvokeService & invokeService() override { return *_invokeService; }
    FNET_Transport & transport() override { return _transport; }
    storage::spi::BucketExecutor& bucket_executor() override { return _bucket_executor; }
    const std::atomic<vespalib::steady_time> & nowRef() const override;
};

}