aboutsummaryrefslogtreecommitdiffstats
path: root/searchcorespi/src/vespa/searchcorespi/flush/closureflushtask.h
blob: be2bc390fe57874644afc846795df3d067f78da0 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "flushtask.h"
#include <vespa/vespalib/util/closure.h>

namespace searchcorespi {

class ClosureFlushTask : public FlushTask
{
    std::unique_ptr<vespalib::Closure> _closure;
    search::SerialNum _flushSerial;

public:
    ClosureFlushTask(std::unique_ptr<vespalib::Closure> closure,
                     search::SerialNum flushSerial)
        : _closure(std::move(closure)),
          _flushSerial(flushSerial)
    {
    }
    
    search::SerialNum getFlushSerial() const override {
        return _flushSerial;
    }

    void run() override {
        _closure->call();
    }
};

/**
 * Wraps a Closure as a FlushTask
 **/
static inline FlushTask::UP
makeFlushTask(std::unique_ptr<vespalib::Closure> closure,
              search::SerialNum flushSerial)
{
    return FlushTask::UP(new ClosureFlushTask(std::move(closure), flushSerial));
}

} // namespace searchcorespi