Commit 8144bc19 authored by Pranjal Raihan's avatar Pranjal Raihan Committed by Facebook GitHub Bot

Use std::atomic<bool> instead of folly::once_flag in folly::detail::MemoryIdler

Summary:
Trying to use `ZeroSizeMutex` in `CallOnce.h` causes a circular dependency:
```
//folly/synchronization:call_once ->
//folly/synchronization:call_once-module ->
//folly/synchronization:call_once-module-helper ->
//folly/synchronization:zero_size_mutex ->
//folly/synchronization:baton ->
//folly/detail:memory_idler ->
//folly/synchronization:call_once
```
The benefits of `folly::once_flag` are as follows:
https://www.internalfb.com/intern/diffusion/FBS/browse/master/fbcode/folly/synchronization/CallOnce.h?commit=d0211e9462c39c4655a7d2ff9d313f6fb433d74a&lines=37-42

A fast path is not necessary here because it's just logging within an error case.
Exception-proof behavior is not needed because glog does not throw.

Reviewed By: yfeldblum, andriigrynenko

Differential Revision: D25797067

fbshipit-source-id: 4de20235ff4115b73ab8a2689e7697fc9fe4ba65
parent bf83c8d2
......@@ -16,6 +16,7 @@
#include <folly/detail/MemoryIdler.h>
#include <atomic>
#include <climits>
#include <cstdio>
#include <cstring>
......@@ -30,7 +31,6 @@
#include <folly/portability/PThread.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h>
#include <folly/synchronization/CallOnce.h>
namespace folly {
namespace detail {
......@@ -97,10 +97,10 @@ static void fetchStackLimits() {
pthread_attr_t attr;
if ((err = pthread_getattr_np(pthread_self(), &attr))) {
// some restricted environments can't access /proc
static folly::once_flag flag;
folly::call_once(flag, [err]() {
static std::atomic<bool> flag{false};
if (!flag.exchange(true, std::memory_order_relaxed)) {
LOG(WARNING) << "pthread_getaddr_np failed errno=" << err;
});
}
tls_stackSize = 1;
return;
......
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