Commit f9511420 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Split out the global ShutdownSocketSet singleton

Summary:
[Folly] Split out the global `ShutdownSocketSet` singleton into its own library to keep the dependencies of `ShutdownSocketSet` lighter-weight.

In general, globals should be an opt-in sort of thing anyway.

Reviewed By: elsteveogrande

Differential Revision: D6790009

fbshipit-source-id: c68fa2bbaeaf3ff205e0c3b1c739d7561e940e64
parent a963e277
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/io/GlobalShutdownSocketSet.h>
#include <folly/Singleton.h>
namespace folly {
namespace {
struct PrivateTag {};
} // namespace
static Singleton<ShutdownSocketSet, PrivateTag> singleton;
std::shared_ptr<ShutdownSocketSet> tryGetShutdownSocketSet() {
return singleton.try_get();
}
ReadMostlySharedPtr<ShutdownSocketSet> tryGetShutdownSocketSetFast() {
return singleton.try_get_fast();
}
} // namespace folly
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <memory>
#include <folly/experimental/ReadMostlySharedPtr.h>
#include <folly/io/ShutdownSocketSet.h>
namespace folly {
std::shared_ptr<ShutdownSocketSet> tryGetShutdownSocketSet();
ReadMostlySharedPtr<ShutdownSocketSet> tryGetShutdownSocketSetFast();
} // namespace folly
......@@ -22,26 +22,16 @@
#include <glog/logging.h>
#include <folly/FileUtil.h>
#include <folly/Singleton.h>
#include <folly/portability/Sockets.h>
namespace folly {
namespace {
struct PrivateTag {};
folly::Singleton<folly::ShutdownSocketSet, PrivateTag> singleton;
} // namespace
ShutdownSocketSet::ShutdownSocketSet(int maxFd)
: maxFd_(maxFd),
data_(static_cast<std::atomic<uint8_t>*>(
folly::checkedCalloc(size_t(maxFd), sizeof(std::atomic<uint8_t>)))),
nullFile_("/dev/null", O_RDWR) {}
std::shared_ptr<ShutdownSocketSet> ShutdownSocketSet::getInstance() {
return singleton.try_get();
}
void ShutdownSocketSet::add(int fd) {
// Silently ignore any fds >= maxFd_, very unlikely
DCHECK_GE(fd, 0);
......
......@@ -39,10 +39,6 @@ class ShutdownSocketSet : private boost::noncopyable {
*/
explicit ShutdownSocketSet(int maxFd = 1 << 18);
// Singleton instance used by all thrift servers.
// May return nullptr on startup/shutdown.
static std::shared_ptr<ShutdownSocketSet> getInstance();
/**
* Add an already open socket to the list of sockets managed by
* ShutdownSocketSet. You MUST close the socket by calling
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment