mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[1/N] Use internal linkage in torch/csrc C++ files. (#150930)
Turn more functions and variables into static if they are not used outside the cpp files. Unused functions are removed. Pull Request resolved: https://github.com/pytorch/pytorch/pull/150930 Approved by: https://github.com/Skylion007 Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
This commit is contained in:
committed by
PyTorch MergeBot
parent
48132de4af
commit
24ca7e91e6
@ -8,10 +8,10 @@
|
||||
#include <libshm/libshm.h>
|
||||
#include <libshm/socket.h>
|
||||
|
||||
std::unordered_map<std::string, ClientSocket> managers;
|
||||
std::string manager_executable_path;
|
||||
static std::unordered_map<std::string, ClientSocket> managers;
|
||||
static std::string manager_executable_path;
|
||||
|
||||
AllocInfo get_alloc_info(const char* filename) {
|
||||
static AllocInfo get_alloc_info(const char* filename) {
|
||||
AllocInfo info = {};
|
||||
info.pid = getpid();
|
||||
info.free = false;
|
||||
@ -23,7 +23,7 @@ AllocInfo get_alloc_info(const char* filename) {
|
||||
return info;
|
||||
}
|
||||
|
||||
void start_manager() {
|
||||
static void start_manager() {
|
||||
std::array<int, 2> pipe_ends;
|
||||
SYSCHECK_ERR_RETURN_NEG1(pipe(pipe_ends.data()));
|
||||
|
||||
@ -78,7 +78,7 @@ void start_manager() {
|
||||
managers.emplace(std::move(handle), std::move(manager));
|
||||
}
|
||||
|
||||
ClientSocket& get_manager_socket(const std::string& manager_handle) {
|
||||
static ClientSocket& get_manager_socket(const std::string& manager_handle) {
|
||||
auto it = managers.find(manager_handle);
|
||||
if (it == managers.end()) {
|
||||
auto socket = ClientSocket(manager_handle);
|
||||
|
@ -32,19 +32,19 @@ struct ClientSession {
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
std::vector<struct pollfd> pollfds;
|
||||
std::unordered_map<int, ClientSession> client_sessions;
|
||||
static std::vector<struct pollfd> pollfds;
|
||||
static std::unordered_map<int, ClientSession> client_sessions;
|
||||
// TODO: check if objects have been freed from time to time
|
||||
std::set<std::string> used_objects;
|
||||
static std::set<std::string> used_objects;
|
||||
|
||||
void register_fd(int fd) {
|
||||
static void register_fd(int fd) {
|
||||
struct pollfd pfd = {};
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN;
|
||||
pollfds.push_back(pfd);
|
||||
}
|
||||
|
||||
void unregister_fd(int fd) {
|
||||
static void unregister_fd(int fd) {
|
||||
pollfds.erase(
|
||||
std::remove_if(
|
||||
pollfds.begin(),
|
||||
@ -54,7 +54,7 @@ void unregister_fd(int fd) {
|
||||
client_sessions.erase(fd);
|
||||
}
|
||||
|
||||
void print_init_message(std::string_view message) {
|
||||
static void print_init_message(std::string_view message) {
|
||||
ssize_t written_bytes = -1;
|
||||
while (!message.empty()) {
|
||||
// NOLINTNEXTLINE(bugprone-assignment-in-if-condition)
|
||||
@ -69,7 +69,7 @@ void print_init_message(std::string_view message) {
|
||||
}
|
||||
}
|
||||
|
||||
bool object_exists(const char* name) {
|
||||
static bool object_exists(const char* name) {
|
||||
int fd = shm_open(name, O_RDONLY, 0);
|
||||
if (fd >= 0) {
|
||||
close(fd);
|
||||
@ -79,7 +79,7 @@ bool object_exists(const char* name) {
|
||||
}
|
||||
}
|
||||
|
||||
void free_used_object(const std::string& name) {
|
||||
static void free_used_object(const std::string& name) {
|
||||
if (!object_exists(name.c_str())) {
|
||||
DEBUG("object %s appears to have been freed", name.c_str());
|
||||
used_objects.erase(name);
|
||||
|
Reference in New Issue
Block a user