1. 29 Mar, 2016 1 commit
    • Sven Over's avatar
      folly/futures: use folly::Function to store callback · 3f2140ea
      Sven Over authored
      Summary:This diff makes it possible to pass callables (such as lambdas) to
      folly::Future::then that are not copy-constructible. As a consequence, move-only
      types (such as folly::Promise or std::unique_ptr) can now be captured in lambdas
      passed to folly::Future::then.
      
      Using C++14 notation, the following is now possible:
        Future<Unit>().then([promise = std::move(promise)]() mutable {
          promise.setValue(123);
        });
      See folly/futures/test/NonCopyableLambdaTest.cpp for more examples.
      
      folly::Future uses std::function to store callback functions. (More precisely,
      the callback function is stored in a std::function in folly::detail::Core.)
      std::function is a copy-constructible type and it requires that the callable
      that it stores is copy constructible as well.
      
      This diff changes the implementation of folly::detail::Core to use
      folly::Function instead of std::function. It also simplifies the code in
      folly::detail::Core a little bit: Core had a reserved space of size
      8*sizeof(void*) to store callbacks in-place. Only larger callbacks (capturing
      more data) would be stored in the std::function, which puts those on the heap.
      folly::Function has a template parameter to set the size of the in-place
      callable storage. In Core, it is set to 8*sizeof(void*), so all callbacks that
      used to be stored in-place inside Core, are now stored in-place inside
      folly::Function. This even reduces the size of a Core object: the
      folly::Function object occupies 80 bytes, which is 16 bytes less than what was
      used before for a std::function (32 bytes) and the callback storage (64
      bytes). The resulting size of a Core<Unit> goes down from 192 to 176 bytes (on
      x86_64).
      
      Reviewed By: fugalh
      
      Differential Revision: D2884868
      
      fb-gh-sync-id: 35548890c392f80e6c680676b0f98e711bc03ca3
      fbshipit-source-id: 35548890c392f80e6c680676b0f98e711bc03ca3
      3f2140ea
  2. 28 Mar, 2016 6 commits
    • Subodh Iyengar's avatar
      Fix cases of overwriting errno · 6f068498
      Subodh Iyengar authored
      Summary:AsyncSocket has a few cases where
      we might overwrite errno, with another function
      call that is done during use.
      
      For example withAddr could cause an EBADF if the fd
      was bad.
      
      This fixes these cases by copying errno, before doing
      anything else
      
      Reviewed By: afrind
      
      Differential Revision: D3101932
      
      fb-gh-sync-id: 73d4810314c90cb987936a0a3a9dc977af07243a
      fbshipit-source-id: 73d4810314c90cb987936a0a3a9dc977af07243a
      6f068498
    • Yedidya Feldblum's avatar
      s/MAX_STATIC_CONSTRUCTOR_PRIORITY/FOLLY_STATIC_CTOR_PRIORITY_MAX/g · 03343ccb
      Yedidya Feldblum authored
      Summary:[Folly] `s/MAX_STATIC_CONSTRUCTOR_PRIORITY/FOLLY_STATIC_CTOR_PRIORITY_MAX/g`.
      
      Namespace it with a `FOLLY_` prefix - when Folly introduces its own symbols, it is best when they are namespaced.
      
      And stick `_MAX` at the end. Reads a bit more hierarchically to me that way.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3095964
      
      fb-gh-sync-id: 4ac8c00c03c8bd146fad9be96ce3849830504d96
      fbshipit-source-id: 4ac8c00c03c8bd146fad9be96ce3849830504d96
      03343ccb
    • Andrii Grynenko's avatar
      Allocate stacks with guard pages by default · efdf2270
      Andrii Grynenko authored
      Summary: This was on for mcrouter for very long time. We should make it default for everyone.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3023133
      
      fb-gh-sync-id: 6401f86df754e9490d46beb5fd9d0cf4b3675208
      fbshipit-source-id: 6401f86df754e9490d46beb5fd9d0cf4b3675208
      efdf2270
    • Sven Over's avatar
      folly::fibers: do not move out of lvalue references · 6f323462
      Sven Over authored
      Summary:If you pass an lvalue to folly::fibers::Fiber::setFunction or
      setFunctionFinally, you do not expect that those methods move
      the function out of your lvalue.
      
      This diff uses std::forward for perfect forwarding, so if an lvalue
      is passed, a copy is made.
      
      If and when when start using folly::Function for storing the
      functions in the Fiber object, passing an lvalue will trigger a
      compiler error because folly::Function is not copyable. That is
      a good thing, as it enforces calling setFunction with std::move
      if you use a named object, making clear that the named object
      gets moved out of. Often people will pass temporary objects
      (like a lambda defined i- place), which a rvalues anyway, so
      this will not be a problem anyway.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3102685
      
      fb-gh-sync-id: 87bf3135f7f6630766f97be351599ff488e4b796
      fbshipit-source-id: 87bf3135f7f6630766f97be351599ff488e4b796
      6f323462
    • Christopher Dykes's avatar
      Create the string.h portability header · 8ff7c8b8
      Christopher Dykes authored
      Summary: Windows has it, but some things aren't there, and some have different names.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2990475
      
      fb-gh-sync-id: 3f30e084eb7789c13b3981ec0fbf5b7b642c3367
      fbshipit-source-id: 3f30e084eb7789c13b3981ec0fbf5b7b642c3367
      8ff7c8b8
    • Christopher Dykes's avatar
      Move asm portability to an Asm portability header · fe33916f
      Christopher Dykes authored
      Summary: Portabilty.h is just a mashup of everything that was needed up-to now, however, with the Windows port significantly expanding the scope of portability in Folly, it no longer needs to be a massive mashup, so start things by splitting out the asm stubs.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3007018
      
      fb-gh-sync-id: f32913f74660aaa8889a553ae5d6f7182a4f5789
      fbshipit-source-id: f32913f74660aaa8889a553ae5d6f7182a4f5789
      fe33916f
  3. 27 Mar, 2016 1 commit
    • Haijun Zhu's avatar
      Move event_base_new out of critical region · a103b7e7
      Haijun Zhu authored
      Summary:event_base_new does not change the global current_base so no need to
      call it with the mutex held.
      
      Reviewed By: chadparry
      
      Differential Revision: D3055963
      
      fb-gh-sync-id: df420b189ef0d7d56eda5ad6c32e03b195804e6b
      fbshipit-source-id: df420b189ef0d7d56eda5ad6c32e03b195804e6b
      a103b7e7
  4. 26 Mar, 2016 2 commits
    • Sven Over's avatar
      folly::Function: improve conversion of return types · ecf14e67
      Sven Over authored
      Summary:Treat any return type as convertible to void:
      
      As of C++17, std::function<void(Args...)> can be set to callables
      returning non-void types when called with parameters Args....
      This diff adds that capability to folly::Function. It also adds
      unit tests, not only for ignoring return types, but also for
      correctly converting between the return type of the embedded
      callabled and the return type of the encapsulating folly::Function.
      
      Allow conversion of one folly::Function type to another one which
      declares a return type the original one can be converted to:
      
      E.g. allow to construct a Function<double()> from a
      Function<int()> or a Function<Base*()> from a
      Function<Derived*()>.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3095583
      
      fb-gh-sync-id: 6d924dc6e97f759d8109db4200e1cb9333a98d31
      fbshipit-source-id: 6d924dc6e97f759d8109db4200e1cb9333a98d31
      ecf14e67
    • Bert Maher's avatar
      Fix portability/Time.h on OSX · b6ed6b39
      Bert Maher authored
      Summary: It needs stdint to define uint8_t
      
      Reviewed By: yfeldblum, mzlee
      
      Differential Revision: D3101140
      
      fb-gh-sync-id: 308507af1ccd81e2eb389a400376556a6cc597b2
      fbshipit-source-id: 308507af1ccd81e2eb389a400376556a6cc597b2
      b6ed6b39
  5. 24 Mar, 2016 2 commits
    • Kevin McCray's avatar
      folly: avoid using atomic operations android can't handle · 61e0e4d9
      Kevin McCray authored
      Summary:On Android, clang 3.8 + libstdc++ doesn't support the full
      range of atomic operations.  This diff fixes up the ones we
      ran into when building fb4a.
      
      Reviewed By: mzlee
      
      Differential Revision: D3092352
      
      fb-gh-sync-id: 7fea8513e23425fc37050ad14d82aabaceb00352
      shipit-source-id: 7fea8513e23425fc37050ad14d82aabaceb00352
      61e0e4d9
    • Yedidya Feldblum's avatar
      Fix Build: folly after replacing FOLLY_NORETURN · 7ea8b939
      Yedidya Feldblum authored
      Summary:[Folly] Fix Build: `folly` after replacing `FOLLY_NORETURN`.
      
      Problem 1:
      * Clang does not treat `[[noreturn]]` and `__attribute__((__noreturn__))` as the same attribute. When a function is declared twice with the noreturn attribute, both declarations must use either the one syntax or the other; Clang fails if the two declarations mix-and-match. When both `folly/detail/FunctionalExcept.h` and gcc49's `bits/functexcept.h` are both included from the same source, they (now) mix-and-match the attribute syntaxes and Clang emits an error.
      * `folly/detail/FunctionalExcept.h` should be included only when `bits/functexcept.h` is unavailable - somehow, both headers were being included.
      
      We fix the latter problem and keep our `[[noreturn]]` syntax.
      
      Found from WDT build failures in Travis CI.
      
      Reviewed By: ldemailly
      
      Differential Revision: D3089987
      
      fb-gh-sync-id: 705a087fc2a9629739d6cedd8315d56111204e6d
      shipit-source-id: 705a087fc2a9629739d6cedd8315d56111204e6d
      7ea8b939
  6. 23 Mar, 2016 2 commits
    • Yedidya Feldblum's avatar
      Use C++'s standardized [[noreturn]] attribute · 9895ee08
      Yedidya Feldblum authored
      Summary:Use C++'s standardized `[[noreturn]]` attribute.
      
      All supported compilers (and some unsupported compilers) also support the standardized syntax.
      
      GCC >= 4.8, Clang >= 3.0, and MSVC >= 2015 have direct support for the C++'s standardized way of writing the attribute.
      
      Clang - http://goo.gl/ftJGVM
      GCC 4.8.2 - http://goo.gl/ORCVOD
      ICC 13.0.1 - http://goo.gl/I5tn5I
      MSVC 2015 - https://msdn.microsoft.com/en-us/library/hh567368.aspx
      
      (Regardling Clang, earlier versions may support it. 3.0 was the earliest Clang version listed at godbolt.com, so that's as far back as I went.)
      
      Therefore, we no longer need to use the compiler-specific syntaxes, or use preprocessor macros with per-compiler definitions:
      
          __attribute__((__noreturn__))
          __attribute__((noreturn))
          __declspec(noreturn)
      
      Reviewed By: Orvid
      
      Differential Revision: D3073621
      
      fb-gh-sync-id: 32d4771d1bf1974693b8574fa2d39c9559872945
      shipit-source-id: 32d4771d1bf1974693b8574fa2d39c9559872945
      9895ee08
    • Christopher Dykes's avatar
      Move the clock details over to the Time.h portability header · dec14727
      Christopher Dykes authored
      Summary: Because things belong places.
      
      Reviewed By: mzlee
      
      Differential Revision: D3077737
      
      fb-gh-sync-id: 966f37df722ae737481d776ff1c9b0d5132b7a58
      shipit-source-id: 966f37df722ae737481d776ff1c9b0d5132b7a58
      dec14727
  7. 22 Mar, 2016 4 commits
    • Michael Lee's avatar
      Add APPLE to portability/Config · 67859615
      Michael Lee authored
      Summary: And use that to guard the use of posix_memalign.
      
      Reviewed By: benyl
      
      Differential Revision: D3081743
      
      fb-gh-sync-id: 2c71d9cbeeaeb59d1600d486cccfc2109699ba6b
      shipit-source-id: 2c71d9cbeeaeb59d1600d486cccfc2109699ba6b
      67859615
    • Sven Over's avatar
      Introducing folly::Function · 08a67734
      Sven Over authored
      Summary:std::function is copy-constructible and requires that the callable that it wraps
      is copy-constructible as well, which is a constraint that is often inconvenient.
      In most cases when using a std::function we don't make use of its
      copy-constructibility.
      
      This diff introduces a templated type called folly::Function that is very
      similar to a std::function, except it is not copy-constructible and doesn't
      require the callable to be either.
      
      Like std::function, Function is a templated type with template parameters
      for return type and argument types of the callable, but not the callable's
      specific type. It can store function pointers, static member function pointers,
      std::function objects, std::reference_wrapper objects and arbitrary callable
      types (functors) with matching return and argument types.
      
      Much like std::function, Function will store small callables in-place, so
      that no additional memory allocation is necessary. For larger callables,
      Function will allocate memory on the heap.
      
      Function has two more template parameters: firstly, an enum parameter of
      type folly::FunctionMoveCtor, which defaults to NO_THROW and determines
      whether no-except-movability should be guaranteed. If set to NO_THROW,
      callables that are not no-except-movable will be stored on the heap, even
      if they would fit into the storage area within Function.
      
      Secondly, a size_t parameter (EmbedFunctorSize), which determines the size of
      the internal callable storage. If you know the specific type of the callable you
      want to store, you can set EmbedFunctorSize to sizeof(CallableType).
      
      The original motivation of this diff was to allow to pass lambdas to
      folly::Future::then that are not copy-constructible because they capture
      non-copyable types, such as a promise or a unique pointer.
      
      Another diff will shortly follow that changes folly::Future to use
      folly::Function instead of std::function for callbacks, thus allowing to
      pass non-copyable lambdas to folly::Future::then.
      
      Reviewed By: fugalh
      
      Differential Revision: D2844587
      
      fb-gh-sync-id: 3bee2af75ef8a4eca4409aaa679cc13762cae0d0
      shipit-source-id: 3bee2af75ef8a4eca4409aaa679cc13762cae0d0
      08a67734
    • Michael Lee's avatar
      Use FOLLY_MOBILE to split some functionality · 328b22e8
      Michael Lee authored
      Summary: The guards already look for __APPLE__, but __ANDROID__ needs this as well.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3053976
      
      fb-gh-sync-id: a9ba7a612d29502d4a7e691c6741837d4a8b42f0
      shipit-source-id: a9ba7a612d29502d4a7e691c6741837d4a8b42f0
      328b22e8
    • Orvid King's avatar
      2d14fafe
  8. 21 Mar, 2016 5 commits
    • Anirudh Ramachandran's avatar
      Add support for probabilistically choosing server ciphers · 0eb9fa39
      Anirudh Ramachandran authored
      Summary:Since SSLContextManager sets SSL_OP_CIPHER_SERVER_PREFERENCE on the SSL_CTX
      when it creates contexts, we may be unable to accommodate any clients who
      prefer a different ciphersuite. Having differently weighted cipher preference
      lists allows SSLContext to set a list with a different most-preferred cipher
      for some fraction of new handshakes.
      
      Note: resumption will work with the previously negotiated ciphersuite even if
      the server doesn't explicitly prefer/support it anymore, provided the cipher is
      supported in OpenSSL.
      
      Reviewed By: knekritz
      
      Differential Revision: D3050496
      
      fb-gh-sync-id: 1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
      shipit-source-id: 1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
      0eb9fa39
    • Michael Lee's avatar
      Have StringTest use PRI*64 instead · 948ec49b
      Michael Lee authored
      Summary: This helps account for 32-bit vs. 64-bit compilation targets.
      
      Reviewed By: benyl
      
      Differential Revision: D3076523
      
      fb-gh-sync-id: 56f49daaf55d242ac48f8b8d38a40c6d6230818b
      shipit-source-id: 56f49daaf55d242ac48f8b8d38a40c6d6230818b
      948ec49b
    • Anirudh Ramachandran's avatar
      Add option to retrieve hex representation of client ciphers · c7087eb7
      Anirudh Ramachandran authored
      Summary: A more compact hex representation of ciphers in ClientHello can be useful, e.g., for logging.
      
      Reviewed By: knekritz
      
      Differential Revision: D3052308
      
      fb-gh-sync-id: beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
      shipit-source-id: beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
      c7087eb7
    • Christopher Dykes's avatar
      Add Windows support to portability/Memory.h · 5b48f33a
      Christopher Dykes authored
      Summary: This adds Windows support to portability/Memory.h and also does some refactoring to be more correct about when to use posix_memalign, and also changes it to fall back to memalign rather than posix_memalign.
      
      Reviewed By: mzlee
      
      Differential Revision: D3069990
      
      fb-gh-sync-id: 88861583c6028e9fb02a3e3804bd6d476956c555
      shipit-source-id: 88861583c6028e9fb02a3e3804bd6d476956c555
      5b48f33a
    • Giuseppe Ottaviano's avatar
      Optimize fbstring::append() · 60088aaa
      Giuseppe Ottaviano authored
      Summary:Instead of relying on `push_back()` to guarantee exponential growth,
      delegate to `expand_noinit`. This removes the duplication of logic
      between the two functions, and significantly speeds up short appends.
      
      ```
      $ _bin/folly/test/fbstring_benchmark_using_jemalloc --bm_min_usec=100000
                                                                Before:             After:
      ============================================================================ ===================
      ./folly/test/FBStringTestBenchmarks.cpp.h       relative  time/iter  iters/s  time/iter  iters/s
      ============================================================================ ===================
      ...
      BM_push_back_fbstring(1)                                     7.51ns  133.20M     6.87ns  145.49M
      BM_push_back_fbstring(23)                                  175.08ns    5.71M   173.92ns    5.75M
      BM_push_back_fbstring(127)                                 586.02ns    1.71M   585.70ns    1.71M
      BM_push_back_fbstring(1024)                                  3.30us  302.81K     3.41us  293.13K
      BM_short_append_fbstring(23)                               367.01ns    2.72M   179.45ns    5.57M
      BM_short_append_fbstring(1024)                               9.33us  107.20K     5.72us  174.95K
      ...
      ============================================================================ ===================
      ```
      
      Reviewed By: philippv
      
      Differential Revision: D3075249
      
      fb-gh-sync-id: 497775ba3fc707bf50821a3cf10fb9d247b9352d
      shipit-source-id: 497775ba3fc707bf50821a3cf10fb9d247b9352d
      60088aaa
  9. 20 Mar, 2016 3 commits
    • Christopher Dykes's avatar
      Add features to portability/Config.h · d05711c6
      Christopher Dykes authored
      Summary: It is perfectly reasonable to need to feature macros when checking configuration, and the configuration is needed to know if features.h exists, so put it in the same file.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3072255
      
      fb-gh-sync-id: 0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
      shipit-source-id: 0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
      d05711c6
    • Christopher Dykes's avatar
      Split iovec out of SysUio.h · d4d47023
      Christopher Dykes authored
      Summary: This is needed to avoid a circular dependency.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3072037
      
      fb-gh-sync-id: 546a46fd68f25f0c5b027d4d938335b2711d8fdd
      shipit-source-id: 546a46fd68f25f0c5b027d4d938335b2711d8fdd
      d4d47023
    • Mark Reitblatt's avatar
      fix typo in log printing in AsyncSSLSocket · 38db78ab
      Mark Reitblatt authored
      Reviewed By: pritamdamania
      
      Differential Revision: D3068807
      
      fb-gh-sync-id: 0b45ab678e2ec5565eb379540576527cf8b1d308
      shipit-source-id: 0b45ab678e2ec5565eb379540576527cf8b1d308
      38db78ab
  10. 19 Mar, 2016 1 commit
  11. 18 Mar, 2016 1 commit
    • Christopher Dykes's avatar
      Create the sys/mman.h portability header · 6346da0d
      Christopher Dykes authored
      Summary: Something that Windows very definitely lacks. This is a fun one.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2979661
      
      fb-gh-sync-id: e23c1db0cb8655b22308b874bd421a7cc1e4759e
      shipit-source-id: e23c1db0cb8655b22308b874bd421a7cc1e4759e
      6346da0d
  12. 17 Mar, 2016 3 commits
    • Yedidya Feldblum's avatar
      Remove pthread_yield support · 2c8de414
      Yedidya Feldblum authored
      Summary:[Folly] Remove `pthread_yield` support.
      
      * It is not actually part of POSIX - rather, `sched_yield` is.
      * In C++, we should be using `std::this_thread::yield` anyway.
      
      Reviewed By: Gownta
      
      Differential Revision: D3056221
      
      fb-gh-sync-id: 2fea55dd7b715149327987d61e5a573ad0455330
      shipit-source-id: 2fea55dd7b715149327987d61e5a573ad0455330
      2c8de414
    • Subodh Iyengar's avatar
      Allow override of session context · 1e9f3465
      Subodh Iyengar authored
      Summary:We currently set the session context to the
      default of common name, this allows session
      context to be set to a different value
      for different applications
      
      Reviewed By: ngoyal
      
      Differential Revision: D3059769
      
      fb-gh-sync-id: 185afeb487c2c62dcf44f96076bd05871692c7ab
      shipit-source-id: 185afeb487c2c62dcf44f96076bd05871692c7ab
      1e9f3465
    • Andrew Cox's avatar
      Tell ASAN about fiber stacks · 2ea64dd2
      Andrew Cox authored
      Summary:ASAN needs to know about the stack extents. Currently it has no knowledge of
      fibers and so it can give false positives, particularly in cases of no-return
      (think exceptions).
      
      See: https://github.com/google/sanitizers/issues/189
      
      This change along with a related ASAN diff fixes that, and I've verified it
      fixes false positive test failures I'm seeing when throws happen from fibers.
      
      Also rips out some hacks that attempted to work around the limitations of
      ASAN these changes should fix.
      
      This change depends on:
      D3017630
      D2952854
      D3017619
      
      And will also depend on rollout of libasan.so to /usr/local/fbcode platform dirs on all machines.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D2952899
      
      fb-gh-sync-id: 19da779227c6c0f30c5755806325aa4cba364cfe
      shipit-source-id: 19da779227c6c0f30c5755806325aa4cba364cfe
      2ea64dd2
  13. 16 Mar, 2016 4 commits
    • Christopher Dykes's avatar
      Create portability/Config.h · d9e0b59d
      Christopher Dykes authored
      Summary: Because including the root portability header just to get a couple of defines to be able to enable things is a waste. In addition, it would be nice if the config defines are never needed outside of the portability headers.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3059651
      
      fb-gh-sync-id: 1cb9910d850ea015616a598808556b4815b3fb74
      shipit-source-id: 1cb9910d850ea015616a598808556b4815b3fb74
      d9e0b59d
    • Eric Niebler's avatar
      move StaticMeta::onThreadExit into libfolly_thread_local.so · 946d061d
      Eric Niebler authored
      Summary: Fix folly/test:thread_local_test in the shared library scenario by moving onThreadExit into libfolly_thread_local.so, avoiding the crash when a user's .so is dlclosed.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D2919287
      
      fb-gh-sync-id: ecc4220fd40203289366eb1a6391b8b6d971e65f
      shipit-source-id: ecc4220fd40203289366eb1a6391b8b6d971e65f
      946d061d
    • Phil Willoughby's avatar
      Remove `using std::make_unique` · fed5dff0
      Phil Willoughby authored
      Summary: Older compilers do not have have `std::make_unique`. We have `folly::make_unique` which does the same job, and because we already have `using namespace folly` in this file it suffices to erase the `using std::make_unique` line.
      
      Reviewed By: eduardosuarez
      
      Differential Revision: D3058089
      
      fb-gh-sync-id: a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37
      shipit-source-id: a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37
      fed5dff0
    • Yedidya Feldblum's avatar
      Remove an outdated/inapplicable comment · 2eba4703
      Yedidya Feldblum authored
      Summary: [Folly] Remove an outdated/inapplicable comment from `folly/Portability.h`.
      
      Reviewed By: Gownta
      
      Differential Revision: D3055909
      
      fb-gh-sync-id: c17fdcc7de13fe5a9bb38bb4498a006ec71a61e2
      shipit-source-id: c17fdcc7de13fe5a9bb38bb4498a006ec71a61e2
      2eba4703
  14. 15 Mar, 2016 5 commits
    • Christopher Dykes's avatar
      Add portability header for sys/file.h · 30c8cd93
      Christopher Dykes authored
      Summary: We don't have it on Windows :(
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2978397
      
      fb-gh-sync-id: 388bc450ce269559825ebfb78e3646533c2e1153
      shipit-source-id: 388bc450ce269559825ebfb78e3646533c2e1153
      30c8cd93
    • Igor Sugak's avatar
      folly/subprocess: fix one -Wsign-conversion and clag 3.9 test · 8c3d9fba
      Igor Sugak authored
      Summary:easy:
      `options.parentDeathSignal_` is `int`, and second argument of `prctl` is `unsigned long`. Adding explicit cast.
      
      hard:
      this change is fixing a real problem when building folly with Clang 3.9.0. The [[ https://github.com/llvm-mirror/clang/commit/f4ddf94ecbd9899a497151621f3871545e24e93b | new alignment implementation ]] in `-O3` generates code that breaks folly's `ParentDeathSubprocessTest.ParentDeathSignal`.
      For the following snipped of code:
      ```lang=cpp
        if (options.parentDeathSignal_ != 0) {
          if (prctl(PR_SET_PDEATHSIG, options.parentDeathSignal_, 0, 0, 0) == -1) {
            return errno;
          }
        }
      ```
      LLVM generates the following assembly:
      ```lang=asm
         0x000000000040a77b <+347>:   mov    0x28(%r14),%rsi
         0x000000000040a77f <+351>:   test   %esi,%esi
         0x000000000040a781 <+353>:   je     0x40a7a1 <folly::Subprocess::prepareChild(folly::Subprocess::Options const&, __sigset_t const*, char const*) const+385>
         0x000000000040a783 <+355>:   mov    $0x1,%edi
         0x000000000040a788 <+360>:   xor    %edx,%edx
         0x000000000040a78a <+362>:   xor    %ecx,%ecx
         0x000000000040a78c <+364>:   xor    %r8d,%r8d
         0x000000000040a78f <+367>:   xor    %eax,%eax
         0x000000000040a791 <+369>:   callq  0x405ad0 <prctl@plt>
      ```
      `%rsi` is a 64-bit register, on the line 1 value of `0x28(%r14)` is loaded to this register. That address points to `options.parentDeathSignal_`, which is a 32-bit value, set to 10 somewhere in a test. After that load:
      ```
      rsi            0x7f000000000a
      ```
      Notice it is not 10 (0xa), there is some garbage value in the upper part of the register. On the line 2, the lower part of this register is checked if it is zero, which corresponds to the first if statement. Then lines 4-8 prepare for `prctl` call. The value of the second argument is passed via `%rsi`, but the upper 32 bits were not cleared. This makes the function call generate `Invalid argument` error.
      With the added explicit cast, notice a call `movslq %eax,%rsi`, which moves a signed 32-bit value of `%eax` (which contains `options.parentDeathSignal_`) to unsigned 64-bin `%rsi`:
      ```
         0x000000000040a77b <+347>:   mov    0x28(%r14),%rax
         0x000000000040a77f <+351>:   test   %eax,%eax
         0x000000000040a781 <+353>:   je     0x40a7a4 <folly::Subprocess::prepareChild(folly::Subprocess::Options const&, __sigset_t const*, char const*) const+388>
         0x000000000040a783 <+355>:   movslq %eax,%rsi
         0x000000000040a786 <+358>:   mov    $0x1,%edi
         0x000000000040a78b <+363>:   xor    %edx,%edx
         0x000000000040a78d <+365>:   xor    %ecx,%ecx
         0x000000000040a78f <+367>:   xor    %r8d,%r8d
         0x000000000040a792 <+370>:   xor    %eax,%eax
         0x000000000040a794 <+372>:   callq  0x405ad0 <prctl@plt>
      ```
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3051611
      
      fb-gh-sync-id: fc0f809bc4be0eed79dc5a701717efa27fedc022
      shipit-source-id: fc0f809bc4be0eed79dc5a701717efa27fedc022
      8c3d9fba
    • Phil Willoughby's avatar
      Convert a polling loop to a futex wait · d43e710c
      Phil Willoughby authored
      Summary:Add a new method to MPMCQueue:
      ```
      template <class Clock, typename... Args>
        bool tryWriteUntil(const std::chrono::time_point<Clock>& when,
                           Args&&... args) noexcept
      ```
      This allows you to write producers which terminate reliably in the absence of consumers.
      
      Returns `true` if `args` was enqueued, `false` otherwise.
      
      `Clock` must be one of the types supported by the underlying call to `folly::detail::Futex::futexWaitUntil`; at time of writing these are `std::chrono::steady_clock` and `std::chrono::system_clock`.
      
      Reviewed By: nbronson
      
      Differential Revision: D2895574
      
      fb-gh-sync-id: bdfabcd043191c149f1271e30ffc28476cc8a36e
      shipit-source-id: bdfabcd043191c149f1271e30ffc28476cc8a36e
      d43e710c
    • Subodh Iyengar's avatar
      Allow httpsession to be movable readCB · f509d73d
      Subodh Iyengar authored
      Summary:Allow HTTPSession to have a movable read
      callback independent of the openssl check.
      
      This allows other downstream transports to
      deliver app data more efficiently.
      
      Reviewed By: w-o-o, knekritz
      
      Differential Revision: D3023517
      
      fb-gh-sync-id: ff27c0e14f7364ad7d7b0028ef740b2678dbcb4c
      shipit-source-id: ff27c0e14f7364ad7d7b0028ef740b2678dbcb4c
      f509d73d
    • Michael Lee's avatar
      Missing guards for FOLLY_TLS in test · f4a80a41
      Michael Lee authored
      Summary:defined(FOLLY_TLS) is guarded once in the test, so we should
      guard for it throughout.  Also a missing header for some platforms.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3049797
      
      fb-gh-sync-id: 5d66c71dda94c57a2e50aee96d55be1c574bf921
      shipit-source-id: 5d66c71dda94c57a2e50aee96d55be1c574bf921
      f4a80a41