1. 17 Apr, 2018 6 commits
    • Dave Watson's avatar
      Add try_take_for to BlockingQueue · 5a7b4437
      Dave Watson authored
      Summary:
      add try_take_for to BlockingQueue, utilizing new LifoSem::try_wait_for method.
      To be used to kill threads after an idle period in CPUThreadPoolExecutor.
      
      Reviewed By: magedm
      
      Differential Revision: D7477268
      
      fbshipit-source-id: 76ea7fa1fc3b4b5f7a7529ce1424a91eef2ac7b1
      5a7b4437
    • Dave Watson's avatar
      parking lot perf improvements · 59e6e586
      Dave Watson authored
      Summary:
      Linux's futex checks the waiter count atomically before grabbing the lock.  This results in much better perf if there are no waiters and you call futexWake().
      Add the same improvement to ParkingLot.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D6639337
      
      fbshipit-source-id: 6e03eff07e4c9ce327bc66d0aabd8cec051a5b19
      59e6e586
    • Nikita Lutsenko's avatar
      folly | Fix folly::setThreadName, folly::getThreadName on iOS/watchOS/tvOS. · 8a6f12e1
      Nikita Lutsenko authored
      Summary:
      According to headers, `pthread_getname_np` and `pthread_setname_np` are available since iOS 3.2 and macOS 10.6.
      However, guarding just on min macOS version isn't going to work for iOS/watchOS/tvOS, because it's very rarely defined.
      So add another case for when `__IPHONE_OS_VERSION_MIN_REQUIRED` is defined and is above iOS 3.2, which will also make watchOS and tvOS work.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7648204
      
      fbshipit-source-id: 1e608cdad3f39242eff79fbb6da8e560eeee720a
      8a6f12e1
    • Jeffrey Shen's avatar
      Fix stack overflow in folly::window · 98174e06
      Jeffrey Shen authored
      Summary:
      If the default inline executor is used for folly::window, and all the futures generated by the callback are also inline, then all spawn function calls (and their associated Futures) are added to the call stack and can overflow. This fixes that issue by using QueuedImmediateExecutor, which will put the executor callback into a thread-local queue, allowing the current function to exit and destruct all objects in its stack frame. Then, only the first call to QueuedImmediateExecutor in a thread is responsible for running each subsequent callback and will do so sequentially.
      
      This will end up allocating dynamic queues that reach a max size of two. It is possible to avoid a dynamic queue by writing a new Executor that only stores a single function, if that is too much of a performance cost.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7597731
      
      fbshipit-source-id: cd8899e6c086ecff812050f7241e80f39c546706
      98174e06
    • Dan Melnic's avatar
      Avoid creating a loop in the ThreadEntryList in onThreadExit · 7c08a582
      Dan Melnic authored
      Summary: Avoid creating a loop in the ThreadEntryList in onThreadExit
      
      Reviewed By: djwatson
      
      Differential Revision: D7632840
      
      fbshipit-source-id: 409358aae16a8aed4ae654ebfeca994385b43a9e
      7c08a582
    • Giuseppe Ottaviano's avatar
      Implement partial loadUnaligned · 1c609e4e
      Giuseppe Ottaviano authored
      Summary:
      Neither GCC or Clang are able to optimize a `memcpy` where
      the length is known to be smaller than a word: a library call is
      generated. This is a simple implementation of a subword
      `loadUnaligned` to be used to read the tail of a buffer when reading
      one word at a time.
      
      Reviewed By: luciang
      
      Differential Revision: D7631978
      
      fbshipit-source-id: d5719580e6bef82aa8e3fbdce8f873b569527a3a
      1c609e4e
  2. 16 Apr, 2018 9 commits
    • Adam Simpkins's avatar
      remove utils.push_dir · 1bd232cd
      Adam Simpkins authored
      Summary: This function is no longer used anywhere.
      
      Reviewed By: Orvid
      
      Differential Revision: D7597741
      
      fbshipit-source-id: 296acfceb59293bbafc6f6bf9c67d951cf41f7be
      1bd232cd
    • Adam Simpkins's avatar
      minor tweaks to utils.py · d5de689d
      Adam Simpkins authored
      Summary:
      Update `make_temp_dir()` to use `shutil.rmtree()` to clean up rather than just
      `os.rmdir()`.  If the function using this context manager throws it may leave
      behind files inside the temporary directory, and it is useful to always clean
      those up.
      
      Also update `read_fbcode_builder_config()` to work regardless of the current
      working directory.  Previously this function only worked if the current working
      directory was the directory containing the configuration file.  This makes sure
      that `read_fbcode_builder_config()` calls are always treated as relative to the
      directory containing the configuration file being read.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7597743
      
      fbshipit-source-id: 817063104081336fcc0a9f825beb74d7d4377499
      d5de689d
    • Marc Celani's avatar
      Create a new SlidingWindow data structure · 59791afd
      Marc Celani authored
      Summary: Creates a new SlidingWindow data structure for general purpose use in stats code.
      
      Reviewed By: anakryiko
      
      Differential Revision: D7597047
      
      fbshipit-source-id: 227438055029c2bacb5edf2943ebc9cc66fdfe36
      59791afd
    • Dan Melnic's avatar
      Use unbounded queue in NotificationQueue · d25334fb
      Dan Melnic authored
      Summary: Use unbounded queue in NotificationQueue (prev changes: D7164130, D7251343, D7278275, D7359322, D7471153, D7606076)
      
      Reviewed By: djwatson
      
      Differential Revision: D7408628
      
      fbshipit-source-id: 04ae235d9b3de603e28115e11fe98fe7e9aa1f8c
      d25334fb
    • Stephan's avatar
      Fix for #819 (lang/Ordering.h is not installed via "make install") · e752dcd0
      Stephan authored
      Summary:
      fixes #819.
      Closes https://github.com/facebook/folly/pull/820
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7642932
      
      Pulled By: Orvid
      
      fbshipit-source-id: c49168ddf111c851d0218b74fbbdf405e9a68fc3
      e752dcd0
    • Kevin Doherty's avatar
      add eraseInto api to F14Set · 7153cc6b
      Kevin Doherty authored
      Summary:
      - Expose an API to erase an item from `F14Set` and do something with it before it is destroyed
      - This includes (but is not limited to) being able to `std::move` it to another container while avoiding a copy
      - Change erase implementations to forward to `eraseInto(...args, emptyCallback)`
      
      Reviewed By: shixiao
      
      Differential Revision: D7588928
      
      fbshipit-source-id: 5e9c2bda216c5c219c333282daadd2170e6a1eba
      7153cc6b
    • Subodh Iyengar's avatar
      Add errmsg callback to udp · 2584b1f2
      Subodh Iyengar authored
      Summary:
      Adds the ability for UDP sockets to optionally
      listen to errors that happen on the socket,
      for example ICMP errors.
      
      In this iteration, we explicitly do not register for
      read events if an error callback is set. So even
      if you set an error callback to get error events
      you must register a read callback.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7632877
      
      fbshipit-source-id: 43c922d0145e1da97b993f5bf4058c20d3469deb
      2584b1f2
    • Subodh Iyengar's avatar
      Clang format AsyncUDPSocket · 6ee198b0
      Subodh Iyengar authored
      Summary:
      Clang format files related to AsyncUDPSocket.
      This helps keep changes consistent.
      
      Reviewed By: yfeldblum, lnicco
      
      Differential Revision: D7632865
      
      fbshipit-source-id: 0761f0cfd06417334e680ca0880280d65480fe7e
      6ee198b0
    • Yedidya Feldblum's avatar
      Tweak SharedPromise and FutureSplitter docs · ba208d71
      Yedidya Feldblum authored
      Summary: [Folly] Tweak `SharedPromise` and `FutureSplitter` docs, in particular to reflection recent changes to execution semantics.
      
      Reviewed By: LeeHowes
      
      Differential Revision: D7630725
      
      fbshipit-source-id: 68da70cd86d131aa09c1909d90a793868039e84f
      ba208d71
  3. 14 Apr, 2018 6 commits
    • Yedidya Feldblum's avatar
      All comparison predicates for IOBuf · f35c91c0
      Yedidya Feldblum authored
      Summary: [Folly] All comparison predicates for `IOBuf`, not just `EqualTo`.
      
      Reviewed By: djwatson, stevegury
      
      Differential Revision: D7596700
      
      fbshipit-source-id: 2d5cef2797dc75d4fb76c2d13e4a938f738da163
      f35c91c0
    • Yedidya Feldblum's avatar
      comparsion-to-predicate adapters · 1bd8b4f5
      Yedidya Feldblum authored
      Summary: [Folly] comparison-to-predicate adapters for comparisons which return `ordering`.
      
      Reviewed By: stevegury
      
      Differential Revision: D7596712
      
      fbshipit-source-id: 1aeccf0d38eec27cfa88af2908f3114523d6b6b5
      1bd8b4f5
    • Yedidya Feldblum's avatar
      to_ordering to convert from int to ordering · a047388c
      Yedidya Feldblum authored
      Summary: [Folly] `to_ordering` to convert from `int` to `ordering`.
      
      Reviewed By: stevegury
      
      Differential Revision: D7596709
      
      fbshipit-source-id: cf1316a7560b9398b94d1c834258f09a797a98f8
      a047388c
    • Yedidya Feldblum's avatar
      An ordering type · fbfde2cb
      Yedidya Feldblum authored
      Summary: [Folly] An `ordering` type, lifted from `FixedString`.
      
      Reviewed By: stevegury
      
      Differential Revision: D7596713
      
      fbshipit-source-id: ba19e1e36e75b946e14f6db9c72ac1ac3c7270e9
      fbfde2cb
    • Adam Simpkins's avatar
      cmake: fix error in exception_tracer/CMakeLists.txt · 832f234a
      Adam Simpkins authored
      Summary:
      D7479058 changed the exception_tracer code to export their targets in the main
      folly-targets.cmake file, but I forgot to remove the `install()` command
      installing the old `folly-exception-tracer-targets.cmake` file.
      
      This would cause `cmake configure` to exit with an error if it detected it
      could built the exception_tracer code, but it would still generate all of the
      necessary Makefiles correctly, so subsequent `make` commands would still work.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7626710
      
      fbshipit-source-id: f015032c3c42cf2911fcaf9b355fc97616ff20e1
      832f234a
    • Léonard Gérard's avatar
      Fix CMakeLists.txt to not exclude everything with 'build' in pathname · 77be443b
      Léonard Gérard authored
      Summary:
      The cmake globbing then excluding strategy implies that if the directory
      in which we are compiling has a folder named `build` on its path like `/home/alice/project/build/folly/...`, everything breaks.
      Note that it is the same for `tools` and `test`, I also fixed the tools one, but the test once has many files.... Using a file list would be the real solution.
      Closes https://github.com/facebook/folly/pull/815
      
      Reviewed By: simpkins
      
      Differential Revision: D7624035
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: a3f1d2f82e55e070d13acc5c394d8cfdfabeb7ed
      77be443b
  4. 13 Apr, 2018 2 commits
    • Marc Celani's avatar
      TDigest for estimating quantiles · 5e1a06ae
      Marc Celani authored
      Summary:
      The existing histogram approach for estimating quantiles is inadequate for common use cases. This diff introduces TDigests for estimating quantiles of streaming values.
      
      The current histogram approach suffers from two issues:
        - The user needs to know something about the universe of values, U, and the underlying distribution in order to get reasonably accurate values
        - Because the histogram is not biased, estimating tail quantiles such as p99.9 requires a large amount of memory.
      
      t-digests (https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf) are biased digests that allow for accurate estimates of tail quantiles, while using a small amount of memory and without requiring the user to know anything about U.
      
      The scaling function in the paper is slow, because it uses arcsin. This approach uses a sqrt function instead. Details of why this works in the comments of the TDigest file.
      
      Reviewed By: simpkins
      
      Differential Revision: D7512432
      
      fbshipit-source-id: 01460433ec7380fed88e5e942ef15f032dd794bb
      5e1a06ae
    • Yedidya Feldblum's avatar
      Fix constexpr predicate names · 0e169ccf
      Yedidya Feldblum authored
      Summary: [Folly] Fix `constexpr` predicate names, which have embarrassing typos.
      
      Reviewed By: igorsugak
      
      Differential Revision: D7605352
      
      fbshipit-source-id: e04a87fd375f09472b020380bf446c7236a39e51
      0e169ccf
  5. 12 Apr, 2018 5 commits
    • Dan Melnic's avatar
      Fix broken Android build · b55e6225
      Dan Melnic authored
      Summary:
      Fix broken Android build
      
      (Note: this ignores all push blocking failures!)
      
      Reviewed By: michalgr
      
      Differential Revision: D7606076
      
      fbshipit-source-id: 0cf0426a34cf62b045acb932d42a8e4a3cd5da71
      b55e6225
    • Tudor Bosman's avatar
      Fix gcc7 error in ExceptionInfo constructor · 9210a201
      Tudor Bosman authored
      Summary:
      When trying to compile `folly/experimental/exception_tracer` with gcc-7.2, I get the following error:
      
      ```
      ExceptionCounterLib.cpp: In instantiation of '{anonymous}::throwHandler(void*, std::type_info*, void (*)(void*))::<lambda(auto:9&)> [with auto:9 = std::unordered_map<long unsigned int, folly::exception_tracer::ExceptionStats>]':
      ../../../folly/Synchronized.h:162:20:   required from 'auto folly::SynchronizedBase<Subclass, (folly::detail::MutexLevel)1>::withWLock(Function&&) [with Function = {anonymous}::throwHandler(void*, std::type_info*, void (*)(void*))::<lambda(auto:9&)>; Subclass = folly::Synchronized<std::unordered_map<long unsigned int, folly::exception_tracer::ExceptionStats>, folly::RWSpinLock>]'
      ExceptionCounterLib.cpp:132:4:   required from here
      ExceptionCounterLib.cpp:127:21: error: uninitialized variable 'info' in 'constexpr' function
             ExceptionInfo info;
                           ^~~~
      In file included from ../../../folly/experimental/exception_tracer/ExceptionCounterLib.h:22:0,
                       from ExceptionCounterLib.cpp:16:
      ../../../folly/experimental/exception_tracer/ExceptionTracer.h:30:8: note: 'struct folly::exception_tracer::ExceptionInfo' has no user-provided default constructor
       struct ExceptionInfo {
              ^~~~~~~~~~~~~
      ../../../folly/experimental/exception_tracer/ExceptionTracer.h:31:25: note: and the implicitly-defined constructor does not initialize 'const std::type_info* folly::exception_tracer::ExceptionInfo::type'
         const std::type_info* type;
                               ^~~~
      ```
      
      Fixed by initializing `ExceptionInfo::type`.
      
      Compiling with gcc 7.2 now works.
      Closes https://github.com/facebook/folly/pull/812
      
      Reviewed By: Orvid
      
      Differential Revision: D7598341
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 0a8859b6d5f174484c8f2148de59a2a592dc2b25
      9210a201
    • Yedidya Feldblum's avatar
      Rename IOBufEqual to IOBufEqualTo · c816aeff
      Yedidya Feldblum authored
      Summary: [Folly] Rename `IOBufEqual` to `IOBufEqualTo` to correspond with the standard naming of `std::equal_to`.
      
      Reviewed By: Orvid
      
      Differential Revision: D7596716
      
      fbshipit-source-id: 2e87aa4b62a002520bdd53b5b7eaba7d9bd822da
      c816aeff
    • kumagi's avatar
      find_package(gflags CONFIG QUIET) didn't works in Ubuntu. · ad317726
      kumagi authored
      Summary:
      in Linux environment, `find_package(gflass)` searches `Findgflags.cmake`.
      And it cannot find  https://github.com/facebook/folly/blob/master/CMake/FindGFlags.cmake , because linux is case-sensitive environment in filenames and cause error.
      
      ```
      CMake Error at CMake/folly-deps.cmake:34 (message):
        Unable to determine the target name for the GFlags package.
      Call Stack (most recent call first):
        CMakeLists.txt:65 (include)
      ```
      
      For linux programmers, this line should find `FindGFlags.cmake` file which exists in the same directory.
      Closes https://github.com/facebook/folly/pull/805
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7505908
      
      Pulled By: Orvid
      
      fbshipit-source-id: c30097a25569d293df9a1bfecbee84cece260306
      ad317726
    • Yedidya Feldblum's avatar
      Function objects for performing constexpr comparisons · 66405fc6
      Yedidya Feldblum authored
      Summary:
      [Folly] Function objects for performing `constexpr` comparisons for C++11 or gcc49.
      
      After upgrading to C++14 and dropping support for C++11, these may be removed because the corresponding function objects in the C++14 standard library are `constexpr`-invocable.
      
      Reviewed By: Orvid
      
      Differential Revision: D7590351
      
      fbshipit-source-id: a8702115a66836aff25761f374b8a2d7dbe12074
      66405fc6
  6. 11 Apr, 2018 1 commit
  7. 10 Apr, 2018 9 commits
    • Dave Watson's avatar
      Fix ThreadCachedInts init · 580c1197
      Dave Watson authored
      Summary: The domain tests seem broken.  Digging in, it seems to be uninitialized ThreadCachedInts variables.  Initialize them.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D7505520
      
      fbshipit-source-id: aca8a6f5b38271bf06ea8a6377bfb692328f1e33
      580c1197
    • Maged Michael's avatar
      DeterministicSchedule: Fix namespace for default_failure_memory_order · d2600ef7
      Maged Michael authored
      Reviewed By: djwatson
      
      Differential Revision: D7571438
      
      fbshipit-source-id: 1484e5e323c7d57a96ad66d46fd999ce51e69951
      d2600ef7
    • Dave Watson's avatar
      Sync time compare exchange · dfd3d1ef
      Dave Watson authored
      Summary: Similar to D7429494, this can be a CAS and save some latency for some readers.
      
      Reviewed By: magedm
      
      Differential Revision: D7505578
      
      fbshipit-source-id: eeeb06c2969a74084edd3df26cf2d135b8b0e132
      dfd3d1ef
    • Alexander Zhavnerchik's avatar
      folly::settings do not inline settings definition · 75765b5c
      Alexander Zhavnerchik authored
      Summary:
      If FOLLY_SETTING_DEFINE(...) is put into .cpp file right now you will get linker error about undefined references.
      
      According to http://en.cppreference.com/w/cpp/language/inline
        2) The definition of an inline function or variable (since C++17) must be present in the translation unit where it is accessed (not necessarily before the point of access).
      
      Hence the linker error. This diff fixes that.
      
      Reviewed By: alikhtarov, mnv104
      
      Differential Revision: D7567469
      
      fbshipit-source-id: 02049e4881e50c414aeb506745e02eed1256daad
      75765b5c
    • Adam Simpkins's avatar
      allow specifying the directory containing CMakeLists.txt · 7be9cf6a
      Adam Simpkins authored
      Summary:
      Update `cmake_configure()`, `cmake_install()`, and `fb_github_cmake_install()`
      to support specifying the directory where CMakeLists.txt is found, relative to
      the directory where the build is being performed.  Previously these functions
      where hardcoded to assume that CMakeLists.txt was always found at '..'
      
      Reviewed By: snarkmaster
      
      Differential Revision: D7540689
      
      fbshipit-source-id: efd3d044345fadc0346e436c01d0a247e1b6fd70
      7be9cf6a
    • Adam Simpkins's avatar
      add a `FOLLY_INIT_LOGGING_CONFIG()` helper macro · 48407345
      Adam Simpkins authored
      Summary:
      Add a macro to help users define the `getBaseLoggingConfig()` function.
      
      While I would prefer to avoid macros if possible, this seems worthwhile.  This
      saves 4 or 5 lines of boilerplate code in each program that sets a custom base
      logger setting.  It also reduces the likelihood of a developer accidentally
      having a typo in the function name, which would still build successfully but
      not have the desired results.
      
      Reviewed By: chadaustin
      
      Differential Revision: D7457652
      
      fbshipit-source-id: 1c316c7ea6949c16bd7b61c0440cc1ee69ecb83e
      48407345
    • Adam Simpkins's avatar
      logging: add an initLoggingOrDie() function · e374ef6a
      Adam Simpkins authored
      Summary:
      Add folly::initLoggingOrDie(), which behaves like `initLogging()` but handles
      errors by printing a message to stderr and then calling `exit(1)`.
      
      Most programs are expected to initialize logging early on during program
      start-up, and will likely use a command line argument or other configuration
      value as the logging settings.  If an error occurs they usually want to print
      the message to stderr and exit unsuccesfully. `initLoggingOrDie()` makes it
      easy to perform these steps without requiring programs to write their own
      exception handlers to handle errors from `initLogging()`.
      
      Reviewed By: chadaustin
      
      Differential Revision: D7164830
      
      fbshipit-source-id: d688046f1b6240c948e4aaabfc9fb24ba3d9ff89
      e374ef6a
    • Anton Likhtarov's avatar
      folly::settings: simplify; define/declare split; Metadata · dd2f2ef7
      Anton Likhtarov authored
      Summary:
      - Let's enforce a single definition. Also makes the implementation much simpler.
      - Collect all static info about a setting in a Metadata struct
      
      Differential Revision: D7544210
      
      fbshipit-source-id: d3f2ef617bd817d355a37e11fa9425b6a4259384
      dd2f2ef7
    • Eugene Pekurovsky's avatar
      F14Map: Add a method for getting the size of dynamically allocated map memory · f09d03aa
      Eugene Pekurovsky authored
      Summary:
      Currently, the memory used by a map instance is available only via computeStats(),
      which is quite expensive. A lightweight method is needed for getting the map memory
      footprint on a hot code path.
      
      Reviewed By: nbronson
      
      Differential Revision: D7544180
      
      fbshipit-source-id: 3cbc98bb9f1c5e7f75fd9eb7f89016580fbb6523
      f09d03aa
  8. 09 Apr, 2018 2 commits
    • Orvid King's avatar
      Fix build on MSVC2015 Update 3 · ed118811
      Orvid King authored
      Summary: Which only supports C++11 style constepxr.
      
      Reviewed By: simpkins
      
      Differential Revision: D7546457
      
      fbshipit-source-id: 52db98379096dd3b25f656e7e62238ce10537bf7
      ed118811
    • Alexander Zhavnerchik's avatar
      Fix operator->() · c0909b44
      Alexander Zhavnerchik authored
      Summary:
      According to http://en.cppreference.com/w/cpp/language/operators
        The overload of operator -> must either return a raw pointer or return an object (by reference or by value), for which operator -> is in turn overloaded.
      
      Hence this change.
      
      Reviewed By: mnv104
      
      Differential Revision: D7548832
      
      fbshipit-source-id: d98ff1f96bc00dc6e2e5cb084b96091a61421627
      c0909b44