1. 19 Jun, 2020 2 commits
    • Mikhail Shatalov's avatar
      Avoid shared_ptr copy in EventBaseLocal::getOrCreate · 28fd04bd
      Mikhail Shatalov authored
      Summary: `folly::get_default()` returns a copy of shared_ptr that gets immediately discarded. The change avoids that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D22119215
      
      fbshipit-source-id: 36aab580d7042d19b6b076cad20586697fbfa5e3
      28fd04bd
    • Matthieu Martin's avatar
      async::promiseWait · d0b905b1
      Matthieu Martin authored
      Summary:
      Provide an Async wrapper for fibers::await, which blocks current task until promise is fulfilled.
      This isn't a build block that is used in very common scenario, so prefered to put it in its own file.
      
      Differential Revision: D22135318
      
      fbshipit-source-id: 753dbefc4ac9a907f5b1f656f70291c88187b5e8
      d0b905b1
  2. 18 Jun, 2020 3 commits
    • Zhengxu Chen's avatar
      Make RequestContext rootid value atomic in RequestContext::StaticContext. · 72e91069
      Zhengxu Chen authored
      Summary:
      Currently RequestContext::getRootidsFromAllThreads() can access StaticContext root ids concurrently with RequestContext::setRequestContext() without synchronization guards, which is not safe cross other platforms than x64 and also causing TSAN warnings when used in server contexts.
      Therefore we can make it std::atomic and access it with relaxed order. This won't affect performance in major platform like x64 since the loads/stores instructions will be the same.
      Also as a side effect this prevents RequestContext::StaticContext from generating copy/move constructor, so we remove an extra copy of root id in StaticContext in setRequestContext path.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D22083558
      
      fbshipit-source-id: ed70e394f1172b07ba00c15f05a370f84265785c
      72e91069
    • darionyaphet's avatar
      Fix typo about Executor (#1386) · 7e9c1601
      darionyaphet authored
      Summary: Pull Request resolved: https://github.com/facebook/folly/pull/1386
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21992975
      
      Pulled By: Orvid
      
      fbshipit-source-id: 7d52e3e9f8db899079263ef15e9f1bbfbedadc44
      7e9c1601
    • Michael Park's avatar
      Remove `TIMED_SYNCHRONIZED(_CONST)` and replace its usage with `wlock`/`rlock` functions. · e2886185
      Michael Park authored
      Summary: This macro has been deprecated and given that there are not that many uses, it seems relatively simple to remove it entirely.
      
      Reviewed By: yfeldblum, aary
      
      Differential Revision: D16904736
      
      fbshipit-source-id: 56daffd480c586be2a5636b3ce20c6fe1d5ea018
      e2886185
  3. 17 Jun, 2020 8 commits
    • Andrii Grynenko's avatar
      Add a method to disable shutdown timer · 266c62de
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D22071829
      
      fbshipit-source-id: c7f0e1bc5a4257731bafee09144c33c9fb474e10
      266c62de
    • Doug Rabson's avatar
      Remove unused type alias · 29adc304
      Doug Rabson authored
      Summary: The ValueType alias in the multiplex function is not used and caused a build failure when I tried to use it, possibly because we have some extra warnings enabled in our code.
      
      Reviewed By: lewissbaker
      
      Differential Revision: D21685780
      
      fbshipit-source-id: 3235c6444a623d5f484f0849679b1497f9456fa9
      29adc304
    • Lukas Piatkowski's avatar
      cargo_from_buck: add the patch section to Cargo workspace and allow workspace... · f6d0e220
      Lukas Piatkowski authored
      cargo_from_buck: add the patch section to Cargo workspace and allow workspace appending to existing manifest
      
      Summary:
      Two changes here:
      1. The `[patch.crates-io]` section of `third-party/rust/Cargo.toml` is being now copied over to workspaces generated by autocargo for OSS and in the runtime generated Cargo.toml file for cargo-fbcode builds. Without that some projects could be buildable in Buck internally, but not externally on GitHub due to missing patches.
      2. If a `[workspace]` Cargo.toml file is being generated and there is already a generated Cargo.toml file in the same directory then instead of overriding that file the `[workspace]` (and `[patch]`) sections are appended to that Cargo.toml file.
      
      Reviewed By: farnz
      
      Differential Revision: D22023144
      
      fbshipit-source-id: dec54491c36c2ee0ab29eefb722b3eceaef6ffe1
      f6d0e220
    • Mark Santaniello's avatar
      Default constructible folly::SysArenaAllocator · f0471228
      Mark Santaniello authored
      Summary:
      Adjust `CxxAllocatorAdaptor` such that it becomes default constructible.  This makes `SysArenaAllocator` default constructible too, which makes it much easier to use.
      
      A default-constructed `SysArenaAllocator` is not useful at all.  Any attempt to allocate just throws `std::bad_alloc`.  But it makes it possible to at least compile code like this:
      
      ```
      using MyAlloc = SysArenaAllocator<char>;
      struct Foo {
         Foo() = default;  // BOOM
         Foo(MyAlloc &a) : v(a) {};
         vector<int, MyAlloc> v;
      }
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21967640
      
      fbshipit-source-id: 5b74c6db14d75364b374cad71d0069b17769e5d6
      f0471228
    • Sumeet Khullar's avatar
      Revert D22027490: Specialize F14Table default constructor to avoid reserve() instantiation · d72d1b57
      Sumeet Khullar authored
      Differential Revision:
      D22027490
      
      Original commit changeset: 964d9fa19ca9
      
      fbshipit-source-id: 2c92ea47c64450cb031be4a6df3c3be4901500b7
      d72d1b57
    • Lewis Baker's avatar
      Only run Futex.clock_source test on Linux platforms · 61a434e9
      Lewis Baker authored
      Summary:
      On Linux platforms the folly::futexWait() functions are implemented using the
      futex() syscall, which requires passing a timeout parameter that specifies a
      an expiry time either in CLOCK_REALTIME or CLOCK_MONOTONIC.
      
      The futexWait() implementation currently assumes that the std::chrono::system_clock
      and std::chrono::steady_clock implementations are thin wrappers over these
      clock types and that we can directly convert the .time_since_epoch() values to
      a timespec value that we can pass to the futex() syscall.
      
      The Futex.clock_source test is checking this assumption about the implementation
      of the std::chrono clocks.
      
      Unfortunately, this assumption does not hold on recent libc++ implementations for
      Apple platforms, which now uses the CLOCK_UPTIME_RAW clock for the
      std::chrono::steady_clock implementation and so this test was failing on the
      Mac platforms.
      
      However, since we aren't actually relying on this assumption on platforms other than
      Linux, we can just disable this test for non-Linux platforms.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D22075639
      
      fbshipit-source-id: 229995ba7c01b52d1949ef5942774920876d0994
      61a434e9
    • Andrii Grynenko's avatar
      Stop using atomic_thread_fence in SaturatingSemaphore · b77dcf05
      Andrii Grynenko authored
      Summary: Thread fences are not supported by TSAN
      
      Reviewed By: yfeldblum
      
      Differential Revision: D22056483
      
      fbshipit-source-id: dfe5b462656605f2e659302125e248b287037629
      b77dcf05
    • Matt Ma's avatar
      Back out "Resubmit: Allow using different symbolizer mode in signal handler." · 23cadde7
      Matt Ma authored
      Summary:
      Original commit changeset: 25d4049019e4
      
      Base diff broke fboss build (using fbcode_builder) with the following error:
      
      /tmp/fbcode_builder_getdeps-ZrootZfboss2.gitZbuildZfbcode_builder-root/installed/folly/include/folly/init/Init.h:22:10: fatal error: folly/experimental/symbolizer/SymbolizerMode.h: No such file or directory
       #include <folly/experimental/symbolizer/SymbolizerMode.h>
      
      Revert this first to unblock fboss while I am investigating the failure.
      
      Reviewed By: shri-khare
      
      Differential Revision: D22077183
      
      fbshipit-source-id: 8bafc0518df82c61922104b7d59ef5ee20fdd572
      23cadde7
  4. 16 Jun, 2020 2 commits
  5. 15 Jun, 2020 8 commits
    • Matt Ma's avatar
      Resubmit: Allow using different symbolizer mode in signal handler. · 792d3247
      Matt Ma authored
      Summary: Fixed the missed initialization in InitOptions.
      
      Reviewed By: luciang
      
      Differential Revision: D22023637
      
      fbshipit-source-id: 25d4049019e42708c98e5b589ed4838e2870d39b
      792d3247
    • Giuseppe Ottaviano's avatar
      Specialize F14Table default constructor to avoid reserve() instantiation · 8d4e8ede
      Giuseppe Ottaviano authored
      Summary: F14 class member fields are often in headers, and often the default constructor is implicit. The current implementation unconditionally instantiates `reserve()`, which has non-negligible cost. By specializing the default constructor we can avoid that in the common case.
      
      Reviewed By: philippv, luciang
      
      Differential Revision: D22027490
      
      fbshipit-source-id: 964d9fa19ca92797bcb209e09959dc4706af39d4
      8d4e8ede
    • Pranav Thulasiram Bhat's avatar
      Deduction guide for Async · 248b90f6
      Pranav Thulasiram Bhat authored
      Summary:
      This diff implements a deduction guide for explicitly creating and returning Async objects in lambdas and functions with deduced return types.
      
      This saves the user from having to specify often lengthy return types when annotating such functions.
      
      Reviewed By: A5he
      
      Differential Revision: D21770141
      
      fbshipit-source-id: f80898ef6eeadee7c5a7168aaae4031e224a0935
      248b90f6
    • Pranav Thulasiram Bhat's avatar
      Async traits · 641a5030
      Pranav Thulasiram Bhat authored
      Summary: This diff implements traits to aid in the development of templated functions accepting annotated functions.
      
      Reviewed By: yfeldblum, A5he
      
      Differential Revision: D21770066
      
      fbshipit-source-id: 40ae340aeeb484c4f9769c13b5c9a92a97723801
      641a5030
    • Pranav Thulasiram Bhat's avatar
      Awaiting Coro · d1f59dd5
      Pranav Thulasiram Bhat authored
      Summary:
      This diff implements `coro_wait`, an annotated helper to block on the execution of a coroutine.
      
      The goal here is to provide an easy way to migrate from fibers to coroutines.
      
      Reviewed By: A5he
      
      Differential Revision: D21978610
      
      fbshipit-source-id: d59a222978d9db2963656312e71c7dcb2b9a11e9
      d1f59dd5
    • Pranav Thulasiram Bhat's avatar
      Awaiting futures · a7d768ee
      Pranav Thulasiram Bhat authored
      Summary:
      This diff adds `future_wait`, an annotated helper to run blocking `get` operations on futures.
      
      `future_wait` will help annotate functions (and their caller stack) that block on futures.
      
      For semifutures, deferred work is performed on fiber-main context, so there is no concern of bleeding fibers.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21965552
      
      fbshipit-source-id: 79941c3b73c67d63d83dcdc778c62a0fc9051de3
      a7d768ee
    • Chad Austin's avatar
      re-enable lz4 compression for rocksdb on macOS and Linux · 3b5ce36b
      Chad Austin authored
      Summary:
      I think LZ4 was disabled accidentally in our rocksdb getdeps build in
      D21319896. Enable it again on macOS and Linux, because otherwise this
      breaks people with EdenFS mounts containing LZ4-compressed proxy
      hashes.
      
      Reviewed By: xavierd
      
      Differential Revision: D21990356
      
      fbshipit-source-id: b9166c2992ae51f09de3fa9a4f114143aa008f43
      3b5ce36b
    • Lewis Baker's avatar
      Add folly::tag_invoke · 66dc0a6f
      Lewis Baker authored
      Summary:
      Adds a helper utility called 'tag_invoke' for defining CPOs that dispatch to a call to an overload of the ADL-name 'tag_invoke()' that takes the CPO as the first argument instead of to a CPO-specific ADL-name.
      
      This makes it possible to build generic adapters, such as type-erasing adapters, that can forward through calls to all CPOs through to an underlying object.
      
      Adds FOLLY_DECLVAL(T) helper macro used in the implementation of some of the traits.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D17867173
      
      fbshipit-source-id: fadae6ec97498008a5238036b7310a1e0ae119a2
      66dc0a6f
  6. 13 Jun, 2020 1 commit
    • Nathan Bronson's avatar
      add explicit cast for narrowing on 32-bit platforms · 6bdbdb6f
      Nathan Bronson authored
      Summary:
      folly::Hash<Range<T>> uses SpookyHashV2::Hash64 (for integral
      T). On 32-bit platforms we need an explicit cast to avoid a narrowing
      warning when converting this to size_t.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: shixiao
      
      Differential Revision: D21491467
      
      fbshipit-source-id: 1cbd05553c61b8dccb664ec4478cfb0b049dc5b5
      6bdbdb6f
  7. 12 Jun, 2020 4 commits
    • Lucian Grijincu's avatar
      Revert D21918702: Allow using different symbolizer mode in signal handler. · 780050d9
      Lucian Grijincu authored
      Differential Revision:
      D21918702
      
      Original commit changeset: 3213e9536147
      
      fbshipit-source-id: 4e9394b2026f0d6d74e668c7c72b3612a42770ea
      780050d9
    • Giuseppe Ottaviano's avatar
      Outline most of TimedDrivableExecutor implementation · 4bbd587c
      Giuseppe Ottaviano authored
      Summary: This header is widely included (via `Future.h`) and instantiations of `UnboundedQueue`'s methods are expensive, so outline them (note that the template methods will only be instantiated if used, so that's fine).
      
      Reviewed By: philippv
      
      Differential Revision: D22014083
      
      fbshipit-source-id: b6a71c38c142917e9e0d86fbb64a88462382952a
      4bbd587c
    • Matt Ma's avatar
      Allow using different symbolizer mode in signal handler. · 8ae59d46
      Matt Ma authored
      Summary: This would allow us have better stack trace with inline functions in signal handler output.
      
      Reviewed By: luciang
      
      Differential Revision: D21918702
      
      fbshipit-source-id: 3213e9536147759a4e59f5b6f68d22d941d36c7f
      8ae59d46
    • Yedidya Feldblum's avatar
      Wrap _r_debug per platform · 55a91da8
      Yedidya Feldblum authored
      Summary: [Folly] Wrap `_r_debug` per platform, since the way to get it varies by platform.
      
      Reviewed By: ot, luciang
      
      Differential Revision: D22004737
      
      fbshipit-source-id: 6f6a6163c9709da0a5042b807cdd88fcdf2e57eb
      55a91da8
  8. 11 Jun, 2020 3 commits
    • Andrii Grynenko's avatar
      Stop using atomic_thread_fence in folly::Baton · f75211c0
      Andrii Grynenko authored
      Summary: Thread fences are not supported by TSAN
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21989519
      
      fbshipit-source-id: bb657c82a64abe025e8f4c030916c0cacc3c0b81
      f75211c0
    • Derek Brown's avatar
      Coroutines Method Typo (#1385) · 2c9b2aad
      Derek Brown authored
      Summary:
      The `collectSemiFuture` method doesn't exist.  Use `collectAllSemiFuture` instead.
      Pull Request resolved: https://github.com/facebook/folly/pull/1385
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21991532
      
      Pulled By: DerekTBrown
      
      fbshipit-source-id: 4ba3378fe34b7e6bb910f7045267fdbab87ebb14
      2c9b2aad
    • Yedidya Feldblum's avatar
      Back out "EventBase::getRecentSteadyTime" · 82dd413a
      Yedidya Feldblum authored
      Summary:
      Original commit changeset: 8eb472ce50bf
      
      This breaks time measurement to include measuring the wait preceding handler/callback invocation.
      
      Reviewed By: w-o-o
      
      Differential Revision: D21986042
      
      fbshipit-source-id: 42701b929878c3f56d736de5ca0417814c64fce1
      82dd413a
  9. 10 Jun, 2020 1 commit
    • Pranav Thulasiram Bhat's avatar
      Raise stackSizeMultiplier for debug builds · aa825c5c
      Pranav Thulasiram Bhat authored
      Summary:
      Debug builds can be prone to stack overflows if they are configurated to use the same stack sizes as prod builds.
      
      This diff effectively doubles the stack size for debug builds to provide more buffer against overflows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21913754
      
      fbshipit-source-id: bd32cc4dd9c79a50be178e5d6d30804a83e60ee4
      aa825c5c
  10. 09 Jun, 2020 8 commits
    • Mohamad Gebai's avatar
      Add strict versions of prevPowTwo() and nextPowTwo() · cb47018e
      Mohamad Gebai authored
      Summary: Returns the previous/next power of two that are strictly smaller/greater than the parameter.
      
      Reviewed By: yfeldblum, Gownta
      
      Differential Revision: D21920224
      
      fbshipit-source-id: be919063379e5b231cc69d743128fcaeb0ea9f39
      cb47018e
    • Yedidya Feldblum's avatar
      Cut FOR_EACH_KV · c94ebed8
      Yedidya Feldblum authored
      Summary: [Folly] Cut the FOR_EACH_KV macro, which may be replaced by a combination of range-for and structured bindings.
      
      Differential Revision: D21826182
      
      fbshipit-source-id: ce4712afd3d0d7806eb1fca8c97009da117f982e
      c94ebed8
    • Alexey Kuzmenko's avatar
      only allocate trimmedName on win32 · 58171cb5
      Alexey Kuzmenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D21921631
      
      fbshipit-source-id: e905d6d2a96775a8c3b328fb78c8d32897f634f6
      58171cb5
    • Junqi Wang's avatar
      Allow connect before bind · e31eb32a
      Junqi Wang authored
      Summary: connect will automatically bind the socket if the socket is not bound yet
      
      Reviewed By: yangchi
      
      Differential Revision: D21845740
      
      fbshipit-source-id: 27a5b44476dfc0b2ae5ff2f0a6c1bd4e976eadc9
      e31eb32a
    • Yedidya Feldblum's avatar
      Dead Code: TAsyncSocket · d11cbbc9
      Yedidya Feldblum authored
      Summary: [Thrift] Dead Code: `TAsyncSocket`.
      
      Reviewed By: vitaut
      
      Differential Revision: D20851837
      
      fbshipit-source-id: d4279fb1ab712f338d399220df26d56c4ab7076a
      d11cbbc9
    • Yedidya Feldblum's avatar
      EventBase::getRecentSteadyTime · da13f8bc
      Yedidya Feldblum authored
      Summary:
      [Folly] `EventBase::getRecentSteadyTime`, returning a recent `steady_clock::time_point` which is updated each pass through the event loop, but not for each ready event or function.
      
      Assuming everything in the loop is truly asynchronous, this permits callers to get a reasonably accurate approximation of the current time, but for many callers to blend or amortize the cost of getting that current time.
      
      May only be called from the running IO thread.
      
      Differential Revision: D21866783
      
      fbshipit-source-id: 8eb472ce50bf012616e567b29f6724c67ef8d41a
      da13f8bc
    • Yedidya Feldblum's avatar
      atomic_ref::compare_exchange_strong · 33403f55
      Yedidya Feldblum authored
      Summary: [Folly] `atomic_ref::compare_exchange_strong` and `atomic_ref::compare_exchange_weak`.
      
      Differential Revision: D21923944
      
      fbshipit-source-id: 55620473ea253782cc1dbb95baef38c96a9fbc70
      33403f55
    • Andrii Grynenko's avatar
      Crash process if folly::Singleton destruction is taking too long · e223d1a4
      Andrii Grynenko authored
      Summary: This provides a single mechanism to mitigate deadlocks in singleton destructors.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D21827615
      
      fbshipit-source-id: 090bad1a91238310e7814663193711df0f4d622a
      e223d1a4