summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/thread.cpp
blob: cad24c5bcda7c6f731f6f3fb60ad9dbb5a3dac6d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "thread.h"

namespace vespalib {

Thread &
Thread::operator=(Thread &&rhs) noexcept
{
    // may call std::terminate
    _thread = std::move(rhs._thread);
    return *this;
}

void
Thread::join()
{
    if (_thread.joinable()) {
        _thread.join();
    }
}

Thread::~Thread()
{
    join();
}

Thread
Thread::start(Runnable &runnable, Runnable::init_fun_t init_fun)
{
    return start([&runnable, init_fun](){ init_fun(runnable); });
}

} // namespace vespalib