1. 06 Jul, 2016 2 commits
    • Adam Simpkins's avatar
      update Synchronized to use LockTraits · c9fd5aed
      Adam Simpkins authored
      Summary:
      Update the Synchronized code to use the new LockTraits added in D3504625.
      This also removes the acquireRead*() and releaseRead*() adapter functions that
      had been defined for various other lock types, which are no longer needed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3512310
      
      fbshipit-source-id: daedd47c0378aebd479dbfe7aba24978deb9cc05
      c9fd5aed
    • Adam Simpkins's avatar
      add LockTraits · 9276f2a5
      Adam Simpkins authored
      Summary:
      This adds a new LockTraits template class, for specifying how to use arbitrary
      custom mutex types.
      
      The goal of this new class is to replace the acquireRead(), acquireReadWrite(),
      releaseRead(), and releaseReadWrite() functions currently defined in
      Synchronized.h.  I have not replaced these functions yet in this diff, but will
      do so in a follow-up diff.
      
      LockTraits has a few advantages over the existing methods:
      * It provides mechanisms for telling if a given mutex supports shared access
        and timed access.
      * The default LockTraits implementation automatically figures out the correct
        behavior for classes that define lock(), unlock(), methods.  It automatically
        detects sharing and timed support based on the presence of lock_shared() and
        try_lock_for() methods.
      
      LockTraits can be specialized for custom lock types that do not conform with
      the lock method names used by the C++ standard.  This does differ slightly from
      the argument dependent lookup mechanism used by the acquireRead() functions.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3504625
      
      fbshipit-source-id: 40320997e9ae2147baecd10b70e8dc06a35e49e1
      9276f2a5
  2. 05 Jul, 2016 3 commits
    • Andrii Grynenko's avatar
      Disable PthreadKeyUnregister on iOS and MSVC · 7235d201
      Andrii Grynenko authored
      Summary: ~PthreadKeyUnregister logic is not safe if we can't guarantee that it has the maximum pririty (i.e. is the last to be run on shutdown).
      
      Reviewed By: ericniebler
      
      Differential Revision: D3517589
      
      fbshipit-source-id: 3340e2e19cf52973ee677288bc4ac6105f3f2543
      7235d201
    • Adam Simpkins's avatar
      fix flaky ConnectTFOTimeout and ConnectTFOFallbackTimeout tests · a3bd593a
      Adam Simpkins authored
      Summary:
      In the ConnectTFOTimeout and ConnectTFOFallbackTimeout tests in
      AsyncSSLSocketTest.cpp, the client runs for 1ms before timing out and quitting.
      It may end up shutting down the server thread before the server has even
      received the TCP connect callback.  If this happened it would cause the test to
      fail, since the server code checked to make sure the callback was invoked.
      
      This diff creates a new ConnectTimeoutCallback server-side callback for these
      tests to use, which doesn't care if it gets told about a new connection or not.
      
      Reviewed By: siyengar
      
      Differential Revision: D3512809
      
      fbshipit-source-id: ce77fe944fb06a38a84c1458356f161cec7387b3
      a3bd593a
    • Subodh Iyengar's avatar
      Add sa_len for sockaddr conversions · dc939388
      Subodh Iyengar authored
      Summary:
      Some platforms like Apple add a additional
      field to sockaddr called sa_len.
      
      This is not normally required by POSIX, so
      all posix methods work correctly when a sockaddr
      is passed in without a sa_len set.
      
      However other functions which are not defined
      by posix such as connectx require this field to
      operate correctly.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3514266
      
      fbshipit-source-id: f8e2941f337222486c81c911dbd06a2ce35e4f00
      dc939388
  3. 02 Jul, 2016 8 commits
  4. 01 Jul, 2016 16 commits
    • Adam Simpkins's avatar
      fix the ThreadLocal test in open source builds · df7b6d2a
      Adam Simpkins authored
      Summary:
      The ThreadLocalTest has been broken in open source builds ever since D2678401,
      because Makefile.am was never updated to build the helper shared library needed
      by the test.
      
      This updates Makefile.am to build the shared library.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3511125
      
      fbshipit-source-id: 4684dbc32acf6ffbfc07079da91a1da480259502
      df7b6d2a
    • Aravind Anbudurai's avatar
      Make AutoTimer work with std::chrono::duration instead of seconds with type double · 0b14cc4f
      Aravind Anbudurai authored
      Summary:
      Currently, AutoTimer outputs duration as a double with seconds as units.
      This is limiting and I'm making it return std::chrono::duration. Users can specify the type with DurationType.
      
      This is needed for me because the library that I am going to use inside the callback I pass in using chrono::duration and it feels hacky to go from duration -> double -> duration.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506557
      
      fbshipit-source-id: 0a5e9e16181bfac3a10df6a253716c0499cff5df
      0b14cc4f
    • Christopher Dykes's avatar
      ConstantRNG should implement UniformRandomBitGenerator · ca33aa31
      Christopher Dykes authored
      Summary: As per http://en.cppreference.com/w/cpp/concept/UniformRandomBitGenerator it was almost there, except that `min()` and `max()` need to be static members.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507595
      
      fbshipit-source-id: 5e0b321c477e37ab8a3487ad643caa83cc6cfc9d
      ca33aa31
    • Aravind Anbudurai's avatar
      clang-format AutoTimer.h · 1c1a6b45
      Aravind Anbudurai authored
      Summary:
      Somehow the formatting is messed up and it was triggering my OCD.
      Sending a diff before I go crazy
      
      Depends on D3506557
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506618
      
      fbshipit-source-id: 218ce2100cc45c5017328e97344029061fe2eff5
      1c1a6b45
    • Christopher Dykes's avatar
      Don't use named variadic macro parameters · 1880e851
      Christopher Dykes authored
      Summary: MSVC doesn't support them, so use `__VA_ARGS__` instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507071
      
      fbshipit-source-id: 186834c87e74257c709fcbc08e3bda7b1b55d02b
      1880e851
    • Christopher Dykes's avatar
      Use asm_volatile_memory() for portable memory barriors in LifoSemTests · b9d8fba1
      Christopher Dykes authored
      Summary: The portability headers exist for a reason, so use them.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507031
      
      fbshipit-source-id: f88c8ed37e648d38231c1d923c1d69d551beabff
      b9d8fba1
    • Christopher Dykes's avatar
      Use UTF-8 strings for strings with multi-byte Unicode code points in them · 309ac912
      Christopher Dykes authored
      Summary: Because MSVC doesn't support strings with multi-byte Unicode code points in them unless it's in a UTF-8 string.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507197
      
      fbshipit-source-id: 27bff1efee03180716418fbfa9ef98f9c04929d9
      309ac912
    • Christopher Dykes's avatar
      Use decltype rather than typeof · 5f78f71a
      Christopher Dykes authored
      Summary: Because `typeof` is a GCC specific extension whose standardized version is called `decltype`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506960
      
      fbshipit-source-id: 0e7495028632b23f149bf8d0163d2000ebec2fcc
      5f78f71a
    • Christopher Dykes's avatar
      Rename SIZE to kSize · ef12daa2
      Christopher Dykes authored
      Summary: Because `SIZE` is a defined type on Windows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507144
      
      fbshipit-source-id: ee9fd9bb7c35055ca69719717aa10d8e9c8701c2
      ef12daa2
    • Christopher Dykes's avatar
      Use uint32_t rather than uint · 7a0de7ae
      Christopher Dykes authored
      Summary: Because `uint32_t` is standardized, and MSVC doesn't have `uint`.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3507011
      
      fbshipit-source-id: ac0abb4ad1b2dbaa890554589817ce75abdd987e
      7a0de7ae
    • Christopher Dykes's avatar
      Use std::vector in the CacheLocalityBenchmark rather than a VLA · 61a96501
      Christopher Dykes authored
      Summary: Because MSVC doesn't support VLAs.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506835
      
      fbshipit-source-id: 8683b5c513ed25e7f47642c8493f8b10da9906be
      61a96501
    • Christopher Dykes's avatar
      Use float literals when initializing float values · 48832457
      Christopher Dykes authored
      Summary: MSVC was correctly warning that we were initializing `float` variables with `double` literals. This just adds the explicit suffix so they are `float` literals instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506797
      
      fbshipit-source-id: 7eb4588958eddb984ba830e2599ac505d495783e
      48832457
    • Christopher Dykes's avatar
      Long is not long enough for a long long · 389ce43b
      Christopher Dykes authored
      Summary: Thus `1UL << 63 == 0` which is not the intended behavior.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3478480
      
      fbshipit-source-id: a31dba7f5a503be2b34a4cb66bc7039076f158a0
      389ce43b
    • Christopher Dykes's avatar
      Don't try and instantiate an invalid function in DiscriminatedPtrDetail · 788ab800
      Christopher Dykes authored
      Summary:
      THe issue is quite simple: Regardless of the control flow, the previous implementation of this was instantiating `ApplyVisitor1<V,R>` which declares a return type, but never returns.
      This refactors `ApplyVisitor1` and `ApplyConstVisitor1` so that the part of the control flow that was previously never reached simply doesn't exist anymore.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3479584
      
      fbshipit-source-id: 605a48e39bba6dc14df1af1e76b55ea60f3e69d5
      788ab800
    • Christopher Dykes's avatar
      Don't use stderr as an identifier name · b0883076
      Christopher Dykes authored
      Summary: Because it is defined as a macro that calls a function to get the error stream. It is also defined as a macro in musl libc.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3506283
      
      fbshipit-source-id: 0652288adfe64010798017e46d962fdc18d2ff56
      b0883076
    • Misha Shneerson's avatar
      stop_watch is moved to folly · 8382636d
      Misha Shneerson authored
      Summary:
      moved stop_watch to folly
      defined aliases for backward compact. These alias will be removed in next diff.
      
      Reviewed By: juchem
      
      Differential Revision: D3474035
      
      fbshipit-source-id: 74ee8bb7f2db46434c937eecf121d1cba473178a
      8382636d
  5. 30 Jun, 2016 3 commits
    • Tianjiao Yin's avatar
      suppress unused variable warnings · ee542790
      Tianjiao Yin authored
      Reviewed By: yfeldblum
      
      Differential Revision: D3501266
      
      fbshipit-source-id: 2ac3b6e2785792ccc45f4568ceff7fd05f0262f3
      ee542790
    • Aravind Anbudurai's avatar
      Make AutoTimer usable with Closures · 3f09eed1
      Aravind Anbudurai authored
      Summary:
      Currently, AutoTimer works only with FunctionObjects that are default constructible because it constructs Logger each time it needs to log. This diff makes AutoTimer work with closures too. This will help in making AutoTimer more flexible because the user can capture necessary dependencies in the lambda.
      
      This diff also cleans up the constructors on AutoTimer by making it take an
      std::string&& instead of Args... that is passed into folly::to<..>. Although
      this makes the instantiation a bit harder, the simplicity of constructor seems
      worth it.
      
      This also refactors the callsites of setMinLogTime to directly pass the
      value into the ctor and changes callsites on fbcode
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3487868
      
      fbshipit-source-id: 52fa1099a5e39b791972cc0d3f678d44ea4ba288
      3f09eed1
    • Scott Michelson's avatar
      Give each eventbase a wheeltimer · 75e5507c
      Scott Michelson authored
      Summary:
      This gives each eventbase a wheeltimer. Construction is on demand, so there's no penalty if it isn't used. Why do this? 3 immediate reasons:
      
      1) some clients already do this outside of the interface: diffusion/FBS/browse/master/fbcode/servicerouter/client/common/ThriftDispatcher.h$302,607?view=highlighted
      2) inefficient timers can be easily avoided: diffusion/FBS/browse/master/fbcode/thrift/lib/cpp2/async/HeaderClientChannel.h;64fb260ea4bd235ba79414a78002fd68cf0453a8$319
      3) D2379210 indicates we can do a better job with this than cob timeout
      
      Reviewed By: andriigrynenko, djwatson
      
      Differential Revision: D3460792
      
      fbshipit-source-id: a7bb6fdd90ca95b6aef8af952d7a66dd0dc260c1
      75e5507c
  6. 29 Jun, 2016 4 commits
    • Eric Niebler's avatar
      gcc-4.8 is not decaying types correctly in lambda init captures. Help it out.... · e6aa2684
      Eric Niebler authored
      gcc-4.8 is not decaying types correctly in lambda init captures. Help it out. Fixes open source build.
      
      Summary: Trivial change gets folly::ThreadLocal building again with gcc-4.8, needed by the Open Source build.
      
      Reviewed By: chadparry, yfeldblum
      
      Differential Revision: D3498657
      
      fbshipit-source-id: cf36f2bef7f1d03d133d16bfd063f7a2ce681822
      e6aa2684
    • Mirek Klimos's avatar
      Fix FiberManager.RequestContext unit test · 235fb4c0
      Mirek Klimos authored
      Summary: with the added blocks, pointer to RequestContext needs to be captured by value, not reference
      
      Differential Revision: D3499921
      
      fbshipit-source-id: 76ff22869228fbdd7ef1651cd2814550f6abc301
      235fb4c0
    • Eric Niebler's avatar
      fix the open source ssl_test target · f285646c
      Eric Niebler authored
      Summary: 'make check' is failing since the path to OpenSSLHashTest.cpp is wrong and because ssl_test is not linked to libcrypto.
      
      Reviewed By: mhx
      
      Differential Revision: D3498207
      
      fbshipit-source-id: 0f443d1f1b76c537d211dc148df0cd3fdfb8eead
      f285646c
    • Mirek Klimos's avatar
      Replace RequestContext::create with RequestContextScopeGuard in tests · a18f2c01
      Mirek Klimos authored
      Summary: RequestContextScopeGuard should be preferred to RequestContext::create because it makes sure that RequestContext is cleared afterwards - need to create more examples of this in the codebase, migrating unit tests should be safe
      
      Reviewed By: interwq
      
      Differential Revision: D3489969
      
      fbshipit-source-id: 202fec93116db3d435c108fafecad26a4ed9b603
      a18f2c01
  7. 27 Jun, 2016 2 commits
    • Marcus Holland-Moritz's avatar
      Allow unchecked conversion from floating point to bool · 12c01784
      Marcus Holland-Moritz authored
      Summary:
      In order to be consistent with integral-to-bool conversion, this
      change allows conversion from floating point values to bool following
      the same rule that is to be consistent with C(++) conventions. Also,
      any arithmetic value can be converted to bool without potential for
      undefined behaviour, so no extra checks are required.
      
      Differential Revision: D3483760
      
      fbshipit-source-id: 024b58d348ef679079aba4d9d5277acb46aba2a1
      12c01784
    • Bo You's avatar
      Folly parseJson doesn't handle minInt properly · 6dbd5d06
      Bo You authored
      Summary:
      Right now in ##parseNumber## in ##folly/json.cpp##, when a negative number is provided, both the minus sign and the digits are stored in the variable ##integral##: https://fburl.com/362938516.
      
      This causes problem when the exact min int is provided (-9223372036854775808). Because now ##integral.size()## equals 20 (including the minus sign), which is greater than ##maxIntLen## (which is 19). We need to handle negatives separately to get the correct result.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3479054
      
      fbshipit-source-id: 15c782962a5f5ee845a2a18f2145c7695ec2d546
      6dbd5d06
  8. 26 Jun, 2016 1 commit
    • David Lam's avatar
      fix typo in dynamic.md documentation · 1ce31b9a
      David Lam authored
      Summary: #accept2ship
      
      Reviewed By: Orvid
      
      Differential Revision: D3486732
      
      fbshipit-source-id: 45bfe1daa1dbd1e427fcd18e71e6b9eeb6d6b2b7
      1ce31b9a
  9. 25 Jun, 2016 1 commit
    • Eric Niebler's avatar
      folly: fix clang's -Wundefined-var-template · 6c76acfc
      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: D3447679
      
      fbshipit-source-id: 22c90c19e2c7a9b6d772058f2c7e350b890b6c0a
      6c76acfc