1. 16 Jun, 2016 2 commits
    • Eric Niebler's avatar
      folly: fix clang's -Wundefined-var-template · 7570fc58
      Eric Niebler authored
      Summary:
      [temp] (14)/6:
      > A function template, member function of a class template, variable template, or static data member of a class template shall be defined in every translation unit in which it is implicitly instantiated (14.7.1) unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required.
      
      `-Wundefined-var-template` warns on any implicit instantiations that are needed but could not be performed because the definition is not available. In particular, for valid code, this warns on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) - used a few times in folly. This seems a bad style, the static data member template should either be defined in the header file or should be explicitly instantiated in each .cpp file.
      
      Reviewed By: igorsugak
      
      Differential Revision: D3270439
      
      fbshipit-source-id: bf305fde3af575a265d65a0ae0bf95db5597587f
      7570fc58
    • Blake Lawson's avatar
      Added limited list of supported ciphers · 8fb2b024
      Blake Lawson authored
      Summary: Added method to enable server support for a specific elliptic curve encryption algorithm.
      
      Reviewed By: siyengar
      
      Differential Revision: D3432860
      
      fbshipit-source-id: 078531eead48ea156a68a109f8a62dc4907ac1ec
      8fb2b024
  2. 15 Jun, 2016 2 commits
    • Haocheng Zhang's avatar
      fix bug for nullptr in qfind · 1de25658
      Haocheng Zhang authored
      Summary: Fix bug for passing null pointer to memchr function, which requires the first argument to never be null.
      
      Reviewed By: luciang
      
      Differential Revision: D3432130
      
      fbshipit-source-id: 419924dd214d9f641d3d46335dae6abbe44ca751
      1de25658
    • Caren Thomas's avatar
      Add constructor for MultiLevelTimeSeries class that uses initializer_list and... · bd6447c6
      Caren Thomas authored
      Add constructor for MultiLevelTimeSeries class that uses initializer_list and add stat methods that uses duration as a parameter.
      
      Summary: Introduce a constructor that takes in an initializer list of 'TimeType' objects for the durations. New methods for sum/avg/rate/count/countrate are created with a 'TimeType' parameter - this makes it possible to call these methods using the duration that specifies the level. Previously, these methods could only be called using the index of the level in the levels_ vector. These methods first do a linear scan through levels_ using the method getLevelsByDuration to find the corresponding index, and then perform the function they specify on the level.
      
      Differential Revision: D3414343
      
      fbshipit-source-id: 8e1fcc16fd013d0b8b855a1eebbeff417e945b07
      bd6447c6
  3. 14 Jun, 2016 4 commits
    • Marcus Holland-Moritz's avatar
      Add conv_benchmark target to Makefile.am · 55c9d0bd
      Marcus Holland-Moritz authored
      Summary: It's useful to be able to build & run the benchmark.
      
      Differential Revision: D3433731
      
      fbshipit-source-id: c37bd5be3da0f89d4792747857d2e7548aea08ba
      55c9d0bd
    • Michael Lee's avatar
      Reverted commit D3427621 · f5bdf4a3
      Michael Lee authored
      Summary: The iOS sdk adds `clock_gettime` support.
      
      Reviewed By: clementgenzmer
      
      Differential Revision: D3427621
      
      fbshipit-source-id: 534276ba1e0ade185e3af0665f419f3c51d3f980
      f5bdf4a3
    • Joseph Griego's avatar
      EventBase keepAlive counter is not atomic · cafe469a
      Joseph Griego authored
      Summary: Since loopKeepAlive() is always used from the EventBase thread, there's no need for the overhead of an shared_ptr (and therefore, an atomic ref counter); we can get away without thread safety. This also allows us to discard the (sometimes incorrect) optimization of not returning a handle when it appears the loop will continue running anyways
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3375503
      
      fbshipit-source-id: 474e4fcf992bdc4fcca9370d3c57bdcc4e042386
      cafe469a
    • Michael Lee's avatar
      Time.h portability for iOS 10. · f04cf0cd
      Michael Lee authored
      Summary: The iOS sdk adds `clock_gettime` support.
      
      Reviewed By: clementgenzmer
      
      Differential Revision: D3427621
      
      fbshipit-source-id: fcd3022c5ea05ceb8e289fbeb1ae845155d2dea9
      f04cf0cd
  4. 11 Jun, 2016 1 commit
    • Alexey Spiridonov's avatar
      DCHECK on reentrant invocations of loop() · 0806af8f
      Alexey Spiridonov authored
      Summary:
      I had a crash bug where an `EventBase` handler called a function, which tried to use the thread's EventBase as if it were its own:
      
      ```
      auto evb = folly::EventBaseManager::get()->getEventBase();
      // schedule work on evb, which calls evb->terminateLoopSoon() on completion
      evb->loopForever();
      ```
      
      This ended up invoking the `event_base_loop()` reentrantly, and corrupting the heap in a hard-to-debug way.
      
      Reviewed By: djwatson
      
      Differential Revision: D3408155
      
      fbshipit-source-id: b8855aa3b390fa33e032ab295d386122d2cb872a
      0806af8f
  5. 10 Jun, 2016 4 commits
    • Ben Hamilton's avatar
      Make Fibers library conditional on working Boost.Context fcontext_t · 52155e1d
      Ben Hamilton authored
      Summary:
      Boost 1.61 removes the `boost::context::fcontext_t` type
      which Folly Fibers depends on.
      
      This makes the Fibers library conditional on a working `fcontext_t`,
      so Folly will build (just without Fibers) if it's not present.
      
      Depends On D3419638
      
      Fixes https://github.com/facebook/folly/issues/413
      
      Reviewed By: Orvid
      
      Differential Revision: D3420097
      
      fbshipit-source-id: 876f8f76a2d0dda4ce5085c27875ab6aaa7b86c0
      52155e1d
    • Andrii Grynenko's avatar
      Fix folly::fibers on OSX with boost 1.60 · 6d52608a
      Andrii Grynenko authored
      Summary: We only need fcontext.hpp, so let's include it directly. all.hpp includes other headers, which use thread-locals (doesn't work with our OSX build).
      
      Reviewed By: igorsugak, bhamiltoncx
      
      Differential Revision: D3419638
      
      fbshipit-source-id: b4fa1bd14454bcd75eaece52c398ac6510273773
      6d52608a
    • Maged Michael's avatar
      Added support for std::mutex in folly Deterministic Schedule · 95c95660
      Maged Michael authored
      Summary:
      Added the class `DeterministicMutex`, a wrapper for `std::mutex`, in `folly/test/DeterministicSchedule.h`. Added a test to `folly/test/DeterministicScheduleTest.cpp` to test the correct behavior of `DeterministicMutex` functions and that deterministic schedule is able to detect race conditions that involve `DeterministicMutex`.
      
      Note: Bootcamp task
      
      Reviewed By: djwatson
      
      Differential Revision: D3412579
      
      fbshipit-source-id: c12861c4ec1cfeadcef027be4513e8e4cb7e0176
      95c95660
    • Marcus Holland-Moritz's avatar
      Get rid of circular dependency when including ExceptionWrapper.h from Conv.h · 500f3598
      Marcus Holland-Moritz authored
      Summary:
      This is needed in order to be able to use folly::Try<> with folly::to<> for
      non-throwing conversions.
      
      Reviewed By: meyering
      
      Differential Revision: D3411003
      
      fbshipit-source-id: 1f20e7871b9cedda2b35527dac70381579abd708
      500f3598
  6. 09 Jun, 2016 6 commits
    • Christopher Dykes's avatar
      Use intrinsics rather than inline assembly where possible · 1228a37d
      Christopher Dykes authored
      Summary:
      I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
      MSVC supports the intrinsics, which is the primary reason for the switch.
      
      Reviewed By: philippv
      
      Differential Revision: D3278901
      
      fbshipit-source-id: 60103ac7cf7ddfb529f65f4aadc687dbdaf423a1
      1228a37d
    • Chad Parry's avatar
      Allow a timer with pending callbacks to be destroyed · 3f6e3b45
      Chad Parry authored
      Summary:
      This diff is part of a string of changes that is getting `HHWheelTimer` to use standard smart pointers.
      
      D2617966 is being reverted. The `DestructorGuard` that was added for safety is not possible without intrusive reference counting.
      That means that the `count_` (of pending callbacks) will still be correct, but there will be nothing to check it against. Because of that, I removed the assertions to make sure that the count of pending callbacks matches the count of active guards. Anyway, there were already ways to defeat that test, such as by creating a `DestructorGuard` from any client code.
      As long as the assertions are gone, the `cancelAll` can be moved to the destructor. It only ever got run when `destroy` was called and `count_` was `0`, which means that `~HHWheelTimer` was also going to get called at the same time.
      
      Reviewed By: djwatson
      
      Differential Revision: D3349303
      
      fbshipit-source-id: 433fa6605ee9921833328e2f82bd07b2e17e42c5
      3f6e3b45
    • pravic's avatar
      Fix typo in docs/Function.md · 2488a9d5
      pravic authored
      Summary: Closes https://github.com/facebook/folly/pull/421
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3413832
      
      Pulled By: elliottneilclark
      
      fbshipit-source-id: 7af1462c250c8d6b5d6f5dfcb3f3117dff7877c9
      2488a9d5
    • Martin Martin's avatar
      Fix a data race found by TSAN in folly::fibers::Baton · e967876f
      Martin Martin authored
      Summary: Fix a data race found by TSAN in folly::fibers::Baton by changing a memory_order_relaxed to memory_order_acquire.  Nathan Bronson says that TSAN is correct and the C++ memory model requires _acquire here.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3412519
      
      fbshipit-source-id: bd0043b41d145e689a97fc7ef47aa6e116ea9194
      e967876f
    • David Callahan's avatar
      fix command line parsing · 3619ec97
      David Callahan authored
      Summary: parse command line flags to pick up -json flag
      
      Reviewed By: mzlee
      
      Differential Revision: D3405794
      
      fbshipit-source-id: e2d216c74f04c15d7470c70abfc2bd25c2ceda98
      3619ec97
    • Brett Simmers's avatar
      Allow const mapped types in folly::AtomicHash(Array|Map) · d4c0d267
      Brett Simmers authored
      Summary:
      Without this const_cast, it's impossible to insert anything into an
      AHA with a const mapped_type, making it effectively useless.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3405687
      
      fbshipit-source-id: 3ecba19e0e92661c2c537c747b4927176104939f
      d4c0d267
  7. 08 Jun, 2016 4 commits
    • Adam Simpkins's avatar
      make Range::size() constexpr · 8cb615a2
      Adam Simpkins authored
      Summary:
      Declare size() to return a constexpr value, so it can be called on constexpr
      Range objects.
      
      This unfortunately does drop the existing assert() check, due to a gcc bug:
      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71448
      
      Reviewed By: lbrandy
      
      Differential Revision: D3394612
      
      fbshipit-source-id: 77ea3b961dc323a39dea6f0e5850f9a311210d09
      8cb615a2
    • Christopher Dykes's avatar
      Pack PackedSyncPtr · 67a55881
      Christopher Dykes authored
      Summary: The comment was right about the packed attribute not liking private members, so pack `PackedSyncPtr` to get GCC to pack structs containing it correctly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3402936
      
      fbshipit-source-id: 11d9def132d5dedf04b0e263c379cac339a52fa3
      67a55881
    • Adam Simpkins's avatar
      add hexlify() and unhexlify() convenience methods · 8bac351a
      Adam Simpkins authored
      Summary:
      Add new versions of hexlify() and unhexlify() that directly return a
      std::string, similar to the helper functions that already exist for humanify()
      and backslashify().
      
      The function signatures for these helpers are different than the humanify() and
      backslashify() helpers--these functions always accept StringPiece or ByteRange
      arguments.  This allows them to easily accept "const char*" arguments, without
      having to convert the arguments to a std::string.  (I think we probably should
      fix the humanify() and backslashify() helpers to be similar in a separate
      diff.)
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3403863
      
      fbshipit-source-id: a2df49d5857e1d34caac3d78283dc293f4ef1ab6
      8bac351a
    • Andrii Grynenko's avatar
      Disable SIGSEGV signal handler if run in JVM · bbac9a99
      Andrii Grynenko authored
      Reviewed By: ldemailly
      
      Differential Revision: D3402550
      
      fbshipit-source-id: 3de47c569868545c3861dab9a7b244ed8fb1fadf
      bbac9a99
  8. 07 Jun, 2016 2 commits
    • Adam Radziwonczyk-Syta's avatar
      Expose current observer from FiberManager · 6da900e4
      Adam Radziwonczyk-Syta authored
      Summary:
      Inteded use case is to write tracing code in common components that can adjust its behavior to the current observer. E.g.
        auto* observer = FiberManager::getUnsafe()->getObserver();
        if (auto* specific_observer = dynamic_cast<SpecificObserver*>(observer)) {
          specific_observer->set_fiber_name(...);
        }
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3392890
      
      fbshipit-source-id: 284b4964bbb17e9a081779b870af68e8f1a81634
      6da900e4
    • Subodh Iyengar's avatar
      Add TFO support to AsyncSSLSocket · 889fe563
      Subodh Iyengar authored
      Summary:
      This adds TFO support to AsyncSSLSocket which
      uses the support for TFO from AsyncSocket.
      
      Because of the way AsyncSSLSocket inherits from
      AsyncSocket it is tricky.
      
      The following changes were made:
      1. Openssl internally will treat only errors with return
      code -1 as READ_REQUIRED or WRITE_REQUIRED errors. So this
      diff changes the return value of the errors in the TFO fallback
      cases to -1.
      
      2. In case we fallback after SSL_connect() to a normal connect,
      we would have to restart the connection process after connect
      succeeds. To do this this overrides the connection success callback
      and restarts the connection before sending the callback to AsyncSocket
      because sometimes callbacks might synchronously call sslConn() in the
      normal connect cases.
      
      3. Delegated bioWrite to call sendSocketMessage instead of sendmsg directly.
      
      Reviewed By: djwatson
      
      Differential Revision: D3391735
      
      fbshipit-source-id: 61434f6de4a9c3d03973c9ab9e51eb49e751e5cf
      889fe563
  9. 06 Jun, 2016 1 commit
  10. 04 Jun, 2016 3 commits
    • Christopher Dykes's avatar
      Allow constexpr construction of AtomicStruct under MSVC · 58d507c1
      Christopher Dykes authored
      Summary: Attempting to use this under MSVC, as `MemoryIdler::defaultIdleTimeout` does, generated warnings about the symbol being dynamically initialized due to an implementation limation. Solve this by defining a union instead of calling `encode` in the constructor.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3387916
      
      fbshipit-source-id: b0d628b6d086960e94121b6183a31348fb151aac
      58d507c1
    • Christopher Dykes's avatar
      Deal with a couple of warnings from MSVC · 5911efa1
      Christopher Dykes authored
      Summary: MSVC is warning that `client` may be uninitialized, which is possible if the callback doesn't actually set them for some reason. Solve that by explicitly initializing it to `nullptr`. Also deal with the warning about the initialization of `dynamic::array` using braced syntax by not using that syntax.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3387782
      
      fbshipit-source-id: e4d25ad32e99a73d7d062be9a2f2b5bde5d17396
      5911efa1
    • Christopher Dykes's avatar
      Remove a couple of MSVC portability defines · 65b5c3d2
      Christopher Dykes authored
      Summary: The first is both wrong (due to the difference in semantics) and unneeded, as MSVC 2015 supports `snprintf` natively and with the correct semantics. The second is simply never used.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3387551
      
      fbshipit-source-id: ea666a60ce859a59ad3d3ff961b4d7d642fd86eb
      65b5c3d2
  11. 03 Jun, 2016 2 commits
    • Andrii Grynenko's avatar
      Add a SIGSEGV signal handler which detects stack overflow · 9c0a6e4e
      Andrii Grynenko authored
      Summary: GuardPageAllocator now keeps a track of all protected pages. If SIGSEGV occurs, signal handler can check address at fault against protected pages and if it matches - we got a fiber stack overflow.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3386960
      
      fbshipit-source-id: 775b36ee08fecbbd87da0025f794717c222f5cce
      9c0a6e4e
    • Subodh Iyengar's avatar
      Always override write bio method · 8aac0e33
      Subodh Iyengar authored
      Summary:
      Always overriding write bio method
      allows us to more cleanly implement
      features like eor tracking, support
      multiple ssl libraries, and also TFO
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3350482
      
      fbshipit-source-id: ddd2333431f9d636d69c8325b2c18d7cc043b848
      8aac0e33
  12. 02 Jun, 2016 1 commit
    • Elliott Clark's avatar
      Update folly OSS build to use 1y · 9fc18f0a
      Elliott Clark authored
      Summary: use std=c++1y for compiling since we use c+=14 feautures but don't want to require a recent gcc.
      
      Reviewed By: bhamiltoncx
      
      Differential Revision: D3380287
      
      fbshipit-source-id: 8ece6007cf613d307bafe692f1af70f5359df95a
      9fc18f0a
  13. 01 Jun, 2016 5 commits
    • Christopher Dykes's avatar
      Assert that MicroSpinLock is a POD type · 708998eb
      Christopher Dykes authored
      Summary: Because if it's not, all hell will break lose (apparently).
      
      Reviewed By: meyering
      
      Differential Revision: D3373061
      
      fbshipit-source-id: f08a863d1bacadeeff9d9cea041f399f136cfc74
      708998eb
    • Christopher Dykes's avatar
      PackedSyncPtr.data_ is private · 9016ec6f
      Christopher Dykes authored
      Summary: As the (now removed) comment says, GCC 4.6 doesn't treat structs with private members as POD types... The thing is, GCC 4.6 is long dead, so make `data_` private and assert that it's a POD type.
      
      Reviewed By: meyering
      
      Differential Revision: D3373172
      
      fbshipit-source-id: b2f1ee59d544461fe986705164cc6c866af62865
      9016ec6f
    • Ben Hamilton's avatar
      Fix test/SynchronizedTest.cpp build break on Clang on OS X · 70497e41
      Ben Hamilton authored
      Summary:
      The Folly `make check` build is broken with Clang on OS X.
      
      This diff fixes the following break in `test/SynchronizedTest.cpp`:
      
        SynchronizedTest.cpp:150:10: error: thread-local storage is not supported for the current target
          static thread_local int lockCount_;
      
      The problem is clang on OS X doesn't support the `thread_local` extension:
      
      http://stackoverflow.com/a/29929949
      
      so we now use the `FOLLY_TLS` compatibility macro.
      
      When I fixed this, I found the test also failed to compile if `FOLLY_SYNCHRONIZED_HAVE_TIMED_MUTEXES` was `#define`d to `0` (as it is on OS X), so I fixed that.
      
      Reviewed By: mzlee
      
      Differential Revision: D3361215
      
      fbshipit-source-id: e93be6872bcab03090448b9421e502e472f149ff
      70497e41
    • Christopher Dykes's avatar
      SingletonVault_c.cpp is always C++ · 3fe4dacd
      Christopher Dykes authored
      Summary: It's simply not possible to compile the C++ side of the C API as C, so don't guard the `extern "C"` as if it is.
      
      Reviewed By: meyering, yfeldblum
      
      Differential Revision: D3369474
      
      fbshipit-source-id: d3316704ce17a471bc9d6a3a235472bf40cedb9d
      3fe4dacd
    • Subodh Iyengar's avatar
      Methods to change cipher suite list · 7030ff9c
      Subodh Iyengar authored
      Summary: Add methods to change cipher suite list and sigalg list
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3295935
      
      fbshipit-source-id: eb46311986465e399eafa69e3070b53b36bce820
      7030ff9c
  14. 31 May, 2016 3 commits
    • Michael Lee's avatar
      SocketFastOpen should include <cerrno> · b5526698
      Michael Lee authored
      Summary: Include cerrno to define `EOPNOTSUPP` and `ENOPROTOOPT`.
      
      Reviewed By: elindsey
      
      Differential Revision: D3366479
      
      fbshipit-source-id: 3a93a1c247ffa4a9d4ea03577713362a2a35c8b7
      b5526698
    • Michael Lee's avatar
      SubprocessTest does not use dirent.h · b1055eef
      Michael Lee authored
      Summary: Remove it as we do not need it here.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3365991
      
      fbshipit-source-id: bb36caca0319df4c8d6e3d978045b7c28369f043
      b1055eef
    • Subodh Iyengar's avatar
      Add support for TFO connections · 53912945
      Subodh Iyengar authored
      Summary:
      This adds support to establish connections
      over TFO.
      
      The API introduced here retains the same
      connect() + write() api that clients currently
      use.
      
      If enableTFO() is called then the connect will
      be deferred to the first write. This only works
      with request response protocols since a write
      must trigger the connect. There is a tradeoff here
      for the simpler API, and we can address this with
      other signals such as a short timeout in the future.
      
      Even though the client might enable TFO, the program
      might run on machines without TFO support.
      There were 2 choices for supporting machines where
      TFO might not be enabled:
      1. Fallback to normal connect if tfo sendmsg fails
      2. Check tfo supported on the machine before using it
      
      Both these have their tradeoffs, however option 1 does
      not require us to read from procfs in the common code
      path.
      
      Reviewed By: Orvid
      
      Differential Revision: D3327480
      
      fbshipit-source-id: 9ac3a0c7ad2d206b158fdc305641fedbd93aa44d
      53912945