/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 | 3.14k | uint16_t PortPicker::AllocateFreePort() { |
22 | 3.14k | 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 | 3.14k | free_port_file_locks_.emplace_back(); |
27 | 3.14k | return GetFreePort(&free_port_file_locks_.back()); |
28 | 3.14k | } |
29 | | |
30 | | } // namespace yb |