1. 11 May, 2017 6 commits
    • Ashwin Bharambe's avatar
      Outline `Optional::require_value()` · 42c42914
      Ashwin Bharambe authored
      Summary:
      We would like to use `folly/Optional` in settings where exceptions
      are disabled. An example is ObjC++ codebases where supporting exceptions
      doesn't quite help (since objc_msgSend() can throw) and yet we need to pay the
      additional binary size cost for the unwind tables.
      
      This patch makes a small change to outline the "assert" utility included
      inside Optional.h
      
      Reviewed By: yfeldblum, mzlee
      
      Differential Revision: D5030172
      
      fbshipit-source-id: 7def3c6eda22c41c8cab2037444978e0a4c50abf
      42c42914
    • Philip Pronin's avatar
      AsyncIO::cancel · c8aadaad
      Philip Pronin authored
      Summary:
      It should be implemented with `io_cancel`, but it is not
      supported (D682836), so still have to drain events, ignoring only
      op callbacks.
      
      Reviewed By: luciang, ot
      
      Differential Revision: D5044020
      
      fbshipit-source-id: 0bcd04c91a437fccaf2189ccf771a1cb61c68942
      c8aadaad
    • Victor Zverovich's avatar
      Fix a race on destruction of ScopedEventBaseThread · e17fce32
      Victor Zverovich authored
      Summary:
      This diff fixes a race that happens on destruction of `ScopedEventBaseThread`.
      
      ```
      Thread1: ~ScopedEventBaseThread()
      Thread1: eb_.terminateLoopSoon() <- preempted just after stop_ = true
      Thread2: eb->loopForever() in run(...) exits because stop_ is true
      Thread2: ...
      Thread2: eb->~EventBase()
      Thread1: queue_->putMessage(nullptr) <- accesses destroyed EventBase
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5042654
      
      fbshipit-source-id: 95515ed7cde09ff5f125ef121bea86ab3907f98a
      e17fce32
    • Yedidya Feldblum's avatar
      hasher instances for 8-bit and 16-bit integral types · 9c626faa
      Yedidya Feldblum authored
      Summary:
      [Folly] `hasher` instances for 8-bit and 16-bit integral types.
      
      Allowing the use of `Hash` with such types.
      
      They are not necessarily the ideal algorithms for those widths, essentially forwarding to the 32-bit instances.
      
      Reviewed By: luciang
      
      Differential Revision: D5043094
      
      fbshipit-source-id: 6ef96dfc8d1baf0a15b9bdd585b7c7672099e4f0
      9c626faa
    • Kevin Chen's avatar
      Add writable() to AsyncTransport · f3bbb0b1
      Kevin Chen authored
      Summary:
      This is useful for checking if it's possible to still write to a transport,
      even if its read side is closed (for transports that support half shutdown,
      like AsyncSocket). Default implementation just returns true for now (up
      to implementers to override).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4982649
      
      fbshipit-source-id: 0a9a2e2b745ea3db57e9f151f3a8634e1bda2465
      f3bbb0b1
    • Mathieu Baudet's avatar
      add missing const to fix `folly::toDynamic` on `std::vector<bool>` · ea2c005e
      Mathieu Baudet authored
      Summary: [folly] add missing const to fix `folly::toDynamic` on `std::vector<bool>`
      
      Reviewed By: ender-wieczorek, yfeldblum
      
      Differential Revision: D5039403
      
      fbshipit-source-id: edd052c7d1d832d424166cba15fcd9f4f8bd219c
      ea2c005e
  2. 10 May, 2017 2 commits
    • Victor Loh's avatar
      Add pollWithRusage to Subprocess · 31751bbf
      Victor Loh authored
      Summary:
      I was looking for a way to get rusage of a particular pid because
      getrusage isn't good enough since it records the rusage of all the children
      that has been terminated (and waited for). Even though wait4 is marked as
      deprecated, wait3 (the cousin of wait4) is still being used in places like
      time. Furthermore, there is no suitable replacement to get rusage with wait*.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5008084
      
      fbshipit-source-id: 6e511ebec7464d21309e5112aca95083e9307ea1
      31751bbf
    • Anton Lunov's avatar
      Revert D4982969: [Folly] Destroy promise/future callback functions before waking waiters · 646be295
      Anton Lunov authored
      Summary: This reverts commit 71134c1657bdd4c38c12d8ca17f8335ef4c27352
      
      Differential Revision: D4982969
      
      fbshipit-source-id: fc1e766a5fd03fbd02c345904c3c6587013f38d5
      646be295
  3. 09 May, 2017 6 commits
    • Arkadiy Shapkin's avatar
      Fix FBString with MSVC · e8d25954
      Arkadiy Shapkin authored
      Summary: Closes https://github.com/facebook/folly/pull/588
      
      Reviewed By: ericniebler
      
      Differential Revision: D5029876
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 6a8f16373dcfb1c7b2741eb808da0f6dbc4207b6
      e8d25954
    • Eric Niebler's avatar
      Add folly::Identity function object to Utility.h; replace AtomicHashArray's... · abc55483
      Eric Niebler authored
      Add folly::Identity function object to Utility.h; replace AtomicHashArray's AHAIdentity and folly/gen's Identity with it
      
      Summary: Code duplication is bad.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5011806
      
      fbshipit-source-id: cab7bb3af1c934a5a63cd3fb98aa33f2578aebfb
      abc55483
    • Arkady Shapkin's avatar
      Support static gflags library · 6d94a087
      Arkady Shapkin authored
      Summary: Closes https://github.com/facebook/folly/pull/587
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5022071
      
      Pulled By: Orvid
      
      fbshipit-source-id: 2506087de76ba4544bf68a330bc2a18977c65f28
      6d94a087
    • Yedidya Feldblum's avatar
      Destroy promise/future callback functions before waking waiters · 0be5c0a4
      Yedidya Feldblum authored
      Summary:
      Code may pass a callback which captures an object with a destructor which mutates through a stored reference, triggering heap-use-after-free or stack-use-after-scope.
      
      ```lang=c++
      void performDataRace() {
        auto number = std::make_unique<int>(0);
        auto guard = folly::makeGuard([&number] { *number = 1; });
        folly::via(getSomeExecutor(), [guard = std::move(guard)]() mutable {}).wait();
        // data race - we may wake and destruct number before guard is destructed on the
        // executor thread, which is both stack-use-after-scope and heap-use-after-free!
      }
      ```
      
      We can avoid this condition by always destructing the provided functor before setting any result on the promise.
      
      Reviewed By: spacedentist
      
      Differential Revision: D4982969
      
      fbshipit-source-id: 71134c1657bdd4c38c12d8ca17f8335ef4c27352
      0be5c0a4
    • Philipp Unterbrunner's avatar
      back_emplace_iterator and related classes and utility functions · d5986bf0
      Philipp Unterbrunner authored
      Summary:
      C++ up to and including C++17 lacks an alternative to std::back_inserter() that uses emplace_back() instead of push_back(). This causes unnecessary temporary objects in some cases, when using std::back_inserter() together with STL functions such as std::copy() or std::transform(). The same holds for std::front_inserter() and std::inserter().
      This diff introduces folly::back_emplacer(), folly::front_emplacer(), folly::emplacer(), and related iterator classes, which call emplace_back(), emplace_front(), and emplace() respectively, with perfect forwarding of any arguments to the output iterator's operator=.
      Includes support for variadic emplacement / multi-argument constructors through a utility function folly::make_emplace_args() which packs its arguments into a special tuple for use with operator=.
      
      Reviewed By: ericniebler
      
      Differential Revision: D4897174
      
      fbshipit-source-id: c85c30c457e0c946938051819baa662d1a0b8ca1
      d5986bf0
    • Christopher Dykes's avatar
      Codemod folly::make_unique to std::make_unique · f34acf2c
      Christopher Dykes authored
      Summary: There are still some upstream references to `folly::make_unique` that need to be removed before it can be full killed, but this gets it most of the way there.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5024310
      
      fbshipit-source-id: 6cfe8ea93662be18bb55588c8200dec72946e205
      f34acf2c
  4. 08 May, 2017 3 commits
    • Jim Meyering's avatar
      change EXPECT_EQ(false, ... to EXPECT_FALSE(...; ditto for true/EXPECT_TRUE · fea92be9
      Jim Meyering authored
      Summary:
      Change every instance of EXPECT_EQ(false, ... to the simpler/shorter EXPECT_FALSE(...
      Likewise, convert each EXPECT_EQ(true, ... to EXPECT_TRUE(...
      
      Differential Revision: D5019004
      
      fbshipit-source-id: 0203f10fa47237f869a75a057ac4456ef03e1f53
      fea92be9
    • Anirudh Ramachandran's avatar
      Move OpenSSLPtrTypes.h from folly/io/async/ssl to folly/ssl · 6b1a43fd
      Anirudh Ramachandran authored
      Summary:
      There's nothing io/async/ssl-specific in this file. Moving to the
      top-level directory will help this be more discoverable. Part of general cleanup
      for io/async/ssl
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5005566
      
      fbshipit-source-id: 66a05a2139ee80a6d63791d1851da3f1858e8abf
      6b1a43fd
    • Dave Watson's avatar
      Add hardware crc impl · d9acfc9e
      Dave Watson authored
      Summary:
      A faster crc32 impl for folly.  Similar to crc32c, except
      intel doesn't provide crc32 directly in hardware - instead, pclmul can be used,
      which is ~2x slower than crc32c, but still ~5-10x faster than software implementation.
      
      Reviewed By: Orvid, yfeldblum
      
      Differential Revision: D4994761
      
      fbshipit-source-id: ad8ba856649eea6dc7b541d561329ff7d7fe2d60
      d9acfc9e
  5. 06 May, 2017 3 commits
    • Andrii Grynenko's avatar
      Fix folly::call_once · 932973bf
      Andrii Grynenko authored
      Summary: std::call_once implementation is broken if function throws. This fixes folly::call_once to not depend on std::call_once.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5015897
      
      fbshipit-source-id: bcbda68becf0930cdbf0b09125cbee61d75c2015
      932973bf
    • Yedidya Feldblum's avatar
      Mark future-core get-state members as const noexcept · c822472d
      Yedidya Feldblum authored
      Summary: [Folly] Mark future-core get-state members as `const noexcept`.
      
      Reviewed By: andrewjcg
      
      Differential Revision: D5014358
      
      fbshipit-source-id: e39b0b63c59267a4ecfab5aac02e6d96ce2e7e00
      c822472d
    • Yedidya Feldblum's avatar
      Stop trying to setrlimit(RLIMIT_AS) in ASAN builds · 613033ba
      Yedidya Feldblum authored
      Summary:
      [Folly] Stop trying to `setrlimit(RLIMIT_AS)` in ASAN builds.
      
      ASAN needs to reserve plenty of memory outside of the limited address space imposed by the call to `setrlimit`.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D5014679
      
      fbshipit-source-id: 2ab71b1cca9297d3a276cf72154fac30a2057f86
      613033ba
  6. 05 May, 2017 6 commits
    • Eric Niebler's avatar
      FixedString gets comparisons with folly::Range and hence with std::string · 90230f14
      Eric Niebler authored
      Summary: It should be possible to perform simple comparison operations between a FixedString and a std::string. By adding asymmetric comparison operators with FixedString and Range, we make FixedString comparable with anything convertible to Range, including std::string.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5007704
      
      fbshipit-source-id: fee89d8807ac2d5378eec0d0a51eb8684976a271
      90230f14
    • Christopher Dykes's avatar
      Fix getCurrentThreadName() on OSX · 0917b8bd
      Christopher Dykes authored
      Summary: OSX was sad. Now it should be happy.
      
      Reviewed By: mzlee
      
      Differential Revision: D5011751
      
      fbshipit-source-id: 77f22ff461036d8530d8f650396d8e12503448e7
      0917b8bd
    • Yedidya Feldblum's avatar
      Control the number of threads in TestExecutor · 0eff88b3
      Yedidya Feldblum authored
      Summary:
      [Folly] Control the number of threads in `TestExecutor`.
      
      Let the caller control the number of threads to use in each given case.
      
      Reviewed By: spacedentist
      
      Differential Revision: D4999699
      
      fbshipit-source-id: 4acf68cf17fbca14f0779daf0268d54c5606e4a8
      0eff88b3
    • Sven Over's avatar
      Future: improve test with task discarding executors · 3703b1b0
      Sven Over authored
      Summary:
      We have tests that check that the Future implementation deals
      cleanly with executors discarding tasks. The existing tests destroy
      the tasks immediately when they are passed to Executor::add. This
      diff adds corresponding tests for the scenario where the task is
      not destroyed right away, but after the call to Future::then has
      completed.
      
      This diff also adds a mechanism to detect that the passed callback
      function is actually destroyed. We have tested already that the
      promise returned by folly::then will be set to a BrokenPromise
      exception when the executor discards the task. However, the task
      passed to the executor is not only the callback we pass to
      folly::then, as the Future implementation wraps it with some code
      that stores the return value in a Promise. Existing tests check
      that this Promise is destroyed. The added mechanism in this diff
      checks that the orignal callback function itself gets destroyed.
      
      Reviewed By: Krigpl
      
      Differential Revision: D5002100
      
      fbshipit-source-id: 4155f61b075d9fe8d1869ad229f4d350571ff4c6
      3703b1b0
    • Yedidya Feldblum's avatar
      Add full noexcept annotations to Indestructible · c484e2ca
      Yedidya Feldblum authored
      Summary:
      [Folly] Add full `noexcept` annotations to `Indestructible`.
      
      And do it without requiring `<type_traits>`.
      
      Reviewed By: Orvid
      
      Differential Revision: D4999243
      
      fbshipit-source-id: f3521237ef4d03d2b187e9ebd6d0c90887872c42
      c484e2ca
    • Christopher Dykes's avatar
      Delete operator=(std::string&&) from StringPiece · 1c86749b
      Christopher Dykes authored
      Summary: This can only ever be used unsafely, so delete it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4951294
      
      fbshipit-source-id: bbc266d1550fceb48946c7c48e76af07292b4a53
      1c86749b
  7. 04 May, 2017 4 commits
    • Christopher Dykes's avatar
      Support naming a ScopedEventBaseThread · cf05856c
      Christopher Dykes authored
      Summary:
      The setThreadName API is in the process of being changed to not accept a thread id, which means the thread itself needs to set the name.
      There are times where a `ScopedEventBaseThread` needs to be named, and this makes that possible.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4916781
      
      fbshipit-source-id: dab05b520a715183ce069151ed16864fa1331abc
      cf05856c
    • Christopher Dykes's avatar
      Add support for getting the current thread's name · 5cef863e
      Christopher Dykes authored
      Summary: It's primarily for use in testing, but is useful for log output as well.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4943072
      
      fbshipit-source-id: 0ca259d6c90f439e733a6179e7cba85dcd1ec9e7
      5cef863e
    • Maged Michael's avatar
      Add thread-safe priority queue with arbitrary priorities using flat combining · 223ef4eb
      Maged Michael authored
      Summary: This template uses flat combining and takes any sequential priority queue implementation that supports the `std::priority_queue` interface (`empty()`, `size()`, `push()`, `top()`, `pop()`) and any lock that meets the standard //Lockable// requirements to implement a thread-safe priority queue that supports arbitrary priorities. The template supports both unbounded and bounded size, and blocking, non-blocking, and timed variants of push, pop, and peek operations.
      
      Reviewed By: djwatson
      
      Differential Revision: D4873602
      
      fbshipit-source-id: 96e1548b4f7427ecd2ee2ead7a19993df4441b33
      223ef4eb
    • Eric Niebler's avatar
      test the typeid of the exception before it is potentially moved · 5947e778
      Eric Niebler authored
      Summary: Access the RTTI of the incomming exception before it is potentially moved from when testing for slicing
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4999189
      
      fbshipit-source-id: 3e6c0a9f10a27810484330e9b37a5b0ec450ff88
      5947e778
  8. 03 May, 2017 9 commits
    • Aravind Anbudurai's avatar
      Helper utility to construct, returns an Expected<..> · 919d544e
      Aravind Anbudurai authored
      Summary:
      folly::File's throwing constructor results in many try-catches in the callsites
      or bugs where the exception is not caught.
      
      This is a helper method to return an Expected with system_error wrapped into an
      exception_wrapper.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4995702
      
      fbshipit-source-id: be0e22b37c21c35bf157ada598916b05dfd32631
      919d544e
    • Giuseppe Ottaviano's avatar
      Store pointers in EliasFanoReader and BitVectorReader only if quantum > 0 · 6f027b29
      Giuseppe Ottaviano authored
      Summary:
      No need to store the pointers to forward and skip arrays if
      they're not used.
      
      Reviewed By: luciang
      
      Differential Revision: D4977014
      
      fbshipit-source-id: 2ed13fdcd1561da1a294f5895f3a5e1b77f1701c
      6f027b29
    • Giuseppe Ottaviano's avatar
      Template EliasFanoReader on size type · 121ecb47
      Giuseppe Ottaviano authored
      Summary: Shrink the reader type if less than 64 bits are sufficient for sizes. Do the same for `BitVectorCoding`, where we don't need an extra template parameter because the size is limited by the value domain.
      
      Reviewed By: philippv, luciang
      
      Differential Revision: D4976756
      
      fbshipit-source-id: 685047da81a556d049fb924c612f99cea3056a82
      121ecb47
    • Giuseppe Ottaviano's avatar
      Do not store inner_ in EliasFanoReader and BitVectorReader · 71ca4d5e
      Giuseppe Ottaviano authored
      Summary: It is not used anywhere except for `previousValue`, but there it can be computed from the other fields. This reduces the `EliasFanoReader` size by 8 bytes.
      
      Reviewed By: philippv, yfeldblum
      
      Differential Revision: D4976704
      
      fbshipit-source-id: 62bc63248b66649e483b59cb9ddf48dfd2c0e992
      71ca4d5e
    • Giuseppe Ottaviano's avatar
      Do not store the lower bits mask in EliasFanoReader · 0b988b15
      Giuseppe Ottaviano authored
      Summary:
      Computing the mask on access has negligible cost as it can be
      hoisted out of the linear search loop, and furthermore on Haswell we
      can use the the `BZHI` instruction.
      
      I also experimented with `BEXTR` but it ended up being slower because
      computing the pattern operand requires a shift and an or (it's
      probably meant for when the pattern is precomputed).
      
      Reviewed By: philippv
      
      Differential Revision: D4976657
      
      fbshipit-source-id: e4c4ca5f0a785595587e6d6ad4676f5b216291cf
      0b988b15
    • Dave Watson's avatar
      Domain destruction fixes · 90c8861c
      Dave Watson authored
      Summary:
      If a retired object's destructor retire()s other hazard pointers, currently
      these are not cleaned up correctly when the domain destructs.
      
      Retired pointers must be cleaned up before destroying hazptr_recs, and must be done
      iteratively until no more garbage is generated.
      
      Reviewed By: magedm
      
      Differential Revision: D4987333
      
      fbshipit-source-id: bcdd61abb47caca0892a8c4dbb864d17d4f2fa30
      90c8861c
    • Christopher Dykes's avatar
      Fix a couple of issues with the CMake script · c2e28878
      Christopher Dykes authored
      Summary:
      The first issue is that I was missing a `G` in `LIBGFLAGS_INCLUDE_DIR` meaning that it always claimed it couldn't find gflags even though it did, and worked just fine anyways.
      The second issue is that it was passing `/permissive-` to MSVC 2015 builds, even though MSVC 2015 doesn't support the permissive flag.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4988813
      
      fbshipit-source-id: f1ea009226baee54032409ce7add3c41f1fe7a19
      c2e28878
    • Christopher Dykes's avatar
      Fix compiling with PThread support on Windows... Again... · 58a70372
      Christopher Dykes authored
      Summary: I was bad and didn't follow through on my previous test plan, and so didn't check that it completely fixed the issue, instead only fixing one of the two problems. This fixes the other one.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4988408
      
      fbshipit-source-id: 44389bc67bcb7d6db984075f3600948460fa8c5a
      58a70372
    • Christopher Dykes's avatar
      Fix ExceptionWrapper under MSVC 2015 Update 3 · 59c1b560
      Christopher Dykes authored
      Summary: Besides this code being utterly bizzare, it doesn't work under MSVC 2015 Update 3, so rather than doing a `static_cast<bool>(std::conjunction<>())` just do `std::conjunction<>::value`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4988341
      
      fbshipit-source-id: ededdbf3f3d945d9e2f140f4e87643ec3c0d4239
      59c1b560
  9. 02 May, 2017 1 commit
    • Christopher Dykes's avatar
      Fix FBString in MSVC 2015 · 5e8852c8
      Christopher Dykes authored
      Summary: MSVC 2015 Update 3 is even worse in this particular case, and requires it to be explicitly referenced as being within the `folly` namespace >_>...
      
      Reviewed By: ot, yfeldblum
      
      Differential Revision: D4988025
      
      fbshipit-source-id: dea311dd42f40b442951b8df3c5f68cf70d13769
      5e8852c8