1. 30 May, 2016 4 commits
    • Christopher Dykes's avatar
      Switch uses of <sys/resource.h> to <folly/portability/SysResource.h> · 79fe4911
      Christopher Dykes authored
      Summary: Diff #4 of 14.
      
      Reviewed By: mzlee
      
      Differential Revision: D3181101
      
      fbshipit-source-id: d0db67ae19ee71e6a251c299ef672baead3ab9d9
      79fe4911
    • Christopher Dykes's avatar
      Switch uses of <sys/mman.h> to <folly/portability/SysMman.h> · 866e9b2f
      Christopher Dykes authored
      Summary: Diff #3 of 14.
      
      Reviewed By: mzlee
      
      Differential Revision: D3110299
      
      fbshipit-source-id: 39e4980df14b0b108b20dbbe57f2c5c6b361ea2e
      866e9b2f
    • Christopher Dykes's avatar
      Switch uses of <sys/file.h> to <folly/portability/SysFile.h> · 64ed63b2
      Christopher Dykes authored
      Summary: Diff #2 of 14.
      
      Reviewed By: mzlee
      
      Differential Revision: D3115972
      
      fbshipit-source-id: c75cbc95f37e8f2c2bf81311a8ca08ee766fc107
      64ed63b2
    • Christopher Dykes's avatar
      Include <folly/portability/SysTime.h> rather than <sys/time.h> · 6ca321dc
      Christopher Dykes authored
      Summary:
      This changes includes of `<sys/time.h>` to `<folly/portability/SysTime.h>`.
      
      The ultimate goal of all of this is to get HHVM compiling on Windows with MSVC 2015. At the moment there are no plans to support MCRouter, Squangle, or AFDT under Windows. There are also no current plans to support MinGW or Cygwin.
      
      Now, on to the headers themselves. There are three primary kinds of portability headers.
      
        - Replacement headers. These are headers such as `<sys/time.h>` that MSVC simply does not have. These headers should always be included instead of the headers they are replacing.
        - Additive headers. These are headers, such as `<time.h>` that MSVC has, but are either missing functions, or has the functions but under a different name. The portability headers for these only needs to be included instead of the original header if you are using a function that MSVC does not have. The reason for this is that forcing the use of the portability header for `<stdlib.h>` just because MSVC doesn't have `mkdtemp` and `realpath` would just be messy.
        - Utility headers. These are portability headers, such as `Memory.h` that exist to provide a portable interface to various things, in this case the allocation and freeing of aligned memory. They are not implementing any existing API, and all contents are in the `folly` namespace.
      
      The API's implemented in the first and second types of headers are intended as drop-in replacements for the Linux versions, however they only implement the functions and features that are actually needed, and are not intended as feature-complete replacements. They are not intended for use outside of Facebook projects. Any API's expecting text input expect them to be in the same encoding as the Posix API's define, in most cases that means UTF-8. Anywhere in the portability headers that fails to account for this is a bug, and should be pointed out in the diff (if it's still in review), or else by filing a task detailing the issue and assigning it to me.
      
      For all headers, if there is a mechanism in C++11, or else in Folly itself, that allows the same functionality, that mechanism should be used instead of adding a function to the portability headers.
      
      Reviewed By: swtaarrs, yfeldblum
      
      Differential Revision: D3095643
      
      fbshipit-source-id: 3a5c0029f95b03ea320725df88e14a67ca38a445
      6ca321dc
  2. 28 May, 2016 3 commits
    • Adam Simpkins's avatar
      add Cursor::readWhile() and skipWhile() · 792e823b
      Adam Simpkins authored
      Summary:
      Add generic functions for reading or skipping until a predicate check fails.
      This will allow us to simplify a few different call sites that have their own
      logic similar to this.  Also change readTerminatedString() to use
      readWhile().
      
      Reviewed By: alandau
      
      Differential Revision: D3337581
      
      fbshipit-source-id: 9f50914c83adfc882219046862972661bed0e72a
      792e823b
    • Ben Hamilton's avatar
      Fix test/ProducerConsumerQueueTest.cpp build break · e9ebf3f4
      Ben Hamilton authored
      Summary:
      The Folly `make check` build is broken with Clang on OS X.
      
      This diff fixes the following break in `test/ProducerConsumerQueueTest.cpp`:
      
        In file included from ProducerConsumerQueueTest.cpp:17:
        ../../folly/ProducerConsumerQueue.h:55:18: error: no member named 'bad_alloc' in namespace 'std'
              throw std::bad_alloc();
      
      The problem is a missing `#include <memory>` in `folly/ProducerConsumerQueue.h`.
      
      Reviewed By: djwatson
      
      Differential Revision: D3361252
      
      fbshipit-source-id: d740914f54ede5617abc16437ab2e20a7376f6e5
      e9ebf3f4
    • Ben Hamilton's avatar
      Fix test/FunctionTest.cpp build breaks · f70249c0
      Ben Hamilton authored
      Summary:
      The Folly `make check` build is broken with Clang on OS X.
      
      This diff fixes two breaks in `test/FunctionTest.cpp`:
      
      1. `FunctionTest.cpp:39:20: error: implicit instantiation of undefined template 'std::__1::array<int, 100>'`
      2. `FunctionTest.cpp:103:3: error: no matching conversion for functional-style cast from 'Function<int (int)>' to '::testing::AssertionResult'`
      
      The first was a missing `#include <array>`, and the second is a workaround for this gtest bug:
      https://github.com/google/googletest/issues/429
      
      Reviewed By: djwatson
      
      Differential Revision: D3361188
      
      fbshipit-source-id: 8140de978a2cbaf0f4aab45781ce0d656f03202b
      f70249c0
  3. 27 May, 2016 5 commits
    • Ben Hamilton's avatar
      Fix open source `make check` build broken by `ThreadedExecutorTest.cpp` moving to `wangle` · ca729c2e
      Ben Hamilton authored
      Summary:
      The Folly `make check` build is broken with Clang on OS X.
      
      This diff fixes the following break in `make check`:
      
        make[3]: *** No rule to make target `../futures/test/ThreadedExecutorTest.cpp', needed by `../futures/test/ThreadedExecutorTest.o'.  Stop.
      
      The problem is a reference to a file which was moved to `wangle` in D3286988.
      
      Reviewed By: simpkins
      
      Differential Revision: D3361287
      
      fbshipit-source-id: a9ae794374982b4accf806bd9608988430c75cfd
      ca729c2e
    • Yang Chi's avatar
      Set bufferCallback_ back to nullptr upon HTTPSession shutdown · 5451eeae
      Yang Chi authored
      Summary: AsyncSocket::handleWrite may trigger HTTPSession::onWriteSuccess which may totally delete the HTTPSession. AsyncSocket::handleWrite also calls bufferCallback_->onEgressBufferCleared(). That bufferCallback_ is the HTTPSession. So in this diff resets bufferCallback_ to nullptr upon HTTPSession shutdown. afrind had a suggestion of adding a DestructorGuard in AsyncSocket::handleWrite. But i don't know DestructorGuard that well. I think it will keep AsyncSocket from being deleted but not the HTTPSession? Or maybe I can DestructorGuard dg(bufferCallback_) ?
      
      Reviewed By: afrind
      
      Differential Revision: D3311058
      
      fbshipit-source-id: cdb5fcbd53837a3effbc096eab87fca4e5d17291
      5451eeae
    • Subodh Iyengar's avatar
      Fix test for corking · 8eaa9657
      Subodh Iyengar authored
      Summary:
      Min rto is now 50ms, so change the
      test accordingly
      
      Reviewed By: w-o-o
      
      Differential Revision: D3357140
      
      fbshipit-source-id: 5a807fabc1a3c216a5120b8eb4930e5c1eb52b7a
      8eaa9657
    • Giuseppe Ottaviano's avatar
      Use exponential growth in fbstring::append(size_type n, value_type c) · 7931ecb1
      Giuseppe Ottaviano authored
      Summary:
      Contrary to the other `append` flavors, `fbstring::append(size_type n, value_type c)`
      does not use exponential growth, which can trigger quadratic behavior.
      
      Reviewed By: philippv
      
      Differential Revision: D3357315
      
      fbshipit-source-id: 2301ed1a9953544368663107113890a25c6621ae
      7931ecb1
    • Christopher Dykes's avatar
      Disable a couple of warnings for MSVC in folly::Function · 555cbaae
      Christopher Dykes authored
      Summary:
      MSVC generates warnings if you define multiple assignment operators or multiple copy constructors on the same type. This is deliberate in `folly::Function`, so just disable the warnings for the struct instead.
      Note that the warnings have to be disabled for the entire struct for them to actually be disabled. Disabling them just around the declarations of the constructors and operators in question does not actually disable the warnings.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3347746
      
      fbshipit-source-id: abb53a1e62bcfb7ce02759a7ce8637d824a82081
      555cbaae
  4. 26 May, 2016 6 commits
    • Adam Simpkins's avatar
      move io/Cursor-defs.h to io/Cursor.cpp · 1fa49a2e
      Adam Simpkins authored
      Summary:
      The two function definitions in this file are both normal function definitions,
      not template functions.  Therefore this should be just a normal .cpp file, and
      not a -defs.h header file.
      
      Reviewed By: igorsugak
      
      Differential Revision: D3348439
      
      fbshipit-source-id: 3ebe49c84493f5aab06c568d9df15a37c2c48836
      1fa49a2e
    • Adam Simpkins's avatar
      add a default Subprocess constructor · c59d3032
      Adam Simpkins authored
      Summary:
      The default constructor creates the Subprocess in an uninitialized state.  This
      makes it possible to default-construct a Subprocess, but only initialize it
      later using the move assignment operator.
      
      Even before this diff, it was possible to have Subprocess objects in
      uninitialized states after using the move assignment operator to move the data
      out of a Subprocess object.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3348490
      
      fbshipit-source-id: aa6acef9be770de8f0ee118da294cb134f04a466
      c59d3032
    • Christopher Dykes's avatar
      Disable the signal stack on Windows · f2423568
      Christopher Dykes authored
      Summary: There is no equivalent functionality for Windows, so disable it completely.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3348481
      
      fbshipit-source-id: 52a104f5a8013113f54d5b10c2f0f9b720eeb4f6
      f2423568
    • Christopher Dykes's avatar
      Remove the declaration of TimeseriesHistogram::getBucketIdx · dfea2768
      Christopher Dykes authored
      Summary: Because, as MSVC rightly tells us, it's not actually defined anywhere.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3347654
      
      fbshipit-source-id: 2162bc745136ee0129caa4de78f38e1361083cd1
      dfea2768
    • Christopher Dykes's avatar
      Include <folly/portability/Windows.h> in folly::format · aa4253e7
      Christopher Dykes authored
      Summary:
      Because apparently I didn't actually add the `Windows.h` include when I added support for MSVC.
      This is safe for all platforms because the portability header only includes `Windows.h` when compiling on Windows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3347785
      
      fbshipit-source-id: 4f3e4e6c11953e2588b6fed287324a92e3ef8873
      aa4253e7
    • Christopher Dykes's avatar
      Fix doVecOperation in the SysUio portability header · 46f41dca
      Christopher Dykes authored
      Summary: Apparently I failed to accurately transfer this particular change to fbcode, which meant it didn't actually compile on Windows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3347976
      
      fbshipit-source-id: 775682f10ab68672f6463ccc69a222ae0a52a097
      46f41dca
  5. 25 May, 2016 1 commit
    • Adam Simpkins's avatar
      add Cursor::peekBytes() · 6a6efad5
      Adam Simpkins authored
      Summary:
      The existing Cursor::peek() method pre-dates the existence of folly::ByteRange,
      and so it returns a std::pair containing a pointer and length.  This is usually
      more awkward to use than ByteRange.
      
      This adds a peekBytes() method that returns a ByteRange object, and updates all
      users of peek() in folly to use peekBytes() instead.  Eventually I think we
      should add a FOLLY_DEPRECATED attribute to peek().  I will wait to add this tag
      until after converting a few other projects to use peekBytes(), though.
      
      Reviewed By: alandau
      
      Differential Revision: D3337302
      
      fbshipit-source-id: 14220a059d915bf5adc66b8b283f7228b796a4dc
      6a6efad5
  6. 24 May, 2016 5 commits
    • Jon Maltiel Swenson's avatar
      std::make_unique -> folly::make_unique · 1f4f1754
      Jon Maltiel Swenson authored
      Summary:
      We should use folly::make_unique instead of std::make_unique in order to support
      compilers without support for C++14.
      
      Reviewed By: pavlo-fb
      
      Differential Revision: D3343288
      
      fbshipit-source-id: 9150af752e57988962a7580851ffa32086c669d7
      1f4f1754
    • Christopher Dykes's avatar
      Update generate_varint_tables to support MSVC · 42c850c0
      Christopher Dykes authored
      Summary: MSVC is a massive pain in this respect, and, after testing many workarounds, and only ending up with it just emitting a dynamic initializer for them, it's easier to just generate the table as a `uint64_t` and load it explicitly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3270226
      
      fbshipit-source-id: 77bc84e58d393373de05a28a30dcb80b66c09c9f
      42c850c0
    • Joseph Griego's avatar
      Clear old fs::path when moving a TemporaryDirectory · e6edf05a
      Joseph Griego authored
      Summary:
      If a TemporaryDirectory with scope DELETE_ON_DESTRUCTION gets moved
      and then goes out of scope, the directory will be deleted while the moved
      object still holds that path; we just clear the path from the old object to
      prevent this
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3331079
      
      fbshipit-source-id: 9c99413661e2436ccec937d3fa652da810133b34
      e6edf05a
    • Chad Parry's avatar
      Switch HHWheelTimer::SharedPtr to a standard shared pointer · 81959105
      Chad Parry authored
      Summary:
      As part of my campaign to get `HHWheelTimer` away from intrusive ref-counting semantics, (cf. D3237530), I am redefining `HHWheelTimer::SharedPtr`. It is now a true `std::shared_ptr`. This will break clients that attempt the following:
      
        HHWheelTimer::UniquePtr timer1{HHWheelTimer::newTimer()};
        HHWheelTimer::SharedPtr timer2{timer1};
      
      In the past, that code would compile, because `timer2` could use the intrusive ref-counting, and `timer1` would still be valid. After this change, the second timer would need to be initialized with `std::move(timer1)` instead. The `UniquePtr` is starting to actually be unique.
      
      There is only one place in the code that actually tries to do such a copy. It's in a test, which I have changed. Any other instances of that behavior would create a compilation error, so it's impossible for one to be overlooked.
      
      Reviewed By: djwatson
      
      Differential Revision: D3337038
      
      fbshipit-source-id: 085e4da41c9a142d253a1ac0b1dd0fc508dff704
      81959105
    • Christopher Dykes's avatar
      Support folly::assume under MSVC · 0558fb60
      Christopher Dykes authored
      Summary: Actually __assume when we assume.
      
      Reviewed By: meyering
      
      Differential Revision: D3336033
      
      fbshipit-source-id: 6c931e9f832dd1d861d03e3ad8e308f612522401
      0558fb60
  7. 23 May, 2016 1 commit
    • Yedidya Feldblum's avatar
      Avoid std::initializer_list ctor in folly::dynamic::array · b939def1
      Yedidya Feldblum authored
      Summary:
      [Folly] Avoid `std::initializer_list` ctor in `folly::dynamic::array`.
      
      This will help deprecate the dangerous initializer-list constructor. The init-list construction is dangerous because its semantics vary by compiler and by compiler version.
      
      Reviewed By: ot
      
      Differential Revision: D3333148
      
      fbshipit-source-id: 031e7593b7e28b299d5eeeb5ce7aed9216dd3a5c
      b939def1
  8. 20 May, 2016 3 commits
    • Andrii Grynenko's avatar
      Make outstanding LoopKeepAlive hold EventBase destructor · 0f76e090
      Andrii Grynenko authored
      Summary:
      LoopKeepAlive handle can be grabbed to signal that some external event will later be scheduled on the EventBase via runInEventBaseThread. Usually the code which will be calling runInEventBaseThread only has a raw pointer to an EventBase, so it doesn't have any way to know it was destroyed.
      
      This change ensures that EventBase destructor will keep running the event loop until all such LoopKeepAlive handles are released.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3323835
      
      fbshipit-source-id: 4071dae691a61dfebe2f1759cf99f661b161fa4a
      0f76e090
    • Christopher Dykes's avatar
      Fix the detection of preadv and pwritev on OSX in OSS · f464accb
      Christopher Dykes authored
      Summary:
      The configure script doesn't define `FOLLY_HAVE_PREADV` if `preadv` isn't supported, so these checks were wrong. Undefined defines expand to `0`, so this is safe.
      Fixes https://github.com/facebook/folly/issues/412
      
      Reviewed By: mzlee, yfeldblum
      
      Differential Revision: D3329405
      
      fbshipit-source-id: faee8951c68d4c67e06e7720dfc142e63a9dbd9f
      f464accb
    • Shubhanshu Agrawal's avatar
      templating folly::fibers::await by Baton · 10c76792
      Shubhanshu Agrawal authored
      Summary:
      This diff templates folly::fibers::await by Baton.
      This would be helpful in passing in custom BatonType's, which is needed for D3007734
      
      Depends on: D3314891
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3314925
      
      fbshipit-source-id: 9052dc503b9509f16cd41b5e3ede0479a98067aa
      10c76792
  9. 19 May, 2016 8 commits
    • Alejandro's avatar
      Promote memory_order_consume to memory_order_acquire · 05cdf111
      Alejandro authored
      Summary:
      The current use case of `std::memory_order_consume` in this project was intended to provide the appropriate synchronization in cases where a consumer spins on `while( spsc_queue.empty() ) {} `, and then attempts to use an element of the queue since the loop was broken out of, according to comments [here](https://reviews.facebook.net/D48141). Consume semantics do not provide this guarantee according to the standard since there is no data dependency from the producer that can be carried to the consumer by doing a load-consume from the corresponding functions. What is needed is a load-acquire. Current compilers promote `memory_order_consume` to `memory_order_acquire`. Thus, this example appears to work simply due to the promotion from consume to acquire, but would fail to generate the right synchronization instructions on weaker architectures once `memory_order_consume` is implemented as intended.  Therefore, the `memory_order` should be tightened to `memory_order_acquire` to guarantee visibility to the consumer
      Closes https://github.com/facebook/folly/pull/381
      
      Reviewed By: djwatson
      
      Differential Revision: D3173574
      
      Pulled By: nbronson
      
      fbshipit-source-id: b109be2e74f016750a3fe1f848e3fc66e609b9d2
      05cdf111
    • Yedidya Feldblum's avatar
      Extract Try to top-level · a56a988a
      Yedidya Feldblum authored
      Summary:
      [Folly] Extract `Try` to top-level.
      
      It was in `folly/futures/`, but this diff moves it to `folly/`.
      
      It is needed for futures, but it is are more general than futures and can be used separately.
      
      Use `folly/Try.h` instead of `folly/futures/Try.h`.
      
      Also fixes up all `#include` sites:
      
          hg grep -lw folly/futures/Try | xargs perl -pi -e 's,\bfolly/futures/Try\b,folly/Try,g'
      
      Reviewed By: markisaa
      
      Differential Revision: D3309908
      
      fbshipit-source-id: cdf13f0ac0b0e36aa07e0f1d04870d06500c5874
      a56a988a
    • Lucian Grijincu's avatar
      folly: FBString: avoid ubsan in assert · 4d78cf49
      Lucian Grijincu authored
      Summary:
      ```
      buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:365:7: runtime error: null pointer passed as argument 2, which is declared to never be null
      third-party-buck/build/glibc/include/string.h:70:33: note: nonnull attribute specified here
          #0 0x433a39 in _ZZN5folly13fbstring_coreIcEC1EPKcmbENKUlvE_clEv ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:365:7
          #1 0x4335a9 in _ZN5folly14ScopeGuardImplIZNS_13fbstring_coreIcEC1EPKcmbEUlvE_E7executeEv ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/ScopeGuard.h:153:29
          #2 0x4335a9 in _ZN5folly14ScopeGuardImplIZNS_13fbstring_coreIcEC1EPKcmbEUlvE_ED2Ev ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/ScopeGuard.h:130
          #3 0x4335a9 in folly::fbstring_core<char>::fbstring_core(char const*, unsigned long, bool) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:427
          #4 0x4353fa in folly::basic_fbstring<char, std::char_traits<char>, std::allocator<char>, folly::fbstring_core<char> >::basic_fbstring(char const*, unsigned long, std::allocator<char> const&) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////buck-out/gen/folly/__default_headers__#default,headers/folly/FBString.h:1038:9
      ```
      
      Reviewed By: Gownta
      
      Differential Revision: D3321266
      
      fbshipit-source-id: 28d5aef16e91a98066a1de6bab95403fbc63eaab
      4d78cf49
    • Andrii Grynenko's avatar
      Move fibers out of experimental · 2622d2f3
      Andrii Grynenko authored
      Summary: folly::fibers have been used by mcrouter for more than 2 years, so not really experimental.
      
      Reviewed By: pavlo-fb
      
      Differential Revision: D3320595
      
      fbshipit-source-id: 68188f92b71a4206d57222993848521ca5437ef5
      2622d2f3
    • Shubhanshu Agrawal's avatar
      adding Promise::await · 6698301a
      Shubhanshu Agrawal authored
      Summary:
      This diff adds a static await method to Promise.
      Also after this, folly::fibers::await is just a wrapper around Promise::await.
      This also removes the friend relationship between Promise and await.
      
      This would be helpful in making the folly::fibers::await templated by Baton changes easier to make.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3314891
      
      fbshipit-source-id: 361546c078caafd067734d2f474c617d7fb888b0
      6698301a
    • Yedidya Feldblum's avatar
      Make Try independent of Future · 75f97748
      Yedidya Feldblum authored
      Summary:
      [Folly] Make `Try` independent of `Future`.
      
      `Try` is useful for futures, but it can be used independently from futures as well.
      
      Reviewed By: djwatson
      
      Differential Revision: D3319130
      
      fbshipit-source-id: badfcaa482dee6e7bdef14a501b4efc91634fa51
      75f97748
    • Andrii Grynenko's avatar
      Export documentation from dex to folly · fdf0474b
      Andrii Grynenko authored
      Reviewed By: yfeldblum
      
      Differential Revision: D3317666
      
      fbshipit-source-id: f5558b117c8da74789ee444cdaa00231e75dc31e
      fdf0474b
    • iivlev's avatar
      Fixing typo in Readme · 6bb67df0
      iivlev authored
      Summary: Closes https://github.com/facebook/folly/pull/403
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3320043
      
      Pulled By: elliottneilclark
      
      fbshipit-source-id: 5d21421216180fb601015a40a3de79e3dd2a162e
      6bb67df0
  10. 18 May, 2016 4 commits
    • Yedidya Feldblum's avatar
      Flesh out the comments about Unit · 004d6c17
      Yedidya Feldblum authored
      Summary:
      [Folly] Flesh out the comments about `Unit`.
      
      * Remove mention of `Future`.
      * Compare `unit` to `void`.
      
      Reviewed By: djwatson
      
      Differential Revision: D3316114
      
      fbshipit-source-id: d30cf36cc029025734bb16c5bdbd640a289cad79
      004d6c17
    • Yedidya Feldblum's avatar
      Extract Unit to top-level · a3323738
      Yedidya Feldblum authored
      Summary:
      [Folly] Extract `Unit` to top-level.
      
      It was in `folly/futures/`, but this diff moves it to `folly/`. It is needed for futures, but it is more general than futures and can be used separately.
      
      Users must replace `folly/futures/Unit.h` with `folly/Unit.h`.
      
      Also codemods existing usage sites:
      
      ```
      hg grep -lw folly/futures/Unit.h | xargs perl -pi -e 's,\bfolly/futures/Unit\.h\b,folly/Unit.h,g'
      ```
      
      Reviewed By: igorsugak
      
      Differential Revision: D3314280
      
      fbshipit-source-id: 16279b76b1d24529bec49077ccb36cd7d39f23b8
      a3323738
    • Ilya Maykov's avatar
      added IOBuf::wrapBufferAsValue() · 6b5a25fc
      Ilya Maykov authored
      Summary:
      Added a version of IOBuf::wrapBuffer() which returns the new IOBuf by value rather than heap-allocating it.
      Motivation: we have a lot of places in the crypto code that do something like this:
      
        // take a string or vector parameter
        auto buf = folly::IOBuf::wrapBuffer( /* string or vector goes here */);
        // do something with buf
        // return
      
      In these cases, a stack-allocated IOBuf would save us from an unnecessary heap allocation. But calling `folly::IOBuf(folly::IOBuf::WrapBufferOp::WRAP_BUFFER, ...)` is gross and in practice people just call the much more readable `wrapBuffer()` function. Hypothesis: readability trumps performance, but if we had a readable version that returned a stack-allocated IOBuf, it might see usage.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3314037
      
      fbshipit-source-id: 4d4b5ec1d067762a27de1d7d6f7cac406388bfa3
      6b5a25fc
    • Andrii Grynenko's avatar
      Fix one more race in Promise::setTry · 4ffd39d6
      Andrii Grynenko authored
      Summary:
      Baton::post has to be the last step of Promise::setTry. If Promise is not owned by
      the posting thread, it may be destroyed right after Baton::post is called.
      
      Reviewed By: pavlo-fb
      
      Differential Revision: D3312506
      
      fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189
      4ffd39d6