Commit 50e8c130 authored by Maged Michael's avatar Maged Michael Committed by Facebook GitHub Bot

NotificationQueue: Use folly::get_cached_pid() instead of getpid()

Summary:
Use folly::get_cached_pid(), a faster getpid() replacement, in NotificationQueue.

Outline CHECK_EQ from checkPid().

Reviewed By: yfeldblum

Differential Revision: D23433868

fbshipit-source-id: 66ef0e243d74aa176a496e1ae15aeae5e67e4f5c
parent 52561279
......@@ -37,6 +37,7 @@
#include <folly/portability/Fcntl.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Unistd.h>
#include <folly/system/Pid.h>
#include <glog/logging.h>
......@@ -276,7 +277,7 @@ class NotificationQueue {
: eventfd_(-1),
pipeFds_{-1, -1},
advisoryMaxQueueSize_(maxSize),
pid_(pid_t(getpid())) {
pid_(folly::get_cached_pid()) {
#ifdef FOLLY_HAVE_EVENTFD
if (fdType == FdType::EVENTFD) {
......@@ -472,7 +473,9 @@ class NotificationQueue {
* code, and crash before signalling the parent process.
*/
void checkPid() const {
CHECK_EQ(pid_, pid_t(getpid()));
if (FOLLY_UNLIKELY(pid_ != folly::get_cached_pid())) {
checkPidFail();
}
}
private:
......@@ -632,6 +635,13 @@ class NotificationQueue {
}
}
FOLLY_NOINLINE void checkPidFail() const {
folly::terminate_with<std::runtime_error>(
"Pid mismatch. Pid = " +
folly::to<std::string>(folly::get_cached_pid()) + ". Expecting " +
folly::to<std::string>(pid_));
}
mutable folly::SpinLock spinlock_;
mutable bool signal_{false};
int eventfd_;
......
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