1. 24 Apr, 2021 2 commits
    • Robin Cheng's avatar
      Unregister event handler fd before closing the fd in EventBaseAtomicNotificationQueue. · b756d166
      Robin Cheng authored
      Summary:
      Thread 1:
        - Creates an eventfd X
        - Registers X with an event base
        - Closes X
        - Unregisters X from the event base
      
      Thread 2:
        - Creates some other file descriptor (eventfd or socket or whatever); the operating system reuses file descriptor #X.
      
      The unregistering of X from the event base in thread 1 races with the opening of reused X in thread 2.
      
      The fix is to unregister X before closing X.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27962155
      
      fbshipit-source-id: 1bcb62c7ebe0297ab9687e1a0edf37d319637fda
      b756d166
    • Yedidya Feldblum's avatar
      cut macro FOLLY_CL_USE_FOLLY_TLS · 0297c176
      Yedidya Feldblum authored
      Summary: Replace the uses of `FOLLY_CL_USE_FOLLY_TLS` in some cases with C++ checks on `kIsMobile`.
      
      Differential Revision: D27669672
      
      fbshipit-source-id: 79a29896653f2fa62b10b488220d8cf83cba3d00
      0297c176
  2. 23 Apr, 2021 4 commits
    • Yedidya Feldblum's avatar
      fix missing include in inline-function-ref test · 483df6d0
      Yedidya Feldblum authored
      Summary: To use `std::atomic`, we need `#include <atomic>`.
      
      Reviewed By: Mizuchi
      
      Differential Revision: D27932606
      
      fbshipit-source-id: 8d29a56a75b27ae35bac37b87a7e6d6d1661030e
      483df6d0
    • Yedidya Feldblum's avatar
      use TYPED_TEST_SUITE over TYPED_TEST_CASE · 4e1a864b
      Yedidya Feldblum authored
      Summary: The facility was renamed in gtest.
      
      Reviewed By: praihan
      
      Differential Revision: D27904281
      
      fbshipit-source-id: 3f00b4371e17cd85672ad7ef706cea4ca1ba5c64
      4e1a864b
    • Yedidya Feldblum's avatar
      switch tests/benchmarks to folly native semaphore wrapper · f0d7b6d5
      Yedidya Feldblum authored
      Summary: On apple platforms, posix sem is deprecated. On windows, it does not exist. So switch to the native-semaphore wrapper.
      
      Reviewed By: chadaustin
      
      Differential Revision: D27903002
      
      fbshipit-source-id: d53c7762fea3123cf67cda48fdd87489a0ee496c
      f0d7b6d5
    • Yedidya Feldblum's avatar
      NativeSemaphore · 58a889d7
      Yedidya Feldblum authored
      Summary:
      A semaphore type which wraps the platform native semaphore type.
      
      On Windows, this is the Windows semaphore type. On Apple, this is the semaphore type from libdispatch. Otherwise, this is the POSIX semaphore type, which is deprecated on Apple and unavailable on Windows.
      
      Reviewed By: Orvid
      
      Differential Revision: D27951114
      
      fbshipit-source-id: e6a870f656eecd3ba41c2efed038b916c124d0e8
      58a889d7
  3. 22 Apr, 2021 6 commits
    • Chad Austin's avatar
      forward env vars through tpx · e9a24429
      Chad Austin authored
      Summary:
      The migration to tpx broke Watchman's tests because test_bser relies on YARN_YARN_OFFLINE_MIRROR being set in the environment and tpx doesn't forward environment variables into the test.
      
      Explicitly forward them ourselves.
      
      Reviewed By: fanzeyi
      
      Differential Revision: D27897172
      
      fbshipit-source-id: 16c8017a89979802bd9d443825ed4e22cb6ff6c9
      e9a24429
    • Giuseppe Ottaviano's avatar
      Allow creation of dismissed ScopeGuards · cc049da2
      Giuseppe Ottaviano authored
      Summary:
      This diff enables a symmetrical pattern to `makeGuard()`/`dismiss()`: `makeDismissedGuard()` will create a guard that will not execute unless `rehired()`'d.
      
      This is for use cases where the guard's scope is wider than where the condition on whether it should execute is evaluated. For example
      ```
      State state;
      auto guard = makeDismissedGuard([&] { cleanup(state); });
      if (modifyStateInAWayThatRequiresCleanup(state)) {
        guard.rehire();
      }
      // Use state.
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27931274
      
      fbshipit-source-id: fbf7048dc991b73553cd6429f5e73345e4104d49
      cc049da2
    • Yedidya Feldblum's avatar
      support FOLLY_SAFE_CHECK with no message args · a99615fe
      Yedidya Feldblum authored
      Summary:
      Permit calls of the form:
      
      ```lang=c++
      FOLLY_SAFE_DCHECK(expr);
      ```
      
      Reviewed By: ot
      
      Differential Revision: D27843903
      
      fbshipit-source-id: 23869720822fcdba0845c42279855b101c8e2b36
      a99615fe
    • Andrii Grynenko's avatar
      Make sure all observer adaptors correctly capture dependencies · dbfa7c45
      Andrii Grynenko authored
      Reviewed By: praihan
      
      Differential Revision: D27800735
      
      fbshipit-source-id: 26f2c1be72bb66864173beb87244129dd6194c8d
      dbfa7c45
    • Yedidya Feldblum's avatar
      let SingletonVault::type_ be atomic · 1366baf8
      Yedidya Feldblum authored
      Summary: It is possible to have concurrent calls to `SingletonVault::setType` and `SingletonHolder::createInstance`. In which cases, non-atomic accesses to `SingletonVault::type_` race.
      
      Differential Revision: D27904167
      
      fbshipit-source-id: be01ee375d37839629b2e1d64bec99e32cd7e213
      1366baf8
    • Yedidya Feldblum's avatar
      tweak rcu benchmarks · 549f235f
      Yedidya Feldblum authored
      Summary:
      Add a benchmark for `rcu_retire`. Remove perf code from the rcu tests.
      
      As a motivating side-effect, removes faulty calls to `printf` which fail to compile across platforms, including mac.
      
      Differential Revision: D27902852
      
      fbshipit-source-id: 1698a0fd8ca3731f0b794cb1c2cb08c4bfb5d714
      549f235f
  4. 21 Apr, 2021 2 commits
    • Yedidya Feldblum's avatar
      remove AccessSpreader extern-template-struct · cd58205e
      Yedidya Feldblum authored
      Summary:
      Using `extern template struct` can be tricky - best to avoid.
      
      Use static storage but no longer use static initialization to avoid all issues surrounding ODR, global initializers, etc. Microbenchmarks show no significant hit.
      
      Add a global constructor to continue triggering initialization at static initialization time.
      
      Differential Revision: D27746718
      
      fbshipit-source-id: c5288c33412a80bb813c8d615794b9773cef323c
      cd58205e
    • Yedidya Feldblum's avatar
      mark the SingletonThreadLocal check function as kept · c5651a00
      Yedidya Feldblum authored
      Differential Revision: D27859994
      
      fbshipit-source-id: afde93e853a08a3d65f3d817cd2bbad337bfbfce
      c5651a00
  5. 20 Apr, 2021 1 commit
    • Lee Howes's avatar
      Add Unsafe names for set and get executor calls · 1bc16f19
      Lee Howes authored
      Summary:
      To encourage migration to safer executors, add transitional *Unsafe names for the old, mutable, global executors. This is consistent with the use of *Unsafe elsewhere in the async framework.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26418111
      
      fbshipit-source-id: 414ee238ed4ae43619ce8d671fa5725f0679f67e
      1bc16f19
  6. 19 Apr, 2021 2 commits
    • Xavier Deguillard's avatar
      cmake: set CMAKE_CXX_FLAGS in FBCompilerSettingsUnix.cmake · 6696dbb0
      Xavier Deguillard authored
      Summary:
      It looks like the various CMAKE_CXX_FLAGS_* are simply ineffective, and I'm not
      sure why, setting CMAKE_CXX_FLAGS does work though, and CMake appears to add
      some release/debug flags to it when generating Ninja files.
      
      Reviewed By: fanzeyi
      
      Differential Revision: D27862117
      
      fbshipit-source-id: a89f6182b5bae9a087f8fcfd4c5f9526f91e2adf
      6696dbb0
    • Yedidya Feldblum's avatar
      call future continuations after catch · 18575625
      Yedidya Feldblum authored
      Summary: Avoid calling arbitrary user code from within the scope of framework `catch` blocks. Instead, get the current exception in the catch block, save it, and call the user code after.
      
      Differential Revision: D27842318
      
      fbshipit-source-id: de3ebabc5c08332701a619a93b6e01bfccc0ea71
      18575625
  7. 17 Apr, 2021 2 commits
    • Giuseppe Ottaviano's avatar
      __PRETTY_FUNCTION__ -> __func__ in FOLLY_SAFE_CHECK · 7c86b9b4
      Giuseppe Ottaviano authored
      Summary:
      Storing the `__PRETTY_FUNCTION__` for logging has an unreasonable cost on (non-strippable) binary size for debug builds, as different template instantiation will produce long, demangled, and non-mergeable strings.
      
      If necessary, all the information is retrievable from the debug info (even if the function is inlined), where it's stored in much more efficient form. So, switch to `__func__`, which is stripped.
      
      Reviewed By: yfeldblum, luciang
      
      Differential Revision: D27825136
      
      fbshipit-source-id: d499084c7e7b24db1cd46aa2b03f4a590c6eddc3
      7c86b9b4
    • Shai Szulanski's avatar
      Prohibit passing empty KeepAlive to scheduleOn · a87085f2
      Shai Szulanski authored
      Summary: Doing so is a bug that can take some time to pin down. Fail at the callsite instead to make this easier.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27829947
      
      fbshipit-source-id: e3628331ffb687718309e130e8e0f2f78c4eb1aa
      a87085f2
  8. 16 Apr, 2021 8 commits
    • Dan Melnic's avatar
      Add support for AsyncSocket connect bind to device · b5e88664
      Dan Melnic authored
      Summary:
      Add support for AsyncSocket connect bind to device
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: danobi
      
      Differential Revision: D27784176
      
      fbshipit-source-id: d7efe3ef59b26aa69552d5f8109f89457ee5fe66
      b5e88664
    • Yedidya Feldblum's avatar
      use do-while-false in FOLLY_SAFE_CHECK · fc32eee3
      Yedidya Feldblum authored
      Summary: To avoid the marginal but still unnecessary compile-time cost of constructing a lambda. And enclose the full thing in braces so it can be used in an unbraced `if`.
      
      Reviewed By: ot, luciang
      
      Differential Revision: D27817005
      
      fbshipit-source-id: 9a1a6e0389fea5907a3a20cffbd6a029b0a85eb9
      fc32eee3
    • Yedidya Feldblum's avatar
      outline HashingThreadId::get · fa173c4e
      Yedidya Feldblum authored
      Reviewed By: Mizuchi
      
      Differential Revision: D27669414
      
      fbshipit-source-id: 617e0b5f17fa8ce5505f7f16b00516ba7f21b064
      fa173c4e
    • Robin Cheng's avatar
      Fix a singleton at fork race? · e370385a
      Robin Cheng authored
      Summary: Why is unsafeGetUnlocked() used here? It seems obviously not safe when we're iterating on the vector after. Am I missing something?
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D27748519
      
      fbshipit-source-id: fe8a78408fdf59e83f5261740e4703f876ad9f9d
      e370385a
    • Yedidya Feldblum's avatar
      use static in FOLLY_SAFE_CHECK for clang+asan · a3c1fac8
      Yedidya Feldblum authored
      Summary: Avoid enlarging data sections. The use of `static` causes data sections to be smaller in certain critical cases.
      
      Reviewed By: cmds, luciang
      
      Differential Revision: D27813138
      
      fbshipit-source-id: 020b14927be5ac035d5f66e7cd652a58f8f820d0
      a3c1fac8
    • Dan Melnic's avatar
      Add support for AsyncSocket readv operations · e31125bc
      Dan Melnic authored
      Summary:
      Add support for AsyncSocket readv operations
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: danobi
      
      Differential Revision: D27585275
      
      fbshipit-source-id: d9a410a4c5d60af06c187e0abb5bd11b7054a6b9
      e31125bc
    • Yedidya Feldblum's avatar
      use extern-access for sanitize wrappers · 8b26cdbd
      Yedidya Feldblum authored
      Summary: Should address various build issues.
      
      Reviewed By: Orvid
      
      Differential Revision: D27699043
      
      fbshipit-source-id: 7bcb827c3372e6243554e8bf04426c041b2c62a4
      8b26cdbd
    • Andrii Grynenko's avatar
      Fix a shutdown race in CPUThreadPoolExecutor::add · ebb45e07
      Andrii Grynenko authored
      Summary:
      It's not safe to expect that the executor is alive after a task is added to the queue (this task could be holding the last KeepAlive and when finished - it may unblock the executor shutdown).
      The fix is to hold a KeepAlive if some operation has to be done after adding to the queue. However it's safe to avoid this in a case where executor thread count will never drop below 1 (otherwise not having active threads may result in a deadlock) and we already have the maximum number of threads running. This optimization should help avoid grabbing the KeepAlive on the fast path.
      
      The difference from the previous implementation is that we still start with 0 threads. But keep minThreads at at least 1.
      
      Differential Revision: D27751098
      
      fbshipit-source-id: 7b992a73b40984376893c1fe2a4a072002f0a12a
      ebb45e07
  9. 15 Apr, 2021 5 commits
    • Aleksandr Sasha Sergeev's avatar
      Add json::print_error and use it for serialization errors · c69aa19d
      Aleksandr Sasha Sergeev authored
      Summary: To differentiate serialization and deserialization errors.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27743086
      
      fbshipit-source-id: 8eb4fe1a1733e3effd0aa0478f59160381738db2
      c69aa19d
    • Yedidya Feldblum's avatar
      fix FOLLY_SAFE_CHECK under gcc+asan · c6819f96
      Yedidya Feldblum authored
      Summary:
      The build was failing at link time with the claim that `__PRETTY_FUNCTION__` was in a discarded section. This occurs only under some versions of gcc with asan enabled.
      
      This approach works by making a copy of `__PRETTY_FUNCTION__` without ever taking a reference to it.
      
      This may not be the ideal fix, but it is the first one that worked upon experimentation.
      
      Differential Revision: D27786615
      
      fbshipit-source-id: 2845c85bdc8158d4b2da7cd200ce55f982285a21
      c6819f96
    • Yedidya Feldblum's avatar
      use weakref for cxxabi demangle · e663b2bc
      Yedidya Feldblum authored
      Summary: Since `[[gnu::weakref]]` can be used effectively in cases where `[[gnu::weak]]` cannot.
      
      Reviewed By: Orvid
      
      Differential Revision: D27672340
      
      fbshipit-source-id: 4882f0176726aece411359c25411f0f4be7fc59f
      e663b2bc
    • Yedidya Feldblum's avatar
      check functions for AccessSpreader · 4a6e1bea
      Yedidya Feldblum authored
      Summary: Add some functions for looking at the code generated by `AccessSpreader<>::current()` and `AccessSpreader<>::cachedCurrent()`.
      
      Differential Revision: D27747508
      
      fbshipit-source-id: 0bc44938e810ec76ead50b6d4c1ade4aec9f8282
      4a6e1bea
    • Dan Melnic's avatar
      Add support for AsyncServerSocket bind to device · b310ff2e
      Dan Melnic authored
      Summary:
      Add support for AsyncServerSocket bind to device
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: danobi
      
      Differential Revision: D27778929
      
      fbshipit-source-id: fa051be2aa5c1b3df5e0c0f30adc3a58de7b7704
      b310ff2e
  10. 14 Apr, 2021 2 commits
  11. 13 Apr, 2021 6 commits
    • Rob Sherwood's avatar
      Mechanism to fire callbacks on new object construction · d31902b9
      Rob Sherwood authored
      Summary:
      Create a new class, ConstructorCallback, that when included as a member in
      another class (e.g., Foo) allows other functions to register and receive
      callbacks every time any of Foo's constructors are called.
      
      Main implementation concern is to be extremely lightweight (e.g., avoid locks)
      assuming that most code calling this will be performance optimized (both
      for CPU and mem).
      
      Implement as a static array of functions:
      
      1) Static array instead of dynamic (e.g., vector):
        vector occasionally resizes so avoid locking during resize
      2) Don't allow removing callback functions:
        simplify the calling of funcitons, again to avoid locks and races
      3) Use function callbacks instead of objects with an observer pattern
        (e.g., like AsyncSocket::LifecycleObserver) to ensure that there
        won't be races on shutdown.  Functions are static where classes can
        de-allocate at shutdown and since we don't allow un-registering the
        call back, it's not easy to remove the race for a class.
      
      Reviewed By: simpkins
      
      Differential Revision: D27056139
      
      fbshipit-source-id: 0846e0d55124cfde2e15acbe18e01ca5e327e7df
      d31902b9
    • Giuseppe Ottaviano's avatar
      Improve cpu id caching in DigestBuilder · 6f9321c4
      Giuseppe Ottaviano authored
      Summary:
      `DigestBuilder` caches the cpu id and invalidates it when it detects contention, but the critical section is small enough that it is possible for two thread to end up on a conflicting slot but not detect it for some time, causing cache-line pingponging in the meantime.
      
      Switch to `cachedCurrent()` instead, which uses the number of accesses to invalidate the cache, and is successfully adopted by other high-concurrency primitives.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27726518
      
      fbshipit-source-id: 05d70ad9f101df4a8797e44cc3cbe94cbd1cb7b8
      6f9321c4
    • Andrii Grynenko's avatar
      Patch unit tests to work with GCC · d5bf7f5a
      Andrii Grynenko authored
      Summary:
      GmockHelpersTest.cpp is the only one that fails to build with GCC after this change.
      Also only 5 tests are failing at this point.
      
      Reviewed By: pixelb
      
      Differential Revision: D27728248
      
      fbshipit-source-id: ded994f466347a8826ba90429a13237c21d3af5e
      d5bf7f5a
    • Nathan G Bronson's avatar
      avoid operator!= ambiguity in c++20 (#1544) · b471fe2a
      Nathan G Bronson authored
      Summary:
      F14 map `iterator` doesn't define `operator==` or `operator!=` to itself.
      Those member functions take `const_iterator` as the right-hand side,
      relying on the ability to convert implicitly from `iterator` to
      `const_iterator`. This interacts poorly with c++20's default equality
      operators, triggering clang's `-Wambiguous-reversed-operator`.
      
      This diff replaces the equality member functions with friends that use
      the same left-hand and right-hand types.  iterator != const_iterator
      will now compile by implicitly converting the left-hand-side and then
      calling `operator!=(const_iterator const&, const_iterator const&)`,
      rather than calling `iterator::operator!=(const_iterator const&)`.
      This resolves the ambiguity in c++20, and should work fine on earlier
      versions, although I have not tested it on anything except c++17.
      
      Pull Request resolved: https://github.com/facebook/folly/pull/1544
      
      Test Plan: does it build?
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27479086
      
      Pulled By: shixiao
      
      fbshipit-source-id: 0d42dbdc056cec58a36de3a816883736a761d0f6
      b471fe2a
    • Pranjal Raihan's avatar
      Refer to type names consistently · 692d08fb
      Pranjal Raihan authored
      Summary: Consistently use `Observer` and `Snapshot` like everywhere else in these files instead of `folly::Observer::{Observer,Snapshot}`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27685699
      
      fbshipit-source-id: 7eca35b9d113d8d9cd8ca631be2ad54c827431ea
      692d08fb
    • Chad Austin's avatar
      remove unused LockFreeRingBuffer functionality · 89383c3a
      Chad Austin authored
      Summary:
      Nothing uses the skipFraction in LockFreeRingBuffer::currentTail, and
      floating point math for discrete fractions can be hard to reason
      about, so remove this dead code.
      
      Differential Revision: D27717906
      
      fbshipit-source-id: b25e2bea25ab66c59e8c76a80d75140db474c46d
      89383c3a