Replace ShutdownSocketSet to singleton
[folly.git] / folly / io / ShutdownSocketSet.cpp
index 09988e7a2593471f15fd019c164f5667d938055d..a64ae49ae5e9ed8595dbe115d78cbea45cbed4c2 100644 (file)
 #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);