blob: fbb31967c5a1d3b8a4a1cee07384ab4ff7f4bac5 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "bucketdb.h"
#include <mutex>
namespace proton::bucketdb {
class Guard
{
public:
Guard(BucketDB *bucketDB, std::mutex &mutex);
Guard(const Guard &) = delete;
Guard(Guard &&rhs);
Guard &operator=(const Guard &) = delete;
Guard &operator=(Guard &&rhs) = delete;
BucketDB *operator->() { return _bucketDB; }
BucketDB &operator*() { return *_bucketDB; }
const BucketDB *operator->() const { return _bucketDB; }
const BucketDB &operator*() const { return *_bucketDB; }
private:
BucketDB *_bucketDB;
std::unique_lock<std::mutex> _guard;
};
/**
* Class that owns and provides guarded access to a bucket database.
*/
class BucketDBOwner
{
public:
BucketDBOwner();
Guard takeGuard() {
return Guard(&_bucketDB, _mutex);
}
size_t getNumActiveDocs() const { return _bucketDB.getNumActiveDocs(); }
private:
BucketDB _bucketDB;
std::mutex _mutex;
};
}
|