Skip to content

Commit 50e8c13

Browse files
magedmfacebook-github-bot
authored andcommitted
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
1 parent 5256127 commit 50e8c13

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

folly/io/async/NotificationQueue.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <folly/portability/Fcntl.h>
3838
#include <folly/portability/Sockets.h>
3939
#include <folly/portability/Unistd.h>
40+
#include <folly/system/Pid.h>
4041

4142
#include <glog/logging.h>
4243

@@ -276,7 +277,7 @@ class NotificationQueue {
276277
: eventfd_(-1),
277278
pipeFds_{-1, -1},
278279
advisoryMaxQueueSize_(maxSize),
279-
pid_(pid_t(getpid())) {
280+
pid_(folly::get_cached_pid()) {
280281

281282
#ifdef FOLLY_HAVE_EVENTFD
282283
if (fdType == FdType::EVENTFD) {
@@ -472,7 +473,9 @@ class NotificationQueue {
472473
* code, and crash before signalling the parent process.
473474
*/
474475
void checkPid() const {
475-
CHECK_EQ(pid_, pid_t(getpid()));
476+
if (FOLLY_UNLIKELY(pid_ != folly::get_cached_pid())) {
477+
checkPidFail();
478+
}
476479
}
477480

478481
private:
@@ -632,6 +635,13 @@ class NotificationQueue {
632635
}
633636
}
634637

638+
FOLLY_NOINLINE void checkPidFail() const {
639+
folly::terminate_with<std::runtime_error>(
640+
"Pid mismatch. Pid = " +
641+
folly::to<std::string>(folly::get_cached_pid()) + ". Expecting " +
642+
folly::to<std::string>(pid_));
643+
}
644+
635645
mutable folly::SpinLock spinlock_;
636646
mutable bool signal_{false};
637647
int eventfd_;

0 commit comments

Comments
 (0)