1. 16 Feb, 2017 4 commits
    • Christopher Dykes's avatar
      Adjust a few things to avoid triggering warnings under MSVC · dfc2add7
      Christopher Dykes authored
      Summary: This includes both unused parameters (W4100) and conditional expression is constant (W4127).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4525057
      
      fbshipit-source-id: 7c057dbe239d02fa2e3ce96373d53814591994ec
      dfc2add7
    • Christopher Dykes's avatar
      Use std::this_thread::yield rather than sched_yield · 79b78eaa
      Christopher Dykes authored
      Summary: They do the same thing, and the first is portable.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4569649
      
      fbshipit-source-id: db0434766f674a7789d6e59335e122b4d2131e06
      79b78eaa
    • Maged Michael's avatar
      Fix data race in Futex<EmulatedFutexAtomic> · eab7000d
      Maged Michael authored
      Summary: Fixed a data race between an atomic store by the waker and a nonatomic memcpy by the waiter.
      
      Reviewed By: nbronson
      
      Differential Revision: D4572410
      
      fbshipit-source-id: 3982ca433e0f628636916516e35aeb7738ae030f
      eab7000d
    • Lovro Puzar's avatar
      Add AtomicIntrusiveLinkedList::reverseSweep() · f54a0bdb
      Lovro Puzar authored
      Summary: In D4558451 I want to pull elements off an atomic list onto a thread-local (single-consumer) vector and pop to get elements in insertion order.  A sweep that provides elements in LIFO order will avoid a redundant pair of list reversals.
      
      Reviewed By: nbronson
      
      Differential Revision: D4564816
      
      fbshipit-source-id: 38cf50418e6afe0be3eec96ce85d571c65f06d7e
      f54a0bdb
  2. 15 Feb, 2017 3 commits
    • Philip Pronin's avatar
      optimize EliasFanoEncoder::defaultNumLowerBits · b49a44c4
      Philip Pronin authored
      Summary:
      `defaultNumLowerBits` is heavily used during PL encoding with
      optimally-partitioned EF. This diff improves its performance by 3.5x by
      avoiding expensive 64-bit division.
      
      Reviewed By: ot, luciang
      
      Differential Revision: D4564615
      
      fbshipit-source-id: 4521d3c05f19573cd2c84f702fcfeaace5f98e77
      b49a44c4
    • Phil Willoughby's avatar
      Replace the future-splitting system · bb76b0f7
      Phil Willoughby authored
      Summary:
      The previous mechanism in SharedPromise doesn't work if the lifetime of the
      SharedPromise object ends before the Future which it was splitting is
      completed.
      
      This variation on the same theme doesn't have that problem.
      
      Reviewed By: spacedentist
      
      Differential Revision: D4339670
      
      fbshipit-source-id: f619762bff1390481715575b3e638ec26b5c4edd
      bb76b0f7
    • Anton Likhtarov's avatar
      Fix undefined behaviour · 1ce2015a
      Anton Likhtarov authored
      Summary: memcpy's src cannot be nullptr even if the size is 0.
      
      Reviewed By: djwatson
      
      Differential Revision: D4560100
      
      fbshipit-source-id: 37cd3ed73f902a136f711a5c1a918258f94d1063
      1ce2015a
  3. 14 Feb, 2017 2 commits
  4. 11 Feb, 2017 1 commit
    • Adam Simpkins's avatar
      add Range constructors from std::array · 60b6e844
      Adam Simpkins authored
      Summary:
      Add explicit constructors to create Range objects referring to the contents of
      a std::array.
      
      D4165608 previously added a folly::range() factory function to create Ranges
      around const arrays.  However, it did not support non-const arrays.  However,
      providing this as a constructor seems better.  This new constructor does not
      appear ambiguous with any existing constructors, and a constructor allows for
      more natural support of non-const arrays: the caller can explicitly indicate
      if they want to construct a Range to const or non-const data in this case.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4523515
      
      fbshipit-source-id: c1a262f9e8f76907d87d80b03f252576506e70ab
      60b6e844
  5. 10 Feb, 2017 3 commits
    • Andrii Grynenko's avatar
      Minor GDB script fix · e1a26ff9
      Andrii Grynenko authored
      Reviewed By: lbrandy
      
      Differential Revision: D4544705
      
      fbshipit-source-id: d60f2026d31c94e020df51f8c887b995986ddcd7
      e1a26ff9
    • Jack Montgomery's avatar
      changed Synchronized.md to reflect SharedMutex as default · 78443c5a
      Jack Montgomery authored
      Summary: folly/docs/Synchronized.md now reflects the fact that SharedMutex is default mutex for Synchronized
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4529851
      
      fbshipit-source-id: b3b8eafe908ba92e3629392fbc4b856b5a99b658
      78443c5a
    • Andrew Krieger's avatar
      Detect identity conversion in toDynamic · 6e4f4207
      Andrew Krieger authored
      Summary:
      D4499520 added typedefs to `dynamic` which made it start matching
      tests for ranges/containers. However, the typedefs are unconditional on the
      actual contents of the `dynamic`. This made toDynamic(dynamic) select the
      range-based conversion operator, always, which immediately asserts when
      trying to do range-based iteration over an Object or a primitive. Add tests
      to the converters that enable/disable depending on whether the object is
      already a `dynamic` and early-out in that case.
      
      Reviewed By: mzlee
      
      Differential Revision: D4538617
      
      fbshipit-source-id: f3a5aafab07946a221dcead782fc27de51afa0a6
      6e4f4207
  6. 09 Feb, 2017 4 commits
    • Den Raskovalov's avatar
      add folly:hasher<bool> · 3751f5de
      Den Raskovalov authored
      Summary:
      hasher<bool> is a trivial thing, but it is useful, if we implement a hash function for a class by writing something like:
        return folly::Hash()(boolField1_, boolField2_, intField3_, boolField4_, someField5_)
      
      Reviewed By: ot
      
      Differential Revision: D4535563
      
      fbshipit-source-id: 5e6672c2eeaebbbac80a8a066a6a0ec4838810f4
      3751f5de
    • Andrii Grynenko's avatar
      Add keepAlive() mechanism · 53367378
      Andrii Grynenko authored
      Summary:
      EventBase and VirtualEventBase already had a loopKeepAlive() mechanism, which enabled libraries to prevent EventBase/VirtualEventBase from being destroyed until all keep-alive tokens were released.
      
      This change adds generic keepAlive() support into folly::Executor. folly::Executors which don't support keep-alive mechanism yet, will just return a no-op KeepAlive token.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4516649
      
      fbshipit-source-id: 869779621c746cb14d985aa73bc4536859914c03
      53367378
    • Phil Willoughby's avatar
      Benchmark string copying via the formatter · cfe87b2e
      Phil Willoughby authored
      Summary:
      Using the formatter is always much slower than using the copy constructor (News at 11).
      
      Comparing the two idioms for formatting out a single string input:
      * the unsafe method (`format(theString)`) is (annoyingly) fastest for small strings; probably because cache-hits dominate the need to inspect every character to see if it is `{` or `}`
      * the safe method (`format("{}",theString)`) is fastest on large strings (crossover at roughly 256 bytes)
      * there isn't a lot in it between 64 and 512 bytes.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4423088
      
      fbshipit-source-id: 7f8590653ab33fe62887a506ea79a43989fbfb29
      cfe87b2e
    • Andrew Krieger's avatar
      Non-const `dynamic` iterators · 73182f6e
      Andrew Krieger authored
      Summary:
      Add non-const iterators corresponding to existing iterator types
      where it makes sense.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4499520
      
      fbshipit-source-id: dc4ec583d3da1c6701805b30b25389fbf9311a7c
      73182f6e
  7. 08 Feb, 2017 2 commits
    • Sebastian Messmer's avatar
      Specialise std::hash for folly::Optional · c141f6ec
      Sebastian Messmer authored
      Summary: This allows using folly::Optional<T> in std::unordered_map and std::unordered_set.
      
      Reviewed By: luciang
      
      Differential Revision: D4469938
      
      fbshipit-source-id: b86b1a4510379b337e9de83471a4aafce6d5a6cb
      c141f6ec
    • Ameya Limaye's avatar
      Throw custom exception type when ABD fails a result because some other token did not call dispatch · bcbc4ff5
      Ameya Limaye authored
      Summary:
      Throw custom exception type when ABD fails a result because some other token did not call dispatch:
      - This is useful because the caller can catch this exception and discard it if they find some other exception
      - The custom exception does not give an indication of the problem. The other exception/s thrown will do that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4395742
      
      fbshipit-source-id: be80f66b1297e9faf625a2fb087590a7d0a9335d
      bcbc4ff5
  8. 07 Feb, 2017 3 commits
    • Christopher Dykes's avatar
      Make a few coersions to bool explicit · 0e4a41d0
      Christopher Dykes authored
      Summary: MSVC has warning 4800 which is triggered on implicit coercions to `bool` when not in use as the condition to a control-flow statement.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4518465
      
      fbshipit-source-id: 858ab9e68215a2a667cb3ea55daf51b74368174d
      0e4a41d0
    • Phil Willoughby's avatar
      Modify BaseFormatter to help static analysers · 11505903
      Phil Willoughby authored
      Summary:
      This decouples the format-string-parser from the storage of the arguments to be
      formatted: a static analyser can now define a class which derives from
      `BaseFormatter` with no storage and use `BaseFormatter::operator()` to verify
      the syntax of the format string and determine which arguments will be
      referenced.
      
      This method of allowing overrides is resolved at compile time; the benchmarks
      confirm that there is no run-time difference.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4507689
      
      fbshipit-source-id: f109d81ae54dc074ac363720ef6e565520435d26
      11505903
    • Phil Willoughby's avatar
      Run clang-format over Format*.h · 9773e441
      Phil Willoughby authored
      Summary:
      Changes are planned, this will make it easier for the new code to look good
      without making the older code look weird.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4514839
      
      fbshipit-source-id: 43f8cd7d85901e1915cc434a0f4b5fd6bce1ec7a
      9773e441
  9. 06 Feb, 2017 2 commits
    • Christopher Dykes's avatar
      Support compiling in C++14 mode · 3259ce0e
      Christopher Dykes authored
      Summary:
      The rest of Folly isn't dependent on C++17 mode in MSVC, so modify this to support not having it enabled.
      This will make adoption easier as C++17 mode acts on the things the standard says are removed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4509919
      
      fbshipit-source-id: f4644f5f5ba78de8ab5192b89ac6320767b51084
      3259ce0e
    • Sven Over's avatar
      execute callbacks as rvalue references · 8898db44
      Sven Over authored
      Summary:
      Callable objects may implement a separate `operator()` for when
      they are called as rvalue references. For example, `folly::partial`
      will move captured objects to the function call when invoked as
      rvalue reference. That allows e.g. to capture pass a `unique_ptr`
      to `folly::partial` for a function that takes a `unique_ptr` by
      value or rvalue-reference.
      
      Callbacks for `folly::Future`s are only ever executed once. They
      may consume captured data. If the callback is an object that
      implements a `operator()() &&`, then that one should be invoked.
      
      This diff makes sure, callbacks passed to `folly::Future` are
      invoked as rvalue references.
      
      Reviewed By: ericniebler, fugalh
      
      Differential Revision: D4404186
      
      fbshipit-source-id: 9f33e442a634acb8797183d3d869840d85bd5d15
      8898db44
  10. 04 Feb, 2017 2 commits
    • Andrey Ignatov's avatar
      Expose testing callbacks from AsyncSocketTest2. · ef2e3d4b
      Andrey Ignatov authored
      Summary:
      `TestConnectionEventCallback` and `TestAcceptCallback` are very handy and can
      be used in other tests outside folly. Specifically I'm going to use them in
      `ConnectHookTest`. It'll also allow to avoid copy/paste in `TransparentTlsTest`.
      
      Reviewed By: plapukhov
      
      Differential Revision: D4507461
      
      fbshipit-source-id: dfaa97e26036ebb11da17a53d4a73431a295f4d4
      ef2e3d4b
    • Matt Glazar's avatar
      Fix environ enumeration on Apple platforms · c847b1b4
      Matt Glazar authored
      Summary:
      environ is documented to not work very well from .dylib-s (dynamic libraries) on macOS. Use the _NSGetEnviron function instead to get a pointer to environ.
      
      <crt_externs.h> is missing from some iOS SDKs, so forward-declare _NSGetEnviron in such cases.
      
      Reviewed By: Orvid, mzlee
      
      Differential Revision: D4491044
      
      fbshipit-source-id: 886d19bdd63dea14225992446b7ba132faf35054
      c847b1b4
  11. 03 Feb, 2017 3 commits
    • Xuli Liu's avatar
      Expose more functions/constructors on BucketedTimeSeries · c10a6640
      Xuli Liu authored
      Summary: Currently BucketedTimeSeries does not expose enough functions to allow assessing its data, therefore there is no way to do serialization/deserialization. Adding functions/constructors to support this.
      
      Reviewed By: simpkins
      
      Differential Revision: D4500075
      
      fbshipit-source-id: 656ac8a208547d8d3fadf9ea150606b6e74775c9
      c10a6640
    • Mark Logan's avatar
      Add ContainerT&& ctors to sorted_vector_map and sorted_vector_set. · b90498bc
      Mark Logan authored
      Summary:
      Add ContainerT&& ctors to sorted_vector_map and sorted_vector_set,
      to support more efficient bulk-construction of these containers. With the
      prior constructors, the only way to do bulk-construction efficiently was
      by using the iterator constructors with a pre-sorted range. If you didn't
      have a presorted range, you would need to make a temporary container in
      order to get a sorted range. Repeatedly calling insert() without a sorted
      range is quadratic, hence not an option.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4491299
      
      fbshipit-source-id: 041c546578f44ee6928c5506e8d8191092143b12
      b90498bc
    • Mark Logan's avatar
      Fix worst-case quadratic behavior of iterator constructors and range insert() · 3ffcb010
      Mark Logan authored
      Summary:
      The iterator constructors and the range insert() method previously
      had quadratic runtime if given an unsorted range. This is now fixed. We
      append the entire range to the container, sort that subrange, and merge it
      into the already-sorted container. Sorting and merging is skipped when possible.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4493534
      
      fbshipit-source-id: e6d73b5c19e374001f9e340ff527c5257bef2ca3
      3ffcb010
  12. 02 Feb, 2017 2 commits
    • Pádraig Brady's avatar
      Fix build failure with GCC 5 · 30db459f
      Pádraig Brady authored
      Summary:
      GCC 5 doesn't recognize LOG(FATAL) as [[noreturn]],
      so remove [[noreturn]] to avoid that warning and build failure.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4484625
      
      fbshipit-source-id: ca129ca3a52239becd7d80f99107e64745bf8838
      30db459f
    • Christopher Dykes's avatar
      Correct the API of some functions in the portability headers · 23688fa8
      Christopher Dykes authored
      Summary: They were based on the signatures of the original functions as defined by MSVC. They should be based on the signatures as defined by Posix instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4471711
      
      fbshipit-source-id: 8a6fd60ba2b326ca57058c119fc77c46f1d21d10
      23688fa8
  13. 01 Feb, 2017 4 commits
    • Yedidya Feldblum's avatar
      Assorted cleanups for folly/portability/BitsFunctexcept.h · 55e591f9
      Yedidya Feldblum authored
      Summary: [Folly] Assorted cleanups for `folly/portability/BitsFunctexcept.h`.
      
      Reviewed By: Orvid, smeenai
      
      Differential Revision: D4492264
      
      fbshipit-source-id: 5e85ac2ad96ef84627cc5473ec0b16c4c9b5da26
      55e591f9
    • Scott Michelson's avatar
      MPMCQueue Wrapper with priorities · cf24f985
      Scott Michelson authored
      Summary: In many cases where MPMCQueue would be used, it's useful to be able to prioritize requests. This implements a thin wrapper on MPMCQueue to accomplish this (albeit in a bit of a memory inefficient way)
      
      Reviewed By: haijunz
      
      Differential Revision: D4465498
      
      fbshipit-source-id: 6630b80ccf3138b5c135e7f7f281133b37d82b4d
      cf24f985
    • Christopher Dykes's avatar
      Swap a few APIs to reduce sign and implicit truncations required to work with it · 41365ea6
      Christopher Dykes authored
      Summary: This results in a more uniform API within Folly, allowing for a more uniform API to use outside of Folly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4471471
      
      fbshipit-source-id: f798a6498bd1a05ed12adea362ff4aedd25789ee
      41365ea6
    • Christopher Dykes's avatar
      Use std::chrono::high_resolution_clock for folly::Benchmark · e0b75e77
      Christopher Dykes authored
      Summary: `clock_gettime(CLOCK_REALTIME)` is based on `std::system_clock` on Windows, but that only has a resolution that's the same as `FILETIME` (100s of nanoseconds), so modernize things and use `std::chrono::high_resolution_clock` which is intended for this purpose.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4476671
      
      fbshipit-source-id: 3db1debc8f408f689b5c9fe1966a72b8dad4da93
      e0b75e77
  14. 31 Jan, 2017 3 commits
    • Igor Adamski's avatar
      FunctionScheduler - set running_ when it has actually started running · b6916a3a
      Igor Adamski authored
      Summary:
      When start() throws because of reasons (in my case it was std::system_error("Resource temporarily unavailalble") coming from std::thread constructo)
      and during the exception propagation we will have to destroy FunctionScheduler then
      thread_.join() in shutdown will throw again.
      This diff sets running_ after the thread is created.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4469816
      
      fbshipit-source-id: cde54dfbf39f04d3ea9dfa02a65295f5440e5ea4
      b6916a3a
    • Phil Willoughby's avatar
      Require compile-time constant format strings to `shellify` · 84d872be
      Phil Willoughby authored
      Summary:
      Because it's impossible to require that a parameter to a function is a compile-time constant string this replaces `shellify()` with the user-defined-literal suffix `_shellify()`.
      
      It's trivial to convert previously-correct code: `shellify("whatever {}", A)` => `"whatever {}"_shellify(A)`
      
      The previous `folly::shellify()` API is still present as a transition measure. Compilers will issue a deprecation warning if it is used.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D4435512
      
      fbshipit-source-id: 6639cd91280dc72108e47a8a7775c5160a4e644f
      84d872be
    • Michael Lee's avatar
      crt_externs.h is not available on all platforms · 0cd1f847
      Michael Lee authored
      Summary: Different deployments of don't always have access to crt_externs.h.
      
      Reviewed By: yfeldblum, Orvid
      
      Differential Revision: D4480621
      
      fbshipit-source-id: f0b18d15fa253d6ba28dee68859cf9a34bf41255
      0cd1f847
  15. 30 Jan, 2017 2 commits
    • Michael Lee's avatar
      Fix folly/Makefile.am · d1af84b6
      Michael Lee authored
      Summary: Missed a `\`
      
      Reviewed By: Orvid
      
      Differential Revision: D4483602
      
      fbshipit-source-id: 91451c3476756125abdbd0dd98ab9fb38bcf2c32
      d1af84b6
    • Michael Lee's avatar
      Split up experimental/TestUtil · ceac4e9e
      Michael Lee authored
      Summary: TestUtil is primarily a temporary file and temporary directory.  Split out the env variable manipulation into a different file.
      
      Reviewed By: Orvid
      
      Differential Revision: D4482071
      
      fbshipit-source-id: 9d1a4a08010a8fad270aa56a7e1432829eb6484c
      ceac4e9e