1. 08 Nov, 2017 3 commits
    • Andre Pinto's avatar
      Avoid implicitly dropping const modifier · 85ad5f46
      Andre Pinto authored
      Summary: Use const_cast instead of implicitly dropping const modifier.
      
      Reviewed By: reanimus
      
      Differential Revision: D6269200
      
      fbshipit-source-id: 61e1708c88a4139d3fdd9cf89f4ff778d0354bb2
      85ad5f46
    • Andre Pinto's avatar
      Fix oss build · b58cbabb
      Andre Pinto authored
      Summary:
      Include folly/Portability.h in GenerateFingerprintTables, so that
      gflags namespace gets defined.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6265226
      
      fbshipit-source-id: d509dc163564420151de7007ad4336d7e5ef9625
      b58cbabb
    • Igor Sugak's avatar
      fix -Wunused-variable · 78a596f1
      Igor Sugak authored
      Summary:
      Exposed by the latest clang:
      ```lang=bash
      folly/test/FixedStringTest.cpp:52:36: error: unused variable 's' [-Werror,-Wunused-variable]
        constexpr folly::FixedString<42> s{"hello world"};
                                         ^
      folly/gen/test/StringBenchmark.cpp:176:15: error: unused variable 'line' [-Werror,-Wunused-variable]
        StringPiece line(kLine);
                    ^
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6264853
      
      fbshipit-source-id: 5cf4b0a8c99eaa31c2499746c70ddc49fdd73074
      78a596f1
  2. 07 Nov, 2017 6 commits
    • Christopher Dykes's avatar
      Workaround a bug in MSVC · 29ffcc50
      Christopher Dykes authored
      Summary:
      It was broken, now it is fixed.
      https://developercommunity.visualstudio.com/content/problem/145407/incorrect-c3520-within-noexcept-expression-in-alia.html
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6254219
      
      fbshipit-source-id: a03961db97d7ac211103655229c1ea703405826a
      29ffcc50
    • Adam Simpkins's avatar
      logging: set the thread name for the AsyncFileWriter thread · 766b616c
      Adam Simpkins authored
      Summary:
      AsyncFileWriter uses a separate thread to write messages to the file
      descriptor.  This diff makes us call setThreadName() to set the name of this
      thread to `log_writer`.
      
      Reviewed By: bolinfest
      
      Differential Revision: D6238229
      
      fbshipit-source-id: 9c93d80e7ac989e03bc3160bb2f135d67e15c8be
      766b616c
    • Dave Watson's avatar
      Support movable keys · 103ad3da
      Dave Watson authored
      Summary: Use the same trick as the values, so that non-copyable keys can be used in ConcurrentHashMap.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6252711
      
      fbshipit-source-id: f0f168c4eb361d372bdfc3417f32222d66c11aaf
      103ad3da
    • Dave Watson's avatar
      Remove incorrect DCHECKS · 897877b8
      Dave Watson authored
      Summary:
      While the returned iterators are always 'valid' and can be read and iterated from,
      they may still be concurrently erased from the map.  Current erase(iter) has DCHECKS that assert we can always
      erase an iterator, but it may have already been removed.
      
      Reviewed By: davidtgoldblatt
      
      Differential Revision: D6221382
      
      fbshipit-source-id: 70b21f53e2fc3daa126df4fb60bc5d3ecb253c71
      897877b8
    • Giuseppe Ottaviano's avatar
      Allow to specify per-priority capacities in PriorityLifoSemMPMCQueue · a77fea17
      Giuseppe Ottaviano authored
      Summary: The `THROW` behavior of `LifoSemMPMCQueue` is unsafe when calling `join()`, because the queue may be full and `join()` will fail to enqueue the poisons. To work around this we can use `PriorityLifoSemMPMCQueue` and dedicate `LO_PRI` to the poisons, but there's no reason that the low priority queue should have the same size as the normal priority. Add a constructor to be able to specify different sizes.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6257017
      
      fbshipit-source-id: c75f33c38fcdad646ba1499bcd434ab65711250c
      a77fea17
    • Yedidya Feldblum's avatar
      crange, and range const overloads · 0718262d
      Yedidya Feldblum authored
      Summary:
      [Folly] `crange`, and `range` `const` overloads.
      
      Instead of using universal reference for `range` overloads, bifurcate explicitly between `&` and `const&` overloads. The `&` overloads return `Range<T*>` while the `const&` overloads return `Range<T const*>`.
      
      Add `crange` overloads, which may accept non-`const` arguments but will return `Range<T const*>` results anyway.
      
      Reviewed By: ot
      
      Differential Revision: D6242038
      
      fbshipit-source-id: bc373c3288ea88792f04b49a372262d12204b586
      0718262d
  3. 06 Nov, 2017 3 commits
    • Yedidya Feldblum's avatar
      Move folly/LifoSem.h · c593d8ed
      Yedidya Feldblum authored
      Summary: [Folly] Move `folly/LifoSem.h` to `folly/synchronization/`.
      
      Reviewed By: meyering
      
      Differential Revision: D6245444
      
      fbshipit-source-id: 14ffa012fa92b8c6aaf5900c930156894a492003
      c593d8ed
    • Eric Niebler's avatar
      Value-initialize the Data union member of folly::Function · d6a27b28
      Eric Niebler authored
      Summary: The Data field was not getting value-initialized, leading compilers to complain when value-initializing const folly::Function objects.
      
      Reviewed By: yfeldblum, ot
      
      Differential Revision: D6241712
      
      fbshipit-source-id: 99ce7f6016f6e7d16b1cff7aa51b7bef53ec592d
      d6a27b28
    • Phil Willoughby's avatar
      Mark constructing an Unexpected as cold · ad3fe1dd
      Phil Willoughby authored
      Summary:
      By marking the main constructors of `Unexpected` cold we are telling the compiler that we don't expect to execute them often. This can improve the locality and performance of the `Expected` branch, and reduce the code-size for the `Unexpected` branch.
      
      The constructors we have marked cold here are only the ones used to originate an `Unexpected`. We don't mark the copy- move- or conversion-constructors as `cold` because they will typically be used in error-handling branches and it is not correct to say that they are colder than their surroundings in that case. Note that the entire error-handling branch is likely to be deduced to be cold because we told the compiler that it is likely that hasValue() is true and hasError() is false.
      
      Because `makeUnexpected` unconditionally invokes one of these cold constructors it will inherit the property of being cold.
      
      The GCC function attribute reference, which describes what `cold` means, is here: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6234305
      
      fbshipit-source-id: 6876073e92ce54936ba7152175d76be653f5f463
      ad3fe1dd
  4. 05 Nov, 2017 1 commit
    • Yedidya Feldblum's avatar
      Move folly/Functional.h · 05a56e4c
      Yedidya Feldblum authored
      Summary: [Folly] Move `folly/Functional.h` to `folly/lang/RValueReferenceWrapper.h`.
      
      Reviewed By: Orvid
      
      Differential Revision: D6242160
      
      fbshipit-source-id: a8ec42106cfe0ea617c87d382694d5eb2f0f61a0
      05a56e4c
  5. 04 Nov, 2017 3 commits
    • Yedidya Feldblum's avatar
      constexpr_clamp · 6ca1c3b6
      Yedidya Feldblum authored
      Summary:
      [Folly] `constexpr_clamp`.
      
      Like `std::clamp` (C++17).
      
      Reviewed By: Orvid
      
      Differential Revision: D6236825
      
      fbshipit-source-id: 0f6c5dc9a955b148021ee6ed3e86201b53ae090c
      6ca1c3b6
    • Lee Howes's avatar
      Make SemiFuture::via throw on nullptr executor. · 36ae3c3e
      Lee Howes authored
      Summary: Make SemiFuture throw if no executor provided to via because in that situation the deferred work will never run.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6233233
      
      fbshipit-source-id: 43b642c46cc0be80b1f13c03bdaf20b8038acec2
      36ae3c3e
    • Yedidya Feldblum's avatar
      Move folly/SafeAssert.h · 2e1b273c
      Yedidya Feldblum authored
      Summary: [Folly] Move `folly/SafeAssert.h` to `folly/lang/`.
      
      Reviewed By: Orvid
      
      Differential Revision: D6230421
      
      fbshipit-source-id: 0086cd6fedd4ce0e7a4d5302a41153ec1a502e74
      2e1b273c
  6. 03 Nov, 2017 6 commits
    • Lee Howes's avatar
      Parameter order · 4780814a
      Lee Howes authored
      Summary: Fix for function parameter order that shows up in opt build on later diff.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D6237125
      
      fbshipit-source-id: fbb7be2c70b32203c658fc239cd74164e01fa1ca
      4780814a
    • Louis Dionne's avatar
      Nitpick: fix typo in name · 2e395f36
      Louis Dionne authored
      Summary: Closes https://github.com/facebook/folly/pull/705
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6234351
      
      Pulled By: Orvid
      
      fbshipit-source-id: e71bb3882c783a47ace4d08f134b2e450aaabb6b
      2e395f36
    • Dan Melnic's avatar
      Expose the zerocopy buf ID, change the AsyncSocket fd constructor to accept... · 15fd86fa
      Dan Melnic authored
      Expose the zerocopy buf ID, change the AsyncSocket fd constructor to accept the id, Buff->Buf, make the cmsghdr methods private
      
      Summary: Expose the zerocopy buf ID, change the AsyncScokey fd constructor to accept the id, Buff->Buf, make the cmsghdr methods private
      
      Reviewed By: djwatson
      
      Differential Revision: D6221324
      
      fbshipit-source-id: d0fc4937adf6cf5790d11e406ffd3ec64c558b9c
      15fd86fa
    • Lee Howes's avatar
      Missing Future/SemiFuture->Value conversion check · 514d9cb9
      Lee Howes authored
      Summary: Conversion check was lost in an earlier refactor. This meant that SemiFuture could be accidentally converted to Future through the value constructor. This should be disabled.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6214526
      
      fbshipit-source-id: 3fc2d026ec6062b38b9500c8adf3eee12c0f2693
      514d9cb9
    • Yedidya Feldblum's avatar
      Alias std::launder when it is available · 61ba3c11
      Yedidya Feldblum authored
      Summary: [Folly] Alias `std::launder` when it is available.
      
      Reviewed By: Orvid
      
      Differential Revision: D6221443
      
      fbshipit-source-id: 33136a8744a39db01fb05513d5ed5476ea67559a
      61ba3c11
    • Eric Niebler's avatar
      don't try to run the poly tests on gcc-4.9. they will fail. · a1d0f15a
      Eric Niebler authored
      Summary: gcc-4.9 does not support features that Poly needs. Disable the tests on that platform.
      
      Reviewed By: meyering
      
      Differential Revision: D6211674
      
      fbshipit-source-id: 289f029122a45b0f9ec740c62b1faaafb51dcab5
      a1d0f15a
  7. 02 Nov, 2017 5 commits
    • Phil Willoughby's avatar
      Make Expected presume it has a value and not an Error · 8b37be00
      Phil Willoughby authored
      Summary: This only affects instruction ordering in GCC-compatible compilers to make the value-having branch preferred.
      
      Reviewed By: davidtgoldblatt, nbronson, yfeldblum
      
      Differential Revision: D6223188
      
      fbshipit-source-id: 57c69b88eda7ee769912874921c45b47ec7a38de
      8b37be00
    • Dan Melnic's avatar
      Change kDefaultZeroCopyThreshold to 0 to avoid a regression and avoid a... · 6b8138f9
      Dan Melnic authored
      Change kDefaultZeroCopyThreshold to 0 to avoid a regression and avoid a failure while running as not root
      
      Summary:
      Change kDefaultZeroCopyThreshold to 0 to avoid a regression when using a buffer chain that exceeds 32K but each buffer is small.
      Change the benchmark to set it's own threshold. Also use calloc vs malloc (in the benchmark only) to get around some weird kernel interaction on non zero copy enabled systems - 2 back to back tests report very different results.
      
      Reviewed By: djwatson
      
      Differential Revision: D6112299
      
      fbshipit-source-id: 3895d3ece2925c4626284ff364495708293edc3e
      6b8138f9
    • Andrey Ignatov's avatar
      Introduce non-throwing try* methods for IPAddress{,V4,V6}. · 30c1e1dc
      Andrey Ignatov authored
      Summary:
      Now there is no interface to create `IPAddress{,V4,V6}` from a string or
      `ByteRange` that doesn't throw. All available static methods throw
      `IPAddressFormatException`.
      
      It has a few disadvantages:
      
      == 1. It's unsafe ==
      
      Caller is not forced to catch exception, it's very easy to write
      `IPAddress(potentiallyInvalidString)` and discover that it can throw when it's
      already in prod.
      
      == 2. It's inconvenient ==
      
      if caller is aware about exception, (s)he's forced to write `try {} catch` that
      is inconvenient and leads to code like this:
        folly::IPAddress taskIp;
        try {
          taskIp = folly::IPAddress(kv.second.taskIp);
        } catch (const folly::IPAddressFormatException&) {
          // Error handling ..
        }
        // Use IP ..
      
      == 3. It's expensive ==
      
      Amended benchmark shows that `IPAddress` constructor is ~10 times slower when a
      string with invalid IP is passed to it.
      
       ---
      
      The diff introduces two non-throwing interfaces for all tree flavors of `IPAddress`:
      
      `tryFromString()` tries to create IP address from string and returns either
      corresponding IP address or `enum class IPAddressFormatError` using
      `folly::Expected`.
      
      `tryFromBinary()` does same thing but for `ByteRange` input.
      
      The code can be as short as:
        if (auto maybeIp = IPAddress::tryFromString(ipStr)) {
          // Use maybeIp.value() ..
        }
      
      The `try` prefix is chosen to be consistent with other interfaces in folly,
      e.g. `to` and `tryTo`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6211182
      
      fbshipit-source-id: f27cf90997c100a5fd42138e66ff9bb172204c20
      30c1e1dc
    • Yedidya Feldblum's avatar
      Refactor is_simple_allocator and callers · 723d4d3f
      Yedidya Feldblum authored
      Summary:
      [Folly] Refactor `is_simple_allocator` and callers.
      
      * Swap order of template parameters.
      * Do decaying in the callers instead.
      * Do a direct invocability test, rather than an indirect test of whether the allocator has a method `destroy` with the expected signature.
      
      Reviewed By: ericniebler
      
      Differential Revision: D6184062
      
      fbshipit-source-id: aec32e6e323b8c6023b94c258ab2bcddd8c53e09
      723d4d3f
    • Christopher Dykes's avatar
      Fix folly::Function under C++17 exception specifier rules · 1bdec475
      Christopher Dykes authored
      Summary: Under C++17's exception specifier rules (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0012r1.html) we need additional specializations to achieve the desired effect.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6214359
      
      fbshipit-source-id: a007c2fcea1496bdfe4fdf923b39c1611c6ad9bc
      1bdec475
  8. 01 Nov, 2017 8 commits
    • Ognjen Dragoljevic's avatar
      Make associative container out-of-range exception provide missing key · e75cf21f
      Ognjen Dragoljevic authored
      Summary:
      When the key is missing, the standard associative containers throw an exception like `unordered_map::at: key not found`. That's nice, but it would be even better if we would actually know what key is missing. This is not an issue when one is accessing the container directly, but when that access happens several levels deep, such as here within folly formatting logic, we have no way of knowing what key was missing. This poses some difficulties in presenting error to the user.
      This change makes folly format throw a subclass of `std::out_of_range` exception on a missing key when a string keyed associative container is used for providing parameters. That subclass stores the actual key used so it can be accessed in the exception handler. Existing callers can still catch `std::out_of_range` so they should be unaffected by this change.
      
      Reviewed By: ot, yfeldblum
      
      Differential Revision: D6202184
      
      fbshipit-source-id: b8a6740aaccc5d8914ad7d099c8b901427f00083
      e75cf21f
    • Lee Howes's avatar
      Quick comment on DE to clarify use cases and lack of thread safety. · 968945c5
      Lee Howes authored
      Summary: (Note: this ignores all push blocking failures!)
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6212919
      
      fbshipit-source-id: b066d99e13e97cbab489132bcb91872ed4407f81
      968945c5
    • Yedidya Feldblum's avatar
      Fix unsynchronized accesses in IOThreadPoolExecutor::getEventBase · 6e142c0d
      Yedidya Feldblum authored
      Summary:
      [Folly] Fix unsynchronized accesses in `IOThreadPoolExecutor::getEventBase`.
      
      `getEventBase` may be invoked concurrently from two threads - RMWs to `nextThread_` must be synchronized with each other.
      
      `getEventBase` may be invoked concurrently with `setNumThreads` - the former's reads of `threadList_.vec_` must be synchronized with the latter's writes to it.
      
      Reviewed By: kennyyu
      
      Differential Revision: D6206916
      
      fbshipit-source-id: 8bfae158effb5896ab478d0c20310293b037c892
      6e142c0d
    • Eric Niebler's avatar
      add a complete example to poly's docs, fix typos and think-o's · 9216d96a
      Eric Niebler authored
      Summary: Address doc criticisms
      
      Reviewed By: Orvid
      
      Differential Revision: D6210376
      
      fbshipit-source-id: fee11cef1c407b092f891a97f94271a81d3718b8
      9216d96a
    • Alisson Gusatti Azzolini's avatar
      Fix OSS's "make check" · e6877652
      Alisson Gusatti Azzolini authored
      Reviewed By: yfeldblum
      
      Differential Revision: D6182541
      
      fbshipit-source-id: 31d255819df1f97b13e475903c0627a1ac96b516
      e6877652
    • Maged Michael's avatar
      Add integrated reference counting · 571e7b97
      Maged Michael authored
      Summary:
      Add support for reference counting integrated with the internal structures and operations of the hazard pointer library. The operations are wait-free.
      The advantages of this approach over combining reference counting with hazard pointers externally are:
      (1) A long list of linked objects that protected by one reference can all be reclaimed together instead of going through a potentially long series of alternating reclamation and calls to retire() for descendants.
      (2) Support for iterative deletion as opposed to potential deep recursion of alternating calls to release reference count and object destructors.
      
      Reviewed By: djwatson
      
      Differential Revision: D6142066
      
      fbshipit-source-id: 02bdfcbd5a2c2d5486d937bb2f9cfb6f192f5e1a
      571e7b97
    • Andrii Grynenko's avatar
      Clear frame cache when activating a fiber · 3ace27b8
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D6207160
      
      fbshipit-source-id: 57468c9d05cdb3ee6e1d10a3a254a5d1bfddc36f
      3ace27b8
    • Yedidya Feldblum's avatar
      A macro for creating member-invoke traits · 3e4e8fe8
      Yedidya Feldblum authored
      Summary:
      [Folly] A macro for creating member-invoke traits.
      
      The macro creates a specialized traits container with member types and aliases mimicking `std::invoke_result` and the related traits types and aliases.
      
      Reviewed By: aary
      
      Differential Revision: D6195087
      
      fbshipit-source-id: 07c2bbab6cccb04dc8ff12e20923351e8f38abfd
      3e4e8fe8
  9. 31 Oct, 2017 5 commits
    • Lee Howes's avatar
      Adding DeferredExecutor to support deferred execution of tasks on a future... · 6e7e5a64
      Lee Howes authored
      Adding DeferredExecutor to support deferred execution of tasks on a future returned from an interface.
      
      Summary: This adds a DeferredExecutor type that is boostable, which means that it follows the expectation we expect for C++20 that .then and get will trigger boost-blocking behaviour and ensure work makes progress. Unlike discussions for C++ this adds boost blocking to folly only in the specific case of deferring work to run on the caller's executor, to avoid the necessity to pass an executor into a library purely to ensure that finalisation work and future completion occor on a well-defined exewcutor.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D5828743
      
      fbshipit-source-id: 9a4b69d7deaa33c3cecd6546651b99cc99f0c286
      6e7e5a64
    • Martin Martin's avatar
      Remove unused field or local var. · 1071e662
      Martin Martin authored
      Summary: Remove unused field or local var.
      
      Reviewed By: terrelln
      
      Differential Revision: D6199120
      
      fbshipit-source-id: 616a2b2549c37bcb57d2f8c530b26089f24c2973
      1071e662
    • Teng Qin's avatar
      Improve folly::RequestContext onSet and onUnset efficiency · b82902de
      Teng Qin authored
      Summary:
      In previous discussions, it has been pointed out that `folly::RequestContext::setContext` consumes considerable amount of CPU cycles in production environments. After some investigation, we thought that might be caused by looping over all `RequestData` instances can calling the virtual `onSet` and `onUnset` callback of them. Both the iteration and invoking virtual methods are not cheap.
      
      As you can see from this change, most of the derived classes of `RequestData` don't override the `onSet` and `onUnset` methods. Mostly likely they are only used for per-Request tracking. So the natural idea is to skip those instances when iterating and avoid the unnecessary virtual method invoke.
      
      I have explored the solution to dynamically examine if the `RequestData` instance added has `onSet` and `onUnset` method overridden. That is possible with GCC's PMF extension, but not [[ http://lists.llvm.org/pipermail/llvm-bugs/2015-July/041164.html | for Clang ]] and probably many other compilers. This definitely won't be very good for `folly`'s probability, even if we gate it by compiler flags.
      
      Therefore, this Diff adds the `hasCallback` method to `RequestData` class indicating whether the instance would have `onSet` and `onUnset` overridden. To make it clear to users that they need to correctly override it in order for their `onSet` and `onUnset` callback to work, making it abstract so that user must override it to something and would aware of that.
      
      Also made some improvements on documentation.
      
      Reviewed By: myreg
      
      Differential Revision: D6144049
      
      fbshipit-source-id: 4c9fd72e9efaeb6763d55f63760eaf582ee4839e
      b82902de
    • Teng Qin's avatar
      Improve folly::RequestContext::get() · 3efddaff
      Teng Qin authored
      Summary:
      Since `folly::RequestContext::get()` returns raw pointer, it could directly use the reference returned by `getStaticContext()`
      I don't expect this to make much of a difference, just tiny improvements
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6153353
      
      fbshipit-source-id: 1c41d4fc259aa5cb3e69e50ed24bed1ba9caf6c3
      3efddaff
    • Alex Guzman's avatar
      Add utility function for loading certificates from a buffer · ecd0fb38
      Alex Guzman authored
      Summary: Adds a function that reads certificates in from a buffer and returns them as a vector of X509 pointers.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6133332
      
      fbshipit-source-id: eaaaffcbd4d03f37d9d5b4c99a52b0d968b163ba
      ecd0fb38