aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/document_db_directory_holder.cpp
blob: 4a09adccf96c4ebf8cf35de8596b912c2e5cf269 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "document_db_directory_holder.h"
#include <mutex>
#include <condition_variable>

namespace proton {

namespace {

std::mutex mutex;
std::condition_variable cv;

}

DocumentDBDirectoryHolder::DocumentDBDirectoryHolder()
{
}

DocumentDBDirectoryHolder::~DocumentDBDirectoryHolder()
{
    std::lock_guard guard(mutex);
    cv.notify_all();
}

void
DocumentDBDirectoryHolder::waitUntilDestroyed(const std::weak_ptr<DocumentDBDirectoryHolder> &holder)
{
    std::unique_lock guard(mutex);
    cv.wait(guard, [&]() { return !holder.lock(); });
}

} // namespace proton