YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/capabilities.cc
Line
Count
Source
1
// Copyright (c) YugaByte, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4
// in compliance with the License.  You may obtain a copy of the License at
5
//
6
// http://www.apache.org/licenses/LICENSE-2.0
7
//
8
// Unless required by applicable law or agreed to in writing, software distributed under the License
9
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
10
// or implied.  See the License for the specific language governing permissions and limitations
11
// under the License.
12
//
13
14
#include "yb/util/capabilities.h"
15
16
17
#include "yb/gutil/spinlock.h"
18
19
namespace yb {
20
21
namespace {
22
23
std::vector<CapabilityId>* capabilities_ = nullptr;
24
25
class CapabilitiesShutdown {
26
 public:
27
30.9k
  ~CapabilitiesShutdown() {
28
30.9k
    delete capabilities_;
29
30.9k
  }
30
};
31
32
CapabilitiesShutdown capabilities_shutdown_;
33
34
// If capability non zero - add it to capabilities.
35
// If out is not nullptr - copy all capabilities to it.
36
296k
void CapabilityHelper(CapabilityId capability, std::vector<CapabilityId>* out) {
37
296k
  static base::SpinLock mutex(base::SpinLock::LINKER_INITIALIZED);
38
296k
  base::SpinLockHolder lock(&mutex);
39
296k
  if (!capabilities_) {
40
26.8k
    capabilities_ = new std::vector<CapabilityId>();
41
26.8k
  }
42
296k
  if (capability) {
43
70.2k
    capabilities_->push_back(capability);
44
70.2k
  }
45
296k
  if (out) {
46
225k
    *out = *capabilities_;
47
225k
  }
48
296k
}
49
50
} // namespace
51
52
70.2k
CapabilityRegisterer::CapabilityRegisterer(CapabilityId capability) {
53
70.2k
  CapabilityHelper(capability, nullptr /* out */);
54
70.2k
}
55
56
225k
std::vector<CapabilityId> Capabilities() {
57
225k
  std::vector<CapabilityId> result;
58
225k
  CapabilityHelper(0 /* capability */, &result);
59
225k
  return result;
60
225k
}
61
62
} // namespace yb