YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/util/port_picker.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 <mutex>
15
16
#include "yb/util/port_picker.h"
17
#include "yb/util/net/net_util.h"
18
19
namespace yb {
20
21
6.95k
uint16_t PortPicker::AllocateFreePort() {
22
6.95k
  std::lock_guard<std::mutex> lock(mutex_);
23
24
  // This will take a file lock ensuring the port does not get claimed by another thread/process
25
  // and add it to our vector of such locks that will be freed on minicluster shutdown.
26
6.95k
  free_port_file_locks_.emplace_back();
27
6.95k
  return GetFreePort(&free_port_file_locks_.back());
28
6.95k
}
29
30
}  // namespace yb