1. 03 Jan, 2019 1 commit
    • Yedidya Feldblum's avatar
      Make co_current_executor look like nullptr, std::nullopt, std::in_place · 8cf16b1e
      Yedidya Feldblum authored
      Summary:
      [Folly] Make `co_current_executor` look like `nullptr`, `std::nullopt`, `std::in_place`.
      
      * Use a `co_` prefix to indicate that it is offers a useful result when awaited.
      * Offer a well-named value with a well-named type or type alias.
        * There is the `nullptr` value and `std::nullptr_t` type or type alias.
        * There is the `std::nullopt` value and the `std::nullopt_t` type or type alias.
        * There is the `std::in_place` value and the `std::in_place_t` type or type alias.
      
      Reviewed By: andriigrynenko, lewissbaker
      
      Differential Revision: D13561713
      
      fbshipit-source-id: 835da086e7165d37a952a1f169318cb566401d12
      8cf16b1e
  2. 02 Jan, 2019 5 commits
    • Orvid King's avatar
      Remove the fd overload of AsyncSocket::OptionKey::apply · 1d5519da
      Orvid King authored
      Summary: Everything has been migrated over to the NetworkSocket overload.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13566609
      
      fbshipit-source-id: 920505a9e91f1acc5810949049880ed07294621b
      1d5519da
    • Nathan Bronson's avatar
      memory savings for F14 tables with explicit reserve() · 3d169f43
      Nathan Bronson authored
      Summary:
      In the case when an explicit capacity is specified (via reserve()
      or an initial capacity) we can save memory by using a bucket_count()
      off of the normal geometric sequence.  This is beneficial for sizes
      <= Chunk::kCapacity for all policies, and for F14Vector tables with
      any size.  In the multi-chunk F14Vector case this will save about
      40%*size()*sizeof(value_type) when reserve() is used (such as during
      Thrift deserialization).  The single-chunk savings are potentially larger.
      The changes do not affect the lookup path and should be a tiny perf win in
      the non-growing insert case.  Exact sizing is only attempted on reserve()
      or rehash() when the requested capacity is >= 9/8 or <= 7/8 of the current
      bucket_count(), so it won't trigger O(n^2) behavior even if misused.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D12848355
      
      fbshipit-source-id: 4f70b4dabf626142cfe370e5b1db581af1a1103f
      3d169f43
    • Maged Michael's avatar
      hazptr: Add test for recursive destruction · 175e5c95
      Maged Michael authored
      Summary: Add test for recursive destruction.
      
      Reviewed By: djwatson
      
      Differential Revision: D13476864
      
      fbshipit-source-id: 513f39f44ad2f0d338d10066b2e337902db32e00
      175e5c95
    • Maged Michael's avatar
      ConcurrentHashMap: Enable destruction order guarantee · 9e652978
      Maged Michael authored
      Summary: Enable destruction order guarantee, i.e., destructors for all key and value instances will complete before the completion of the destructor of the associated ConcurrentHashMap instance.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D13440153
      
      fbshipit-source-id: 21dce09fa5ece00eaa9caf7a37b5a64be3319d5e
      9e652978
    • Maged Michael's avatar
      hazptr: Avoid deadlock on tagged list · b693ea20
      Maged Michael authored
      Summary:
      Prevent deadlock on tagged retired lists within calls to `do_reclamation()` that call `cleanup_batch_tag()`.
      
      Changes:
      - Make locking the tagged list reentrant.
      - Eliminate sharding of tagged lists to prevent deadlock between concurrent calls to `do_reclamation()` on different shards that call `cleanup_batch_tag` on the other shard.
      - Expose the list of unprotected objects being reclaimed in `do_reclamation()` of the tagged list so that calls to `cleanup_batch_tag()` don't miss objects with a matching tag.
      - Refactor of commonalities between calls to `retire()` in `hazptr_obj_base` and `hazptr_obj_base_linked` into `hazptr_obj::push_obj()`.
      - Fixed release of tagged list lock to use CAS in a loop instead of store, since concurrent lock-free pushes are possible.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D13439983
      
      fbshipit-source-id: 5cea585c577a64ea8b43a1827522335a18b9a933
      b693ea20
  3. 30 Dec, 2018 1 commit
    • Yedidya Feldblum's avatar
      test_once · d7d5fe11
      Yedidya Feldblum authored
      Summary:
      [Folly] `test_once`, a way to check whether any call to `call_once` with a given `once_flag` has succeeded.
      
      One example of use might be for exception-safety guarding object destruction when object construction is guarded by the `once_flag`, and when the user is interested in conserving per-object memory and wishes to avoid the extra 8-byte overhead of `std::optional`.
      
      ```lang=c++
      template <typename T>
      struct Lazy {
        folly::aligned_storage_for_t<T> storage;
        folly::once_flag once;
      
        ~Lazy() {
          if (folly::test_once(once)) {
            reinterpret_cast<T&>(storage).~T();
          }
        }
      
        template <typename... A>
        T& construct_or_fetch(A&&... a) {
          folly::call_once(once, [&] { new (&storage) T(std::forward<A>(a)...); });
          return reinterpret_cast<T&>(storage);
        }
      };
      ```
      
      Reviewed By: ovoietsa
      
      Differential Revision: D13561365
      
      fbshipit-source-id: 8376c154002f1546f099903c4dc6be94dd2def8e
      d7d5fe11
  4. 28 Dec, 2018 2 commits
    • Nathan Bronson's avatar
      extend FOLLY_F14_PERTURB_INSERTION_ORDER to all F14FastMap/Set · 0c66e13e
      Nathan Bronson authored
      Summary:
      Previously the debug-build randomization of F14 iteration order
      was applied only to F14ValueMap/Set, F14NodeMap/Set, and F14FastMap/Set
      that uses the value storage strategy.  This extends the behavior to
      F14FastMap/Set that use the vector storage strategy, which are those
      instances where sizeof(value_type) >= 24.
      
      F14FastMap/Set using the vector storage strategy must move items
      to randomize, so this reordering will also expose cases that assume
      reference or iterator stability across multiple inserts without a call
      to .reserve().
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13305818
      
      fbshipit-source-id: 178a1f7b707998728a0451af34269e735bf063f3
      0c66e13e
    • Nitin Garg's avatar
      Simple benchmark for getStackTrace · 3772b70b
      Nitin Garg authored
      Summary: Needed to get a rough sense of its expense to know when it would be worth collecting in contention events.
      
      Reviewed By: prateek1404
      
      Differential Revision: D13544220
      
      fbshipit-source-id: 6a4c00d84d997c6fbe5dfb0e0cdb9bfbbe97a8a0
      3772b70b
  5. 22 Dec, 2018 1 commit
    • Victor Zverovich's avatar
      Fix singleton_thread_local_test CMake build · 840fd786
      Victor Zverovich authored
      Summary:
      Add the `singleton_thread_local_test` companion shared library to CMake config
      and enable these only when folly is compiled with `-fPIC`. This should fix
      Travis build.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13542693
      
      fbshipit-source-id: 2372da298cc69c2e7e491fbde681fe90d8879d47
      840fd786
  6. 21 Dec, 2018 1 commit
    • Yedidya Feldblum's avatar
      co_invoke · da78383f
      Yedidya Feldblum authored
      Summary:
      [Folly] `folly::coro::co_invoke`, both generalizing and constraining `folly::coro::lambda` and modeling on `std::invoke`.
      
      Constrained only to work on callables which return `Task<_>` in order to be sure that `invoke_result_t<F, A...>` is the same as the type of `co_await <expr>` where `expr` has type `invoke_result_t<F, A...>`. We know that this constraint holds for `Task<_>`. The alternative is to make it work for all types and use `decltype(auto)` as the return type.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D13523334
      
      fbshipit-source-id: 9af220dd45d6b9f6676c5ef49ba2e01395babd72
      da78383f
  7. 20 Dec, 2018 3 commits
    • Doron Roberts-Kedes's avatar
      Fix parent_->segments_ index out of bounds bug. · dd52ab90
      Doron Roberts-Kedes authored
      Summary: Found while testing with BufferedDeterministicAtomic.
      
      Reviewed By: djwatson
      
      Differential Revision: D13509000
      
      fbshipit-source-id: ec1cef0afc888136db3ccda8dff99bc0a45f6bff
      dd52ab90
    • Doron Roberts-Kedes's avatar
      BufferedAtomic: add futex extensions, share impl with DeterministicAtomic · c68fd6e3
      Doron Roberts-Kedes authored
      Summary:
      Make code for futex[Wait/Wake]Impl for DeterministicAtomic templated, rename to deterministicFutex[Wait/Wake]Impl, and move to DeterministicSchedule.h so that it can be shared by BufferedDeterministicAtomic.
      
      Point the futex[Wait/Wake]Impl for DeterministicAtomic at deterministicFutex[Wait/Wake]Impl<DeterministicAtomic>.
      
      Create new futex[Wait/Wake]Impl for BufferedDeterministicAtomic using deterministicFutex[Wait/Wake]Impl<BufferedDeterministicAtomic>
      
      Reviewed By: djwatson
      
      Differential Revision: D13519817
      
      fbshipit-source-id: c792ea9dcd6287236bc772e9aa9662277cc9e642
      c68fd6e3
    • Dan Melnic's avatar
      Replace new/delete[] with std::unique_ptr · afce0f0b
      Dan Melnic authored
      Summary: Replace new/delete[] with std::unique_ptr
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13525009
      
      fbshipit-source-id: 8497329e2881f1cfd6fe7ca5c4ae432c3071faec
      afce0f0b
  8. 19 Dec, 2018 4 commits
    • Orvid King's avatar
      Shift calls of AsyncSocket::OptionKey::apply to the NetworkSocket overload · 1fbec4b0
      Orvid King authored
      Summary: The file descriptor overload will be going away.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13508239
      
      fbshipit-source-id: 3fce90d98e9252881cb9ed0030fba558d89470af
      1fbec4b0
    • Andrii Grynenko's avatar
      Add coroutine support to fibers::Semaphore · c1990c7c
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D13515209
      
      fbshipit-source-id: 6d4688242a586b6e5558c62c1c6f3bb7c6595dfb
      c1990c7c
    • Andrii Grynenko's avatar
      Fix a race in fibers::Semaphore · 43ea7bf4
      Andrii Grynenko authored
      Summary: We should never end up doing compare_exchange_weak with oldVal==0, because that may result in increment/decrement from 0.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13514210
      
      fbshipit-source-id: 0ccffe5d9525389ba02208f3bf37ce14acb9f28e
      43ea7bf4
    • Andrii Grynenko's avatar
      Make coro::Task convertible to SemiFuture · 7d487470
      Andrii Grynenko authored
      Summary: coro::Task can be always converted to a lazy SemiFuture. This can be very useful when converting existing futures code to coroutines.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13502414
      
      fbshipit-source-id: 2e3971217086c762f3f831ef19d0d88b621b7c80
      7d487470
  9. 18 Dec, 2018 2 commits
  10. 17 Dec, 2018 4 commits
    • Yedidya Feldblum's avatar
      Change Synchronized::copy copy-assignment overload · 3980dd0f
      Yedidya Feldblum authored
      Summary:
      [Folly] Change Synchronized::copy copy-assignment overload: rename to `copy_into`, and take ref v.s. ptr.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: aary
      
      Differential Revision: D13475878
      
      fbshipit-source-id: 4923a0cc73359853357dba60c6e4be654e92ce82
      3980dd0f
    • Yedidya Feldblum's avatar
      "Upgrade" wording in Synchronized · f7bf375c
      Yedidya Feldblum authored
      Summary:
      [Folly] "Upgrade" wording in `Synchronized`.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: aary
      
      Differential Revision: D13484147
      
      fbshipit-source-id: 5ccaac2de5e03986885000869a862d2a37ab5751
      f7bf375c
    • Aaryaman Sagar's avatar
      Add back const write lock methods to Synchronized · 15be4529
      Aaryaman Sagar authored
      Summary:
      The behavior of not allowing write locks on const methods is inconsistent, as
      there is no way of determining the semantics of the protected object.  In
      particular there are two types of classes that come into mind here
      
      - Pointer and reference like classes.  These can be const, but the underlying
        data item need not be const.  Here it should be perfectly resaonable to
        allow users to acquire a write lock on a const Synchronized<> object
      - Types with mutable members.  These can be write locked even when const, this
        behavior is probably okay.
      
      On the other hand the previous motivation of this diff - inconsistency with
      upgrade locks is being removed.  They will no longer expose non-const access
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13478631
      
      fbshipit-source-id: 652a08c61abf35c3eadc45cedc5d300fbef83a6b
      15be4529
    • Andrii Grynenko's avatar
      Lambda · eeeed147
      Andrii Grynenko authored
      Summary: Introduce a coro::lambda helper which makes it safe to create coroutine lambdas with captures.
      
      Reviewed By: lewissbaker
      
      Differential Revision: D13473068
      
      fbshipit-source-id: a1177b4d57715b10fc4398fa6626ee105a8a43ce
      eeeed147
  11. 16 Dec, 2018 2 commits
  12. 14 Dec, 2018 4 commits
    • David Goldblatt's avatar
      Add AtomicReadMostlyMainPtr · 69c7f1b7
      David Goldblatt authored
      Summary:
      This is a ReadMostlyMainPtr variant that allows racy accesses. By making the
      write-side slower, the read side can avoid any contended shared accesses or
      RMWs.
      
      Reviewed By: djwatson
      
      Differential Revision: D13413105
      
      fbshipit-source-id: f03c7ad58be72b63549b145ed6f41c51563831d1
      69c7f1b7
    • Lee Howes's avatar
      Deprecate Future::onError · cc381bd4
      Lee Howes authored
      Summary:
      onError is to be phased out because:
       * It is weakly typed
       * (most seriously) It loses the executor and so terminates a via chain silently causing subsequent work to run in the wrong place
      
      onError is replaced with thenError which fixes both problems.
      
      This diff merely deprecates it to allow for a gentle phase out.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13418290
      
      fbshipit-source-id: a0c5e65a97ed41de18d85ceab258417355a43139
      cc381bd4
    • Yedidya Feldblum's avatar
      Extract FunctionTraitsSharedProxy · 32543b61
      Yedidya Feldblum authored
      Summary: [Folly] Extract `FunctionTraitsSharedProxy`, deduplicating four nearly identical implementations.
      
      Differential Revision: D13461506
      
      fbshipit-source-id: 2927dbe1629024cf778301c509b82711940a8099
      32543b61
    • Orvid King's avatar
      Remove the fd overload of ShutdownSocketSet::* · a9b13cab
      Orvid King authored
      Summary: No longer needed
      
      Reviewed By: djwatson
      
      Differential Revision: D13456759
      
      fbshipit-source-id: ea08992d3bd4babbdcf326b0c01f64cd1184784f
      a9b13cab
  13. 13 Dec, 2018 2 commits
  14. 12 Dec, 2018 3 commits
  15. 11 Dec, 2018 5 commits
    • Andrii Grynenko's avatar
      addTaskEager/addTaskEagerFuture · a3085174
      Andrii Grynenko authored
      Summary: This allows avoiding extra executor/queueing operations if caller knows that task can be safely run inline.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D13404703
      
      fbshipit-source-id: 4aa71e59b48572671e8031ee7ea4dcd4e3a6138b
      a3085174
    • Songqiao Su's avatar
      (folly/benchmark)(RFC) allow users to record customized counters during benckmark · 59b94083
      Songqiao Su authored
      Summary:
      There could be cases that user want to record some of their own metrics during benchmark. This diff add another kinds of macro BENCHMARK_COUNTERS to make it happen, see Test plan for an example.
      
      One problem is that it would be hard to output the result on the fly. As it needs to run all benchmarks first to know which customized counter are used, then it can output the proper column headers.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D9874668
      
      fbshipit-source-id: 2004bb4484e54c1edd65763d1727486c6905d884
      59b94083
    • Andre Pinto's avatar
      Add getTotalBufferedBytes() method fo AsyncTransport · 399c4fa5
      Andre Pinto authored
      Summary:
      When BufferCallback::onEgressBuffered() is called, applications usually want to
      know how many bytes were buffered so that can take actions (such as avoiding
      that connection, failing fast, etc).
      This diff adds getTotalPendingBytes() to AsyncTransport to allow applications
      to easily query how many bytes were actually buffered.
      
      Reviewed By: spalamarchuk
      
      Differential Revision: D13252677
      
      fbshipit-source-id: 8ec203f6764e00f52d471321afb549376397eb84
      399c4fa5
    • Dylan Yudaken's avatar
      Fix potential buffer overflow in use of strncat · 2e5a8ccb
      Dylan Yudaken authored
      Summary: There is a bug in ElfFile using strncat which could cause buffer overflows when a previous file open failed. strncat only limits based on the src length, and so if strlen(dest) > 0 this could have overflowed.
      
      Reviewed By: anakryiko
      
      Differential Revision: D13398108
      
      fbshipit-source-id: 793c35884f1e639f36758f36046158858fd5976a
      2e5a8ccb
    • Nitin Garg's avatar
      Add APIs in DynamicTokenBucket to be able to return excess tokens and to borrow from future. · e919bad4
      Nitin Garg authored
      Summary:
      The common use case for token buckets to implement resource usage throttling/smoothing also implies that callers need to either implement their own backoff+retry mechanism. The simple exponential backoff approach is prone to starvation and over-throttling (under-utilized resource). Many cases will simply be okay with being told at what point in future their allocations can be met effectively doing the starvation free FIFO scheduling for them. Added a consumeWithBorrow API to enable this behavior.
      
      Added checks in existing API to account for the possibility of the internal clock of the bucket being 'in future' wrt to the 'now' argument passed in the call.
      
      Also added an API to be able to return previously allocated tokens effectively moving the clock back on the bucket. This is largely for completeness and there isn't an immediate use case in mind for this.
      
      Reviewed By: yfeldblum, usumeet
      
      Differential Revision: D13166472
      
      fbshipit-source-id: 4d6f93eedcc75eb07c1250026e57806c96974c96
      e919bad4