1. 13 Jan, 2018 2 commits
    • Adam Simpkins's avatar
      cmake: set compiler flags for non-Windows platforms · 03957924
      Adam Simpkins authored
      Summary:
      Update CMakeLists.txt to check the current platform, and to set compiler flags
      correctly.  It now uses flags for Microsoft Visual Studio on Windows, and flags
      for gcc or clang on all other platforms.  Previously it unconditionally used
      MSVC flags.
      
      Reviewed By: meyering
      
      Differential Revision: D6710435
      
      fbshipit-source-id: dbae3097bcadf1ee4a25879dd7770603387c0e4d
      03957924
    • Adam Simpkins's avatar
      cmake: support using a separate build directory · 3d9eb7ff
      Adam Simpkins authored
      Summary:
      Fix rules in the CMakeLists.txt file that generate source files to first create
      their output directory if necessary.  This allows the build to succeed when
      building with a separate build output directory, rather than placing build
      artifacts in the source tree itself.
      
      Reviewed By: meyering
      
      Differential Revision: D6710436
      
      fbshipit-source-id: 786a65a37a70833e7e4a5affe4df292626dbb591
      3d9eb7ff
  2. 12 Jan, 2018 5 commits
    • Eric Niebler's avatar
      correctly handle APIs that accept Poly<T&> as an argument · 4a5ba093
      Eric Niebler authored
      Summary: Multi-dispatch in Poly was handled by treating arguments of type Poly<I&> as special, unwrapping them. That's a problem if the underlying API actually wants the Poly<I&> unmolested.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6713975
      
      fbshipit-source-id: 18a90fa701fab14c3d3d46c247efe09ea5903b11
      4a5ba093
    • Sergey Makarenko's avatar
      Register singleton's destruction using std::atexit · 3f4a8ae0
      Sergey Makarenko authored
      Summary:
      scheduleDestroyInstances function is called from createInstance function when
      new instance of specific singleton type is created thus marking a point in
      static objects order  when all singltons will be destructed.
      This does not work well for situations when singleton is loaded as part of
      python extension which is a shared object. In this case static objects of this
      shared object would be constructed first and singleton from this extension will
      be created after that. Since destruction order is reversed and all singletons
      will be destructed together, static objects of python extension will be
      destroyed before singleton from this extension. Which leads to heap-after-free
      ASAN exceptions.
      In other words, lifetime of all folly singletons is aligned to the lifetime of the
      first created folly singleton.
      Using std::atexit to register singleton's destruction from singleton
      constructor will align  lifetime of singletons to the most recent singleton
      which matters for python extensions and does not matter for other use cases.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D6705644
      
      fbshipit-source-id: 5c933886ceae649e3c75f8e7e7936d5a7ed04539
      3f4a8ae0
    • Enji Cooper's avatar
      Spell uintptr_t properly in static_assert in `getStackTrace()` · c7801abd
      Enji Cooper authored
      Summary:
      While here, pet the linter with respect to the warning around the indentation with the comment containing the licensing tort.
      Signed-off-by: default avatarEnji Cooper <yaneurabeya@gmail.com>
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6710314
      
      fbshipit-source-id: fc0b971e6300af9c63a690c54c08fc70e0313b70
      c7801abd
    • Yedidya Feldblum's avatar
      Unsafe pre-sorted construction for sorted-vector containers · fd5eeb5f
      Yedidya Feldblum authored
      Summary:
      [Folly] Unsafe pre-sorted construction for sorted-vector containers.
      
      If the backing container type can be constructed directly in sorted order or can be determined in advance to be in sorted order, then a special constructor can help code take advantage of this condition by avoiding an extra invocation of `std::sort`.
      
      Reviewed By: spalamarchuk
      
      Differential Revision: D6708379
      
      fbshipit-source-id: 25d886b0814dc9230c6046ed1e7f199fac47754e
      fd5eeb5f
    • Adam Simpkins's avatar
      cmake: fix error message on non-Windows platform · ab21322d
      Adam Simpkins authored
      Summary:
      Building folly with cmake is only supported on Windows for now.  This fixes
      cmake on non-Windows platforms to fail with a helpful message telling people to
      use autoconf.  This message was in place before, but was after an MSVC version
      check preventing it from appearing.
      
      Reviewed By: meyering
      
      Differential Revision: D6707328
      
      fbshipit-source-id: a28a07ab0da41d605b11d93bba40f33520c5f57e
      ab21322d
  3. 11 Jan, 2018 5 commits
    • Yedidya Feldblum's avatar
      MemoryIdler::futexWaitUntil · b1fe65ff
      Yedidya Feldblum authored
      Summary:
      [Folly] `MemoryIdler::futexWaitUntil`.
      
      Adds `MemoryIdler::futexWaitUntil` that works like `Futex::futexWaitUntil`, in a similar way that `MemoryIdler::futexWait` works like `Futex::futexWait`.
      
      Removes the ability to customize the idle-timeout clock for `MemoryIdler::futexWait` as a side-effect; the idle-timeout is now a pure duration. Now, the clock used with the idle-timeout is the same as the normal deadline clock, so the idle-timeout clock can be set for `MemoryIdler::futexWaitUntil` by providing a deadline with that clock type. This normally would not matter, but it affects the unit-tests.
      
      Reviewed By: djwatson
      
      Differential Revision: D6681679
      
      fbshipit-source-id: e3cf6e71d7530c5877a834b318b423eb91f71eb9
      b1fe65ff
    • Dave Watson's avatar
      Relax stop_ memory order · 3d2b926a
      Dave Watson authored
      Summary: stop_ can be relaxed everywhere, it implies only an asynchronous signal, not any sort of memory barrier.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D6690079
      
      fbshipit-source-id: 6f193204e1619f9a8adf81db2d46d05954bfbf85
      3d2b926a
    • Yedidya Feldblum's avatar
      Cut the ScopeGuard alias now that we have auto · 653053aa
      Yedidya Feldblum authored
      Summary:
      [Folly] Cut the `ScopeGuard` alias now that we have `auto`.
      
      This form works because of hidden lifetime extension:
      ```lang=c++
      folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ });
      //  ...
      //  guard falls out of scope
      ```
      But this form would not work correctly:
      ```lang=c++
      folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ });
      std::async(std::launch::async, [guard = std::move(guard)] {});
      ```
      Because `folly::ScopeGuard` is an rvalue-reference-to-base.
      We have `auto`, so just remove `folly::ScopeGuard`. This form works correctly:
      ```lang=c++
      auto guard = folly::makeGuard([] { /*...*/ });
      std::async(std::launch::async, [guard = std::move(guard)] {});
      ```
      
      Reviewed By: igorsugak
      
      Differential Revision: D6690070
      
      fbshipit-source-id: 54e32b300d36fce4eb95a59f1828819afe312ec0
      653053aa
    • Yedidya Feldblum's avatar
      Move ScopeGuardImpl and ScopeGuardImplBase into the detail namespace · e61c2150
      Yedidya Feldblum authored
      Summary:
      [Folly] Move `ScopeGuardImpl` and `ScopeGuardImplBase` into the `detail` namespace.
      
      Let them be marked as private implementation details.
      
      Reviewed By: andrewjcg
      
      Differential Revision: D6665317
      
      fbshipit-source-id: 03e8fee6a16338395ec92c582613b053bd9f74ec
      e61c2150
    • Yedidya Feldblum's avatar
      Stop using ScopeGuardImpl in DynamicParser · 5277a636
      Yedidya Feldblum authored
      Summary:
      [Folly] Stop using `ScopeGuardImpl` in `DynamicParser`.
      
      `ScopeGuardImpl` is an impl type that should not be treated as public.
      
      Reviewed By: igorsugak
      
      Differential Revision: D6689835
      
      fbshipit-source-id: aea6c985e40887594c0aeb0c0948fa77c149a89b
      5277a636
  4. 10 Jan, 2018 18 commits
    • Yedidya Feldblum's avatar
      folly::Init, RAII variant of folly::init · 7bf14860
      Yedidya Feldblum authored
      Summary:
      [Folly] `folly::Init`, RAII variant of `folly::init`.
      
      Use it in `main` used by unit-tests.
      
      Reviewed By: ot
      
      Differential Revision: D6566358
      
      fbshipit-source-id: fb8e5a18fc43eb65e2cbeb070d97094bd413bb96
      7bf14860
    • Maged Michael's avatar
      UnboundedQueue: Use hazptr_obj_batch · 2d80d4e0
      Maged Michael authored
      Summary: Manage retirement of removed segments using hazptr_obj_batch in order to reduce the chances of fragmenting related segments across thread local lists of retired objects of many threads, which could lead to unnecessarily high memory usage.
      
      Reviewed By: djwatson
      
      Differential Revision: D6686697
      
      fbshipit-source-id: 0d786c0f9e0bac2c44183ed3da21619e1feb3d52
      2d80d4e0
    • Adam Simpkins's avatar
      logging: fix build error when using gcc with -Wmissing-braces · 79a92dfd
      Adam Simpkins authored
      Summary:
      Since std::array is actually a struct containing an array it technically
      requires double braces around its initializer.  The language allows eliding
      these braces, and clang doesn't complain about only using a single brace, but
      gcc does when using `-Wmissing-braces`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6695289
      
      fbshipit-source-id: 913fcfbea4164a02d001bd2344e340c0b6ee62aa
      79a92dfd
    • Yedidya Feldblum's avatar
      Let Futex import base-class ctors · dcf8a19c
      Yedidya Feldblum authored
      Summary:
      [Folly] Let `Futex` import base-class ctors.
      
      Rather than needing to define ctors and inherit `boost::noncopyable`.
      
      Reviewed By: WillerZ
      
      Differential Revision: D6674054
      
      fbshipit-source-id: 59e0a4815682b227346954fe47c6eda49e3ad62f
      dcf8a19c
    • Maged Michael's avatar
      Add hazptr_obj_batch · 028415ba
      Maged Michael authored
      Summary: Provide capability for custom batching retirement of objects, for example object that belong to the same data structure, to avoid the risk fragmenting related objects across thread local lists of retired objects of many threads, which could lead to unnecessarily high memory usage.
      
      Reviewed By: djwatson
      
      Differential Revision: D6686603
      
      fbshipit-source-id: fadcade73e71170ef1bcec221c4da6f4ddeecff5
      028415ba
    • Yedidya Feldblum's avatar
      Tweak FutexResult comments · e7f26d60
      Yedidya Feldblum authored
      Summary: [Folly] Tweak `FutexResult` comments.
      
      Reviewed By: nbronson
      
      Differential Revision: D6673979
      
      fbshipit-source-id: 1777311cd93d5a83432c4ebb48a8432a1c504ca9
      e7f26d60
    • Yedidya Feldblum's avatar
      Futex::futexWait returns FutexResult · e229101b
      Yedidya Feldblum authored
      Summary: [Folly] `Futex::futexWait` returns `FutexResult`.
      
      Reviewed By: nbronson
      
      Differential Revision: D6673871
      
      fbshipit-source-id: 378c69d8362970e985da31e31d8e9b0179d2917f
      e229101b
    • Yedidya Feldblum's avatar
      Support for all clock types in Futex · 8bfee85e
      Yedidya Feldblum authored
      Summary:
      [Folly] Support for all clock types in `Futex`.
      
      Only `system_clock` and `steady_clock` remain optimal as before, but at least let `Futex` work, even if non-optimally, for all clock types.
      
      Reviewed By: nbronson
      
      Differential Revision: D6673741
      
      fbshipit-source-id: 0a0f778f61b71bea76e12b7fab478e33ce3bbaae
      8bfee85e
    • Yedidya Feldblum's avatar
      Use ptr-to-const in Futex · 0a6bc82e
      Yedidya Feldblum authored
      Summary: [Folly] Use ptr-to-`const` in `Futex`.
      
      Reviewed By: igorsugak
      
      Differential Revision: D6673723
      
      fbshipit-source-id: b828c2284b40ec8166e823eca7725beccd330f87
      0a6bc82e
    • Yedidya Feldblum's avatar
      Fix some copyright lines in folly/detail/ and folly/test/ · b67b22f4
      Yedidya Feldblum authored
      Summary: [Folly] Fix some copyright lines in `folly/detail/` and `folly/test/`.
      
      Differential Revision: D6673878
      
      fbshipit-source-id: 6c060a974bb4d40d0f24a44ebddddf892805c65e
      b67b22f4
    • Yedidya Feldblum's avatar
      Baton support for wait-options · 2ac160c2
      Yedidya Feldblum authored
      Summary: [Folly] Baton support for wait-options
      
      Reviewed By: nbronson
      
      Differential Revision: D6591168
      
      fbshipit-source-id: beca8422ac0daa572fb43c371923a86f199999f9
      2ac160c2
    • Yedidya Feldblum's avatar
      Timed wait operations for spin-only Baton · 3579ddb4
      Yedidya Feldblum authored
      Summary:
      [Folly] Timed wait operations for spin-only `Baton`.
      
      Enables `try_wait_for` and `try_wait_until` for `Baton</* MayBlock = */ false, /*...*/>`.
      
      Reviewed By: nbronson
      
      Differential Revision: D6672153
      
      fbshipit-source-id: 95da07260b21c2b88b8f7bf81cbfcbe5f5099ac0
      3579ddb4
    • Adam Simpkins's avatar
      logging: include file name suffixes in XLOG() category names · d056738b
      Adam Simpkins authored
      Summary:
      Update `getXlogCategoryNameForFile()` to keep the file name suffix (e.g., `.h`
      or `.cpp`) in the category name.  Previously the code had stripped this out.
      However it seems worth leaving it in:
      - This makes it possible to independently control log levels for messages from
        the header file vs the cpp file.
      - This makes the category name logic slightly easier to explain to users.
      
      The documents I added in D6525997 already describe this new category name
      selection behavior.  This change updates the code to match the documented
      behavior.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6690464
      
      fbshipit-source-id: 9af6b549d084bd900f788a08e9213e82579b664a
      d056738b
    • Adam Simpkins's avatar
      logging: add numbered INFO* log level values · 59f59178
      Adam Simpkins authored
      Summary:
      Define INFO0 through INFO9 levels for users that want to have finer-grained
      control over info log messages.
      
      This also renumbers the DBG log levels slightly so that there are exactly 1000
      levels between each major log level step.  This renumbering change should not
      affect any code behavior, since these level values are primarily used in memory
      and aren't saved persistently anywhere.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6690466
      
      fbshipit-source-id: acd499cff6830a1d1b579f295bd4b2bac93b5ada
      59f59178
    • Adam Simpkins's avatar
      logging: rename the `DEBUG` log level to `DBG` · 24d6b776
      Adam Simpkins authored
      Summary:
      I ran into some open source projects that define `DEBUG` as a preprocessor
      macro on the compiler command line.  (They effectively defined it as the
      opposite of `NDEBUG`.)  Doing some Google searches revealed that there are a
      number of projects that appear to use this as a macro.
      
      Therefore this diff renames the `DEBUG` log level enum value to `DBG` to avoid
      potentially conflicting with projects that do use `DEBUG` as a macro name.
      
      I did keep the behavior that `logLevelToString()` returns "DEBUG" for an input
      of `LogLevel::DBG`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6690465
      
      fbshipit-source-id: 35bb1698afb45eb670e60c192f21390cbf09331d
      24d6b776
    • Giuseppe Ottaviano's avatar
      Change the enumerate() example to bind the proxy by reference · 489eeb1c
      Giuseppe Ottaviano authored
      Summary:
      When compiling without optimizations binding the proxy by
      reference is slightly faster (no differences in opt mode), so change
      the documentation to recommend this syntax.
      
      The proxy can still be bound by `auto`, `const auto`, and `const
      auto&`, in all case behaving as expected and with no overhead in opt
      mode. Added a test to make sure these all work.
      
      Reviewed By: yfeldblum, luciang
      
      Differential Revision: D6688958
      
      fbshipit-source-id: 7c6b460a01708786bda7614546fa2e1667f27299
      489eeb1c
    • Giuseppe Ottaviano's avatar
      Improve performance of enumerate() with optimization disabled · 66c782bb
      Giuseppe Ottaviano authored
      Reviewed By: yfeldblum, WillerZ
      
      Differential Revision: D6682606
      
      fbshipit-source-id: 5a203a849e96d3020cf9ad2669451122954c2199
      66c782bb
    • Adriana Libório's avatar
      Fixing typo in sorted_vector_types.h · 80d1c0e1
      Adriana Libório authored
      Summary:
      title
      
      Created from Diffusion's 'Open in Editor' feature.
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: Sushisugre
      
      Differential Revision: D6688367
      
      fbshipit-source-id: 6e2f2d3fcb897fe78c1caef841515856b1f2bd42
      80d1c0e1
  5. 09 Jan, 2018 4 commits
    • Dan Melnic's avatar
      Return if we handle any error messages to avoid unnecessarily calling recv/send · 2a4ad2c8
      Dan Melnic authored
      Summary: Return if we handle any error messages to avoid unnecessarily calling recv/send
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6677314
      
      fbshipit-source-id: 21f724bb2c92b954888ba97bf7820d72decd2775
      2a4ad2c8
    • Dave Watson's avatar
      use in futex · ee1a988d
      Dave Watson authored
      Summary: Use new ParkingLot API in futex.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6595853
      
      fbshipit-source-id: 7024ac1d3e0c5958a651a3e33c1427038bbe7808
      ee1a988d
    • Dave Watson's avatar
      Add a check if max atomic_shared_ptrs is reached. · 6824c36b
      Dave Watson authored
      Summary:
      Batching reference counts reduces the maximum number of atomic_shared_ptrs
      available to the system (and also shared_ptrs).
      
      Add a check, test, and some comments about it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5916291
      
      fbshipit-source-id: 0bbf7b43284d94a304201219883c82b3654c1585
      6824c36b
    • Maged Michael's avatar
      UnboundedBlockingQueue: Adjust segment size · 4591832b
      Maged Michael authored
      Summary: Adjust the segment size of the `UnboundedQueue` to 64 instead of 256, a size more suitable for CPUThreadPoolExecutor::CPUTask elements.
      
      Reviewed By: djwatson
      
      Differential Revision: D6665918
      
      fbshipit-source-id: c34c4fa936ee5c6d6a3dd4489129c936369f3980
      4591832b
  6. 08 Jan, 2018 5 commits
    • Eric Niebler's avatar
      give all folly exception types default visibility · f842b713
      Eric Niebler authored
      Summary: This makes sure that whether folly is statically or dynamically linked, all folly exception types will have exactly one definition, and one set of type information.
      
      Reviewed By: mzlee
      
      Differential Revision: D6671431
      
      fbshipit-source-id: 1c06826a05f87cbf9af747c9abdb5f524744d054
      f842b713
    • Keith Daigle's avatar
      Update cpuid test to expect failure on non intel cpu · 24f2ac23
      Keith Daigle authored
      Summary: Found that testing would fail on aarch64 since mmx is an Intel thing.  Changed it to just check for x64.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6670050
      
      fbshipit-source-id: 6ce4b45bb5ef02d65305636d6ac28be7631ddf1b
      24f2ac23
    • Chad Austin's avatar
      test that _sp includes nul bytes · 3df17628
      Chad Austin authored
      Summary:
      D6617812 wants to build a StringPiece from a literal with an
      embedded nul. Add a test to verify that _sp is suitable for this use
      case.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6651024
      
      fbshipit-source-id: be4fb875762829fdb61c57fa72954fef286e9df0
      3df17628
    • Neel Goyal's avatar
      Use local error buffer in readStoreFromBuffer · 5eda6650
      Neel Goyal authored
      Summary: ERR_error_string will use a static buffer if none is provided.  This is unsafe in threaded envs when we build a string out of it later.  Switch this to use ERR_error_string_n
      
      Reviewed By: yfeldblum, knekritz
      
      Differential Revision: D6664958
      
      fbshipit-source-id: 2071347373ac61ebc28296fa66845cd718172b5e
      5eda6650
    • Yedidya Feldblum's avatar
      Remove gcc-v4.7 support from MemoryIdler · 1374bb3a
      Yedidya Feldblum authored
      Summary:
      [Folly] Remove gcc-v4.7 support from `MemoryIdler`.
      
      As of gcc-v4.8, `std::is_trivial<std::chrono::duration<Rep, Period>>::value` holds. We no longer need any extra support.
      
      Reviewed By: meyering
      
      Differential Revision: D6673517
      
      fbshipit-source-id: f28b2d126f113547ebf36c85f9fa37a5d944d65b
      1374bb3a
  7. 07 Jan, 2018 1 commit
    • Yedidya Feldblum's avatar
      Terminal comma for FutexResult enumerators · 7462c4c2
      Yedidya Feldblum authored
      Summary: [Folly] Terminal comma for `FutexResult` enumerators. Style nit.
      
      Reviewed By: meyering
      
      Differential Revision: D6673523
      
      fbshipit-source-id: abf9f4d3e99bf9a6d3042a49252b1b1190e69b9f
      7462c4c2