blob: a11f1853162800a3d7620f8a604bccb2ef325f57 (
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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/searchcorespi/index/i_thread_service.h>
namespace proton::test {
/**
* Implementation of IThreadService that overrides isCurrentThread() to true.
* Can be used by unit tests that do not care about that functions are executed in the correct
* thread.
*/
class SimpleThreadService : public searchcorespi::index::IThreadService
{
private:
searchcorespi::index::IThreadService &_service;
public:
SimpleThreadService(searchcorespi::index::IThreadService &service)
: _service(service)
{
}
virtual vespalib::Executor::Task::UP execute(vespalib::Executor::Task::UP task) {
return _service.execute(std::move(task));
}
virtual void run(vespalib::Runnable &runnable) {
_service.run(runnable);
// sync() because underlying implementation can use isCurrentThread()
// to determine to run it directly.
if (!_service.isCurrentThread()) {
sync();
}
}
virtual vespalib::Syncable &sync() {
_service.sync();
return *this;
}
virtual bool isCurrentThread() const {
return true;
}
};
}
|