aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/test/thread_utils.h
blob: d193a9555c335ac9a23d487f2ed67731f4b6f5e0 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/searchcorespi/index/ithreadingservice.h>
#include <vespa/vespalib/util/lambdatask.h>

namespace proton::test {

/**
 * Run the given function in the master thread and wait until done.
 */
template <typename FunctionType>
void
runInMasterAndSync(searchcorespi::index::IThreadingService &writeService, FunctionType func)
{
    writeService.master().execute(vespalib::makeLambdaTask(std::move(func)));
    writeService.master().sync();
}

/**
 * Run the given function in the master thread.
 */
template <typename FunctionType>
void
runInMaster(searchcorespi::index::IThreadingService &writeService, FunctionType func)
{
    writeService.master().execute(vespalib::makeLambdaTask(std::move(func)));
}

}