1. 30 Apr, 2021 6 commits
    • Yedidya Feldblum's avatar
      shrink UniqueInstance ctor · 6ed9d378
      Yedidya Feldblum authored
      Summary:
      It is monomorphized but called rarely. Best to optimize for size.
      
      The `UniqueInstance` ctor is currently called in the constructor of each translation unit for each distinct instance of `SingletonThreadLocal`.
      
      `UniqueInstance` may be extended to more use-cases so it is worthwhile optimizing for size.
      
      Reviewed By: luciang
      
      Differential Revision: D27602938
      
      fbshipit-source-id: e4077830544516219485814ccc48805b7bb38e34
      6ed9d378
    • Vishal Sahu's avatar
      coro helper for FAIL() gtest macro · ebe2f775
      Vishal Sahu authored
      Summary: Need this to migrate CO_TEST using FAIL() fully on coroutines.
      
      Reviewed By: ispeters
      
      Differential Revision: D28099628
      
      fbshipit-source-id: c79658809210184d8895c3d1551e04b1baf88cae
      ebe2f775
    • Yedidya Feldblum's avatar
      tweak catch_exception taking fun-ptrs · 9552fbcd
      Yedidya Feldblum authored
      Summary: To reduce build size, avoid creating unnecessary functions. If the provided callable is already a function-pointer, the callee will already not be inlined.
      
      Differential Revision: D27984345
      
      fbshipit-source-id: a5a31330541338eb04e802bd9dafd99188af3ab9
      9552fbcd
    • Yedidya Feldblum's avatar
      work around gcc < 7 in UniqueInstance · f35ba916
      Yedidya Feldblum authored
      Summary: Some older versions of gcc cannot deduce the relevant types correctly, and they are still in use in corners of the codebase.
      
      Differential Revision: D28111907
      
      fbshipit-source-id: 0367cb102f450f0f601350308a5831c7fd68f775
      f35ba916
    • Yedidya Feldblum's avatar
      assume thread_local in SingletonThreadLocal · 3bab334d
      Yedidya Feldblum authored
      Differential Revision: D27582896
      
      fbshipit-source-id: e4228117ba02fe18bd6e8964640f293c963a8732
      3bab334d
    • REDMOND\agnel's avatar
      Fix several C++ warnings (#1565) · 3cdd3009
      REDMOND\agnel authored
      Summary:
      Fixes warnings about implicit type truncation. By making the conversions explicit, react-native-windows will be able to remove suppressions for several warnings required per SDL.
      
      Pull Request resolved: https://github.com/facebook/folly/pull/1565
      
      Reviewed By: igorsugak
      
      Differential Revision: D27964258
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: b13f8728ecda0b38c2fd661199d6551c5ff87993
      3cdd3009
  2. 29 Apr, 2021 4 commits
    • Yedidya Feldblum's avatar
      tweak FOLLY_LIKELY to accept complex expressions · 903990db
      Yedidya Feldblum authored
      Summary: Complex expressions involving certain tokens parse at preprocessor time as multiple preprocessor arguments. Quite awkward. The trick is to change the preprocessor macro to deal in variadic arguments.
      
      Reviewed By: ot, Orvid, luciang
      
      Differential Revision: D27986071
      
      fbshipit-source-id: a126fca260396418b14b7367e3e41ddeea78b7af
      903990db
    • Srivatsan Ramesh's avatar
      Change socket QueueMessage to a variant · cdf0badc
      Srivatsan Ramesh authored
      Summary: QueueMessage is now a variant of NewConnMessage and ErrorMessage
      
      Reviewed By: praihan
      
      Differential Revision: D27384053
      
      fbshipit-source-id: a92f514b56f31e879dc329984bf0a615ed339836
      cdf0badc
    • Yedidya Feldblum's avatar
      assume thread_local in Executor · 0b19393b
      Yedidya Feldblum authored
      Differential Revision: D27582476
      
      fbshipit-source-id: 376fecda16de8a4836f9ba5196701a9045799ce7
      0b19393b
    • Yedidya Feldblum's avatar
      make the template part of the unique-instance key · eeaef4a2
      Yedidya Feldblum authored
      Summary: So that it is possible to have both `Foo<K0, K1, X, Y>` and `Bar<K0, K1, A, B>` where both `Foo` and `Bar` use `UniqueInstance`.
      
      Differential Revision: D27600228
      
      fbshipit-source-id: a5d58726ea0009d7a45c0234f9cff723662a4604
      eeaef4a2
  3. 28 Apr, 2021 1 commit
    • Lee Howes's avatar
      Add terminateOnBlocking parameter to CPUThreadPoolExecutor · 2a80218d
      Lee Howes authored
      Summary: Parameterises CPUThreadPoolExecutor to allow us to construct one that prohibits blocking operations on its threads. The flag is stored as a thread local and applied using a scoped guard.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27893465
      
      fbshipit-source-id: 71af1c0b7c23752f499712f498b6abb58a345979
      2a80218d
  4. 27 Apr, 2021 3 commits
    • Philip Pronin's avatar
      expose AsyncIOOp::getIocb · 2798cd1b
      Philip Pronin authored
      Summary:
      Similarly to `IoUringOp::getSqe()`, expose underlying submission data
      structure.  The end goal is to perform certain introspection in client code to
      report aggregated stats (number of IO, total size of IO, ...).
      
      Reviewed By: ot
      
      Differential Revision: D28022188
      
      fbshipit-source-id: edc51420ed901f0a0d9b5b1338308ad680371298
      2798cd1b
    • Alex Eckert's avatar
      Add api to check if AsyncPipe is still connected · 9eff0218
      Alex Eckert authored
      Summary:
      I have a use case where I would like to check if the
      AsyncPipe is still active without pumping something in to
      write(). Could set up an onClosed callback, but this would introduce
      more complexity.
      
      This adds a function to determine if the queue inside the AsyncPipe
      still exists.
      
      Reviewed By: iahs
      
      Differential Revision: D28015007
      
      fbshipit-source-id: 1ba37466218abd2f42eab1d8ea5677c3945e31f5
      9eff0218
    • Alan Frindell's avatar
      Optional peerAddress argument for sockets created with fd · ab5d1a0b
      Alan Frindell authored
      Summary: For TCP sockets, it may not be possible to query the peer address from the fd if the endpoint is no longer connected (closed with reset).  In most server cases, the peer address is known when the connection is accepted, so it can be prepopulated.
      
      Reviewed By: mjoras
      
      Differential Revision: D27985942
      
      fbshipit-source-id: 630098ac00930b978fe8a9cad1894834c44d4d93
      ab5d1a0b
  5. 26 Apr, 2021 3 commits
    • Igor Sugak's avatar
      fix -Wsuggest-override and -Wsuggest-destructor-override · e5cb25c2
      Igor Sugak authored
      Summary:
      ```
      folly/executors/InlineExecutor.h:29:11: error: '~InlineLikeExecutor' overrides a destructor but is not marked 'override' [-Werror,-Wsuggest-destructor-override]
        virtual ~InlineLikeExecutor() {}
                ^
      folly/Executor.h:57:11: note: overridden virtual function is here
        virtual ~Executor() {}
                ^
      In file included from tupperware/agent/system/Mounts.cpp:18:
      In file included from folly/futures/Future.h:36:
      In file included from folly/fibers/Baton.h:297:
      In file included from folly/fibers/Baton-inl.h:19:
      folly/fibers/FiberManagerInternal.h:588:10: error: 'timeoutExpired' overrides a member function but is not marked 'override' [-Werror,-Wsuggest-override]
          void timeoutExpired() noexcept { run(); }
               ^
      folly/io/async/HHWheelTimer.h:95:18: note: overridden virtual function is here
          virtual void timeoutExpired() noexcept = 0;
                       ^
      In file included from tupperware/agent/system/Mounts.cpp:18:
      In file included from folly/futures/Future.h:36:
      In file included from folly/fibers/Baton.h:297:
      In file included from folly/fibers/Baton-inl.h:19:
      folly/fibers/FiberManagerInternal.h:589:10: error: 'callbackCanceled' overrides a member function but is not marked 'override' [-Werror,-Wsuggest-override]
          void callbackCanceled() noexcept {}
               ^
      folly/io/async/HHWheelTimer.h:100:18: note: overridden virtual function is here
          virtual void callbackCanceled() noexcept { timeoutExpired(); }
                       ^
      3 errors generated.
      ```
      
      Reviewed By: simpkins
      
      Differential Revision: D27988235
      
      fbshipit-source-id: 799484c52f89fa20f647ff0801b8d136b657b395
      e5cb25c2
    • Lee Howes's avatar
      Add a termination tag to the blocking context · 4794b98c
      Lee Howes authored
      Summary:
      Add a termination tag that carries through the blocking context chain. This flag notifies logging operations that they may go as far as to terminate the process if blocking operations are detected.
      
      The flags carry through the blocking scopes so the termination flag will stay present while we enable and disable blocking - it would be sticky for a given thread once set.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D27869075
      
      fbshipit-source-id: 27014a3e6c9b28c0f433949a576bb6116e7c06c0
      4794b98c
    • Yedidya Feldblum's avatar
      use only public gmock interface in transport/socket lifecycle observer · da606bda
      Yedidya Feldblum authored
      Summary: Internals are not portable between versions or across platforms.
      
      Reviewed By: Orvid
      
      Differential Revision: D27990286
      
      fbshipit-source-id: b70d8d3f67a1e5262efa842f70817e3ae3972339
      da606bda
  6. 25 Apr, 2021 6 commits
    • Yedidya Feldblum's avatar
      prefer thread_local over FOLLY_TLS in F14 · 92d8ef30
      Yedidya Feldblum authored
      Reviewed By: Orvid
      
      Differential Revision: D27582035
      
      fbshipit-source-id: 0f0c35adca1c44dcd0ef88f2443f769d7991e6aa
      92d8ef30
    • Yedidya Feldblum's avatar
      move thread-id function bodies to source · f68ed33b
      Yedidya Feldblum authored
      Summary: Add a source file for the function bodies of `getThreadID` and `getOSThreadID`.
      
      Differential Revision: D27698463
      
      fbshipit-source-id: 255961954b1be07e59b19ef3006dcd6149795861
      f68ed33b
    • Yedidya Feldblum's avatar
      add missing include of <algorithm> · dead70cc
      Yedidya Feldblum authored
      Summary: `folly/stats/StreamingStats.h` uses `std::min` and `std::max` so must `#include <algorithm>`.
      
      Reviewed By: Orvid
      
      Differential Revision: D27986054
      
      fbshipit-source-id: 1c1160101e1ebb4e0b1a16d3d97fd2931db9eeb0
      dead70cc
    • Yedidya Feldblum's avatar
      StaticSingletonManager type-erased create · 8ed2344b
      Yedidya Feldblum authored
      Summary: `StaticSingletonManager::create<T, Tag>` is larger than necessary, which may not be desirable when using many tags with the same type. Permit call-sites to use static data to shrink the functions.
      
      Reviewed By: aary
      
      Differential Revision: D27863037
      
      fbshipit-source-id: 9f6ced3e7d7a85b78e671f69d7a475ab4de5eea0
      8ed2344b
    • Yedidya Feldblum's avatar
      fix the deprecation suppression for gcc in the exception_wrapper test · 6fcad841
      Yedidya Feldblum authored
      Summary: By suppressing `-Wdeprecated-declarations` v.s. `-Wdeprecated`, which latter works only under clang.
      
      Reviewed By: Orvid
      
      Differential Revision: D27987616
      
      fbshipit-source-id: 4bf2a225a65d8ac7c7555123343e9536759fcfcc
      6fcad841
    • Igor Sugak's avatar
      fix a couple of -Wunused-value violations · e6e7080e
      Igor Sugak authored
      Summary:
      Reported by clang-12:
      ```
      folly/test/SynchronizedTestLib-inl.h:587:7: error: expression result unused [-Werror,-Wunused-value]
            SYNCHRONIZED_DUAL(lv, v, lm, m) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      folly/Synchronized.h:1819:5: note: expanded from macro 'SYNCHRONIZED_DUAL'
          ::folly::detail::SYNCHRONIZED_macro_is_deprecated{};                       \
          ^                                                ~~
      ```
      
      Reviewed By: chadaustin
      
      Differential Revision: D27954777
      
      fbshipit-source-id: bd1dba5ebf563b34b496457b980568ea1c978442
      e6e7080e
  7. 24 Apr, 2021 9 commits
    • Yedidya Feldblum's avatar
      prefer thread_local over FOLLY_TLS in SharedMutex · 5d1b9736
      Yedidya Feldblum authored
      Reviewed By: Orvid
      
      Differential Revision: D27559485
      
      fbshipit-source-id: be2db59ef6d9b4cf178216a4b8851e27e7ecef93
      5d1b9736
    • Yedidya Feldblum's avatar
      use INSTANTIATE_TEST_SUITE_P over INSTANTIATE_TEST_CASE_P · 9ce8cd46
      Yedidya Feldblum authored
      Summary: The facility was renamed in gtest.
      
      Reviewed By: praihan
      
      Differential Revision: D27985919
      
      fbshipit-source-id: d35795d7bfb985767b5e6c28141dac47a4b9f0ce
      9ce8cd46
    • Yedidya Feldblum's avatar
      prefer fmt for formatting in small-locks bench · 76f8268c
      Yedidya Feldblum authored
      Summary: No risk of mismatched types.
      
      Reviewed By: vitaut
      
      Differential Revision: D27933275
      
      fbshipit-source-id: 41bf921748299ead7388bb0dc4197eb4390aa007
      76f8268c
    • Yedidya Feldblum's avatar
      cut google-perftools spin-lock from small-locks bench · 2e5f2bae
      Yedidya Feldblum authored
      Summary: To avoid the extra and unusual dependency in this particular case.
      
      Differential Revision: D27933052
      
      fbshipit-source-id: aeda0b7b5916c3fe05581f9880472d194412c461
      2e5f2bae
    • Yedidya Feldblum's avatar
      fix memory order in hazptr example · db330e7c
      Yedidya Feldblum authored
      Summary: The release order is not valid for compare-exchange-failure-load.
      
      Reviewed By: magedm
      
      Differential Revision: D27932613
      
      fbshipit-source-id: 689929ecdef8feaec268dc2cd350ce001103ee75
      db330e7c
    • Yedidya Feldblum's avatar
      cut posix semaphore polyfill · 31fbd123
      Yedidya Feldblum authored
      Summary: Prefer not to have polyfills. The class `NativeSemaphore` replaces this polyfill.
      
      Reviewed By: Orvid
      
      Differential Revision: D27971239
      
      fbshipit-source-id: 39bd8b2d9be895a947faee4d522420535378fdc3
      31fbd123
    • Lee Howes's avatar
      Rename ForbidTag to TrackTag to be more consistent with its implementation · 2a4fe7ca
      Lee Howes authored
      Summary: Rename ForbidTag to TrackTag as a counter to PermitTag. ForbidTag did not capture the idea that in practice we simply log blocking operations. TrackTag allows for that and opens scope for a more aggressive form of tracking on top.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D27914911
      
      fbshipit-source-id: d56132b7e389825167503934b7af08f9a3ccf1fe
      2a4fe7ca
    • 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
  8. 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
  9. 22 Apr, 2021 4 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