1. 11 Feb, 2021 2 commits
    • Yedidya Feldblum's avatar
      let EventBaseLocal::getOrCreateFn function return value · 1486429b
      Yedidya Feldblum authored
      Summary:
      Let the function passed to `EventBaseLocal::getOrCreateFn` directly return the value to be stored, rather than allocating it and returning a pointer.
      
      Details of its storage should be internal to `EventBaseLocal` and should not leak out into the creator functions.
      
      Differential Revision: D26246341
      
      fbshipit-source-id: d72a62998985e42ef517eede3654324dc9f48709
      1486429b
    • Victor Zverovich's avatar
      Replace folly::writeTo with fmt::print · 029aff28
      Victor Zverovich authored
      Summary:
      Remove `folly::writeTo` which is untested and virtually unused, replacing
      ```
      folly::writeTo(
          stdout,
          folly::format(...));
      ```
      with
      ```
      fmt::print(...);
      ```
      for better compatibility with C++20 `std::format`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26326405
      
      fbshipit-source-id: 598ec5d7906b2d36b20aa63f410a0c2621bc62fa
      029aff28
  2. 10 Feb, 2021 3 commits
    • Jakob lövhall's avatar
      docs/Synchronized.md spelling (#1523) · af3fd11e
      Jakob lövhall authored
      Summary:
      removed double of word 'lock'
      
      Pull Request resolved: https://github.com/facebook/folly/pull/1523
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26367154
      
      Pulled By: Orvid
      
      fbshipit-source-id: 586647d28b9ad002ee975450426d2da967dc638e
      af3fd11e
    • Shai Szulanski's avatar
      erased_unique_ptr · 49926b98
      Shai Szulanski authored
      Summary: There are lots of unnecessary uses of shared_ptr for type erasure where refcounting is not needed because it is trivial to convert to shared_ptr<void>, while it is more involved to make the equivalent unique_ptr. Adds a utility that hides the details to bring effort parity between the two pointer types.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26323443
      
      fbshipit-source-id: e33c5378f7df3105c7cb97d2622dca351b866035
      49926b98
    • Dan Melnic's avatar
      Add IoUringBackend support for openat, openat2, close, fallocate · 1e63a88c
      Dan Melnic authored
      Summary: Add IoUringBackend support for openat, openat2, close, fallocate #forcetdhashing
      
      Reviewed By: kevin-vigor
      
      Differential Revision: D26325604
      
      fbshipit-source-id: dbeea468ffbb324dc8c7afc1dbde1e451f72e06d
      1e63a88c
  3. 09 Feb, 2021 7 commits
    • Alfred Fuller's avatar
      Enable AllowAllParametersOfDeclarationOnNextLine in canary · e032bce6
      Alfred Fuller authored
      Summary:
      Making it consistent with other *OnNextLine rules.
      
      Also fixes really odd line breaks after the return type of some functions, for example:
      ```
      template <typename M>
      iterator
      insert_or_assign(const_iterator /*hint*/, key_type const& key, M&& obj) {
      ```
      becomes:
      ```
      template <typename M>
      iterator insert_or_assign(
          const_iterator /*hint*/, key_type const& key, M&& obj) {
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D25987579
      
      fbshipit-source-id: cc24ea3db1b256f5563fb051fbd572adfccf556a
      e032bce6
    • Xavier Deguillard's avatar
      ninja: upgrade and build from source on macOS · 89d16506
      Xavier Deguillard authored
      Summary:
      On macOS, ninja only provides prebuilt Intel binaries, not arm64 ones. Since we
      need to have a native arm64 ninja to be able to build binaries for the M1,
      let's compile it from scratch on macOS too. Compiling it takes less than 30s so
      it shouldn't add any notable cost to any builds.
      
      Reviewed By: genevievehelsel
      
      Differential Revision: D26322029
      
      fbshipit-source-id: 1bbeeac2a3f0ba07c477a2b33f8878a91ccaec0e
      89d16506
    • Shai Szulanski's avatar
      CancellationToken::merge() · 5d1f7e5f
      Shai Szulanski authored
      Summary:
      Combining CancellationTokens is a common pattern in user code, which requires the user to manage a CancellationSource and attach a callback per token to be merged:
      ```
          folly::CancellationSource source;
      
          folly::CancellationCallbacki cb1{
              std::move(token1), [&] { source.requestCancellation(); }};
          folly::CancellationCallback cb2{
              std::move(token2), [&] { source.requestCancellation(); }};
          ...
      
          co_await co_withCancellation(source.getToken(), ...);
      ```
      
      This diff adds the functionality to folly:
      ```
          co_await co_withCancellation(folly::CancellationToken::merge(token1, token2, ...), ...);
      ```
      
      This diff subclasses CancellationState for simplicity. If the extra vtable ptr is a concern, we can instead template CancellationState to combine them, but that would come with a compilation speed penalty.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26277772
      
      fbshipit-source-id: 169f65b4cf8f7f10f2800fb7797bb09379ecc239
      5d1f7e5f
    • Yedidya Feldblum's avatar
      fix folly/lang/ExceptionTest.cpp under libc++ · de428b41
      Yedidya Feldblum authored
      Summary: Fix the uncaught-exception termination message expectations in `folly/lang/ExceptionTest.cpp` under libc++.
      
      Reviewed By: markisaa
      
      Differential Revision: D26328622
      
      fbshipit-source-id: 2e2f9fce93c65556508d99d1f7b80f0971f35c0c
      de428b41
    • Dan Melnic's avatar
      Lower min capacity so the test succeeds when ulimit -l has a lower value · 94e80675
      Dan Melnic authored
      Summary: Lower min capacity so the test succeeds when ulimit -l has a lower value
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26321362
      
      fbshipit-source-id: 9d2c41fbbc190f46a6174c3f847943e13f5bea6c
      94e80675
    • Victor Zverovich's avatar
      Remove deprecated formatting functions · e69ea26b
      Victor Zverovich authored
      Summary: Removed deprecated folly format APIs.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26317507
      
      fbshipit-source-id: 67f42d059088946a34e77c944befa4dcb24d8673
      e69ea26b
    • Xavier Deguillard's avatar
      openssl: update to 1.1.1i · 74c66ce2
      Xavier Deguillard authored
      Summary:
      I've been trying to get EdenFS to compile on an M1 mac, and openssl only
      support these starting with 1.1.1i. From their changelog:
      
          *) Add support for Apple Silicon M1 Macs with the darwin64-arm64-cc target.
           [Stuart Carnie]
      
      Let's start by upgrading openssl.
      
      Reviewed By: fanzeyi
      
      Differential Revision: D26318433
      
      fbshipit-source-id: dfe1a06ee7061dfcd026b0347eb050155895ebd9
      74c66ce2
  4. 07 Feb, 2021 1 commit
    • Yedidya Feldblum's avatar
      reexport coroutine_handle · 56effb5a
      Yedidya Feldblum authored
      Summary: Reexport `coroutine_handle` from `folly/experimental/coro/Coroutine.h`, which wraps inclusion of `experimental/coroutine`.
      
      Differential Revision: D26227588
      
      fbshipit-source-id: 32cdb2b6d87e90065bf9f140716d63670c04db5f
      56effb5a
  5. 06 Feb, 2021 3 commits
  6. 05 Feb, 2021 9 commits
    • Mikhail Shatalov's avatar
      DCHECK for nullptrs in EventBaseLocal setter and factory getter · f310f66e
      Mikhail Shatalov authored
      Summary: `getOrCreateFn()` is prone to undefined behavior as it returns `nullptr` reference if factory function returns a `nullptr` or empty `std::shared_ptr<T>`, or if `emplace(evb, nullptr)` is called. This diff adds `DCHECK`s to enforce non-nulls. Note that `getOrCreate()` is not affected as it uses `std::make_shared` under the hood that is guaranteed to have a new object constructed.
      
      Differential Revision: D26246552
      
      fbshipit-source-id: b7bc7164841b70fc0889c782438bf96a61857bbd
      f310f66e
    • Xavier Deguillard's avatar
      preprocessor: increase max arguments of FOLLY_PP_FOR_EACH · e237e691
      Xavier Deguillard authored
      Summary: EdenFS has a use-case for this macro but with 10+ arguments. Raise the maximum number of arguments from 7 to 15 to permit this.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26268587
      
      fbshipit-source-id: be0b0579d854a93dc2983706a253370fe05905df
      e237e691
    • Dan Melnic's avatar
      Add support for io_uring min capacity · 737e6144
      Dan Melnic authored
      Summary: Add support for io_uring min capacity. This should allow us to create io_uring instances even memory is fragmented and the kernel cannot allocate contiguous physical memory for capacity CQ entries (SQ is usually much smaller).
      
      Reviewed By: kevin-vigor
      
      Differential Revision: D26252442
      
      fbshipit-source-id: f4e3bd4f00d21321b77d4e1452400689dbca1073
      737e6144
    • Yedidya Feldblum's avatar
      XLOG_FIRST_N · 7e4c8713
      Yedidya Feldblum authored
      Summary: Add `XLOG_FIRST_N` log function.
      
      Reviewed By: simpkins
      
      Differential Revision: D26184283
      
      fbshipit-source-id: 23081f759897bbf7949ce603f8e5edb29869b40d
      7e4c8713
    • Dan Melnic's avatar
      Remove FOLLY_UNLIKELY from IoUringBackend::eb_event_base_loop · 4eaba962
      Dan Melnic authored
      Summary: Remove FOLLY_UNLIKELY from IoUringBackend::eb_event_base_loop
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26272113
      
      fbshipit-source-id: de280347908e5448cc97ffc1e1be3100cf6cd4b1
      4eaba962
    • Yedidya Feldblum's avatar
      reexport suspend_always, suspend_never · 317e8753
      Yedidya Feldblum authored
      Summary: Reexport `suspend_always`, `suspend_never` from `folly/experimental/coro/Coroutine.h`, which wraps inclusion of `experimental/coroutine`.
      
      Differential Revision: D26215623
      
      fbshipit-source-id: 5dbe5dba67e0c4dcb5a54b00753937c39833d3a7
      317e8753
    • Yedidya Feldblum's avatar
      rely on C++17 syntactic copy elision in DelayedInit · cc15e578
      Yedidya Feldblum authored
      Summary: Rely on C++17 syntactic copy elision in `DelayedInit` to simplify and write `try_emplace` in terms of `try_emplace_with`.
      
      Reviewed By: praihan
      
      Differential Revision: D26260351
      
      fbshipit-source-id: 590fdfed55ee325ed8a8ae4fa68c1db0bebf1545
      cc15e578
    • Yedidya Feldblum's avatar
      move and revise fmt/compile.h portability · b93c8daa
      Yedidya Feldblum authored
      Summary: Move the libfmt portability code into `folly/portability/` and revise it only to mutate folly's namespace.
      
      Reviewed By: Orvid
      
      Differential Revision: D26182824
      
      fbshipit-source-id: e0b72f523dfeac7ff7799ff2104a1146032dfbf3
      b93c8daa
    • Yedidya Feldblum's avatar
      let coro headers always be buildable · 4ab51101
      Yedidya Feldblum authored
      Summary: Let folly coro headers always be buildable whether or not coroutines are available. They may just be empty apart from transitive includes.
      
      Reviewed By: iahs
      
      Differential Revision: D26191449
      
      fbshipit-source-id: 5865ce5edb13f97624b9f60c45c045886fdf0bfb
      4ab51101
  7. 04 Feb, 2021 4 commits
    • Misha Shneerson's avatar
      python event loop consumes one task at a time from C++ notification queue · f133aef5
      Misha Shneerson authored
      Summary:
      Currently, when C++ threads communicate with python's event loop, they place
      the items on the queue, notify the event loop, and when even loops starts
      running, they would consume all items from this queue at once.
      The downside of this approach is that we are unable to deprioritize the
      upstream tasks to yield to internal python tasks. However, such ability to yield
      is fundamental to how Thrift approaches load shedding under overload.
      In this diff we change the approach to take only a single item from the queue at a
      time. Notice that if queue is not emptied, the consumer will notify the event loop to
      consume from this queue on the next iteration of the loop.
      
      Reviewed By: zhxchen17
      
      Differential Revision: D26228933
      
      fbshipit-source-id: 827d21df12b65d518109151cb150cd45e513da57
      f133aef5
    • Yedidya Feldblum's avatar
      tweaks to DelayedInit · d8ecccad
      Yedidya Feldblum authored
      Summary:
      Tweaks to `folly::DelayedInit`:
      * No potential for ambiguity in placement-new by using `::new` and casting the address to `void*`.
      * Helper functions `slot` and `store` simplify `try_emplace_with` and `try_emplace`.
      * `try_emplace_with` and `try_emplace` are no longer `const`-qualified, removing the need for `mutable` qualifiers.
      
      The emplacement members should not be `const`-qualified since they are not semantically non-modifying. The `const` qualifier signals semantic non-modification. While it is the case that there are customs around `const` qualifiers and concurrency, these customs are not the core meaning of `const`.
      
      Reviewed By: praihan
      
      Differential Revision: D25919779
      
      fbshipit-source-id: 95e5c4b4abf5285fbb00dddda1192998baf6ee59
      d8ecccad
    • Maged Michael's avatar
      ConcurrentHashMap: Catch use-after-destruction user bugs · b9cc811a
      Maged Michael authored
      Summary:
      The change aims to make it easier to catch user bugs of using the map during or after its destruction in optimized modes without ASAN.
      
      The changes are:
      - Clear the buckets_ and chunks_ pointers in the corresponding destructors.
      - Add DCHECK-s of buckets_ (or chunks_) in other member functions when non-null values are expected.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D26232735
      
      fbshipit-source-id: 14f0c11e10997773efb78c7275db99932dd19703
      b9cc811a
    • Nick Cooper's avatar
      RFC: Add direct support for relative benchmarking to the folly/Benchmark library. · 88ee330d
      Nick Cooper authored
      Summary:
      When modifying code that lacks alternative variations, there is only a 'HEAD' benchmark - so it can be useful to keep a version of these results for latter printing in the format of a relative benchmark.
      
      Add a new flag to simplify this use-case,
      --bm_relative_to: A flag taking the path to a JSON-verbose formatted dump, which will be used when printing (in non-JSON-mode) to produce output relative to the provided prior dump.
      
      Usage:
      - generate a JSON benchmark dump, use "--bm_json_verbose"
        $ your_benchmark_binary --benchmark --bm_json_verbose  old-json
      - run a benchmark printing a comparison to an old dump:
        $ your_benchmark_binary --benchmark --bm_relative_to old-json
      
      Note: You can also use bm_json_verbose and bm_relative_to at the same time, this will print relative results and update the JSON dump
      
      Reviewed By: luciang
      
      Differential Revision: D26214397
      
      fbshipit-source-id: 8134b74604b7bb5037934205e8eee5e3ffc27f15
      88ee330d
  8. 03 Feb, 2021 7 commits
    • Pranjal Raihan's avatar
      Use compact_once_flag in DelayedInit only if size can be reduced · d6d84f34
      Pranjal Raihan authored
      Summary: If `T` is greater than 4-byte aligned, then `compact_once_flag` brings no size improvements. We can use `once_flag` in these cases, which has a better mutex (`folly::SharedMutex` rather than `folly::MicroLock`).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26214262
      
      fbshipit-source-id: ea15376ea892df42cc9d3a6eac3da458fe0564a8
      d6d84f34
    • Orvid King's avatar
      Back out "Fix definition of folly::remainder for android" · eb1954c7
      Orvid King authored
      Summary: Original commit changeset: 149b780350bf
      
      Reviewed By: zaxy78
      
      Differential Revision: D26222637
      
      fbshipit-source-id: 29bc017be6619165cbd497c27c7843fd95e345b1
      eb1954c7
    • Andrew McFague's avatar
      folly: Backout changes to folly::DelayedInit and pass in a reference via folly::ConcurrentLazy · ca1e1523
      Andrew McFague authored
      Summary: This violates some expectations for how this function should be called, so explicitly allow this to be passed as a reference.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26215425
      
      fbshipit-source-id: 29cff0407ec10ab61970d32da083110d1b609fbb
      ca1e1523
    • Orvid King's avatar
      Fix definition of folly::remainder for android · 57c897d3
      Orvid King authored
      Summary: Non-uclibc android wasn't getting folly::remainder defined, so fall back to the STL in that case.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D26196078
      
      fbshipit-source-id: 149b780350bf4aaf6917ecce5e4718c91815c744
      57c897d3
    • Nick Cooper's avatar
      Add usage description to BenchmarkCompare · 8f284aae
      Nick Cooper authored
      Summary: As above.
      
      Reviewed By: luciang
      
      Differential Revision: D26213601
      
      fbshipit-source-id: e2eb639d0059e20cfd6828be669c62491e5ad9c4
      8f284aae
    • Yedidya Feldblum's avatar
      coro safe_point · 229a0c46
      Yedidya Feldblum authored
      Summary:
      Add a new concept of a safe-point to folly::Task<...> with implementation-defined semantics.
      
      Example usage:
      ```lang=c++
      Task<> co_something() {
        while (is_work_available()) {
          co_await co_safe_point;
          do_work();
        }
      }
      ```
      
      Previously, a coroutine function which would cancel itself if cancellation is requested would need to spell cancellation pass-through a bit less elegantly:
      ```lang=c++
      Task<> co_something() {
        while (is_work_available()) {
          auto token = co_await co_current_cancellation_token;
          if (token.isCancellationRequested()) {
            co_yield co_cancel;
          }
          do_work();
        }
      }
      ```
      
      Initial semantics include:
      * If cancellation has been requested, finish the coroutine with cancellation.
      * Otherwise, continue the coroutine.
      
      In the future, it may be wise to add additional behavior:
      * If the coroutine has been running for too long since its previous resumption, reschedule it.
      
      Reviewed By: aary
      
      Differential Revision: D25861265
      
      fbshipit-source-id: 6da896f1529d652bfe222cf3a70e9dbe19778510
      229a0c46
    • Yedidya Feldblum's avatar
      use LOG_FIRST_N in MemoryIdler · bdbdd4b3
      Yedidya Feldblum authored
      Summary: Use `LOG_FIRST_N` in `MemoryIdler` rather than reimplement it.
      
      Reviewed By: praihan
      
      Differential Revision: D26185702
      
      fbshipit-source-id: c1045ef8bf6aabefa4c0806c35c156539d6e594f
      bdbdd4b3
  9. 02 Feb, 2021 1 commit
    • Dan Melnic's avatar
      Delay registration of the timer and signal fds until running the loop first time · 536086dc
      Dan Melnic authored
      Summary:
      Delay registration of the timer and signal fds until running the loop first time
      On some Linux kernel versions, io_uring will remove any fd registrations on thread exit. So creating the backend in a thread that exits later will cause us not to receive timer and signal fd events.
      
      Reviewed By: kevin-vigor
      
      Differential Revision: D26200805
      
      fbshipit-source-id: dc3025964deb3cf87bf3e5a27141abcdb8698caf
      536086dc
  10. 01 Feb, 2021 2 commits
  11. 30 Jan, 2021 1 commit
    • Misha Shneerson's avatar
      python event loop consumes one task at a time from C++ notification queue · 7c9f69f9
      Misha Shneerson authored
      Summary:
      Currently, when C++ threads communicate with python's event loop, they place
      the items on the queue, notify the event loop, and when even loops starts
      running, they would consume all items from this queue at once.
      The downside of this approach is that we are unable to deprioritize the
      upstream tasks to yield to internal python tasks. However, such ability to yield
      is fundamental to how Thrift approaches load shedding under overload.
      In this diff we change the approach to take only a single item from the queue at a
      time. Notice that if queue is not emptied, the consumer will notify the event loop to
      consume from this queue on the next iteration of the loop.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D26163397
      
      fbshipit-source-id: 48cd6cb57c48ea67dce4eb5f0de6db5b0feb75ac
      7c9f69f9