1. 04 Aug, 2016 3 commits
    • Nick Terrell's avatar
      Fix Enumerate C++17 Support · 5f92025e
      Nick Terrell authored
      Summary: `RangeEnumerator`s `begin()` and `end()` could return different values, but `Enumerator`s `operator ==` didn't support comparision with different types.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3662576
      
      fbshipit-source-id: cfd10fffd220c70191ce0ac2ed78edd35daf5538
      5f92025e
    • Christopher Dykes's avatar
      Don't use a macro for no reason · 381f8e28
      Christopher Dykes authored
      Summary: There is no reason at all for this to be a macro, so get rid of the macro.
      
      Reviewed By: igorsugak, yfeldblum
      
      Differential Revision: D3666339
      
      fbshipit-source-id: cf131fd4182fe89c5ce0c981edf9bd7fb46158a9
      381f8e28
    • Christopher Dykes's avatar
      Don't name a member small · cf1c637d
      Christopher Dykes authored
      Summary:
      Because, if you aren't compiling with `WIN32_LEAN_AND_MEAN`, including `WinSock2.h` will result in `small` being `#define`'d as `char`. The best way to work around the issue is to simply change the name of the member to something else.
      It would also have been possible to solve the problem by adding a section to `folly/portability/Windows.h`, but that would have required including that header in `folly/Function.h`, which there really is no reason to do.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3666417
      
      fbshipit-source-id: 21c0363a4b77bb01e4ec20b2fc625c40729879c3
      cf1c637d
  2. 03 Aug, 2016 9 commits
    • Christopher Dykes's avatar
      Fix the mode being used in the implementation of open in the Fcntl portability header · a0f8eed7
      Christopher Dykes authored
      Summary: The mode parameter to `open` under MSVC is not the same as the mode parameter everywhere else, so we need to do a bit of translation.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3651218
      
      fbshipit-source-id: 80df1e15f34b8d66533256107d8c9218f757fde2
      a0f8eed7
    • Christopher Dykes's avatar
      Force the overflow in BitVectorCoding::skipTo to be 64-bit · abb963a0
      Christopher Dykes authored
      Summary: This code was relying on the `- 1` overflowing as a 64-bit value, but MSVC (correctly in my opinion) was overflowing this as a 32-bit value, resulting in a segfault when trying to run the bitvector and eliasfano tests on MSVC.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3652343
      
      fbshipit-source-id: 38a22abfc0d05ab2f070c450eebfa69af07d26af
      abb963a0
    • Mirek Klimos's avatar
      Unset RequestContext properly in EventBase::runLoopCallbacks · 6e8fcd16
      Mirek Klimos authored
      Summary: We need to make sure RequestContext is unset properly for correct attribution of events to requests in BPF. djwatson, is there a reason not to set RequestContext when running runLoopCallbacks() from EventBase destructor?
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3640289
      
      fbshipit-source-id: bc48e936618adb1a1619de004b8479f58d3b683d
      6e8fcd16
    • lpathy's avatar
      Added DiscriminatedPtr support to arm64 · 0376a848
      lpathy authored
      Summary: Closes https://github.com/facebook/folly/pull/429
      
      Reviewed By: mzlee
      
      Differential Revision: D3649806
      
      Pulled By: Orvid
      
      fbshipit-source-id: 77288e0a1aedf15a18f558e18fbc1dc3a56e5fd6
      0376a848
    • Christopher Dykes's avatar
      Fix a typo in PicoSpinLock · 0ce4e4c6
      Christopher Dykes authored
      Summary:
      Because I fail at typing underscores apparently.
      This also switches the shifts over to using `kLockBitMask_` instead, which was already defined for us.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3652483
      
      fbshipit-source-id: 6bd527beeb90bea8ee7632c0a3bfbbb9e0a7e2e7
      0ce4e4c6
    • Alexander Stocko's avatar
      Add libfollytestmain.la to mallctl's LDADD · a1e9df40
      Alexander Stocko authored
      Summary:
      Fixes make check problem for MallctlHelperTest.
      
      Previous make check output:
      
      MallctlHelperTest.o: In function `MallctlHelperTest_valid_read_Test::TestBody()':
      MallctlHelperTest.cpp:(.text+0x25): undefined reference to `testing::internal::AlwaysTrue()'
      MallctlHelperTest.cpp:(.text+0x2e): undefined reference to `testing::internal::AlwaysTrue()'
      MallctlHelperTest.cpp:(.text+0x51): undefined reference to `testing::Message::Message()'
      MallctlHelperTest.cpp:(.text+0x72): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
      MallctlHelperTest.cpp:(.text+0x85): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
      MallctlHelperTest.cpp:(.text+0x91): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
      MallctlHelperTest.cpp:(.text+0xe4): undefined reference to `testing::Message::Message()'
      MallctlHelperTest.cpp:(.text+0x111): undefined reference to `testing::inte
      Closes https://github.com/facebook/folly/pull/448
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3659427
      
      Pulled By: Orvid
      
      fbshipit-source-id: c1445b881bbebdace4defc02024a5184fd821ed6
      a1e9df40
    • Yuri Putivsky's avatar
      folly AsyncPipeReader supports IOBuf · 2bee060d
      Yuri Putivsky authored
      Summary: folly AsyncPipeReader takes a callback of type AsyncReader::ReadCallback. Now AsyncReader::ReadCallback class supports IOBuf as a buffer for transfer read bytes. Need to extend AsyncPipeReader class to support IOBuf as well
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3650893
      
      fbshipit-source-id: e2142341c8b8b0b2ef248c1f13a8caba9d50ba67
      2bee060d
    • Maged Michael's avatar
      Test of DeterministicSchedule support for global invariants and auxiliary vari · 832479bd
      Maged Michael authored
      Summary:
      Depends on D3648146
      
      Atomic counter test with:
      - Buggy path triggered by an env var
      - Auxiliary data
      - A global invariant
      - A function to be called with shared accesses to update auxiliary data and check the global invariant.
      
      Reviewed By: djwatson
      
      Differential Revision: D3648195
      
      fbshipit-source-id: 18620a887f114abf31ba1261c38287139a1591a7
      832479bd
    • Gustavo Serra Scalet's avatar
      Fix compiler warnings · 40857a36
      Gustavo Serra Scalet authored
      Summary:
      - unused variables
      - suppressing "warning: variable length array ‘vec’ is used [-Wvla]"
      Closes https://github.com/facebook/folly/pull/443
      
      Reviewed By: djwatson
      
      Differential Revision: D3641928
      
      Pulled By: Orvid
      
      fbshipit-source-id: 0bd58a75f8948f28cc2d232c03bd443734d9657d
      40857a36
  3. 02 Aug, 2016 5 commits
    • Maged Michael's avatar
      DeterministicSchedule support for global invariants and auxiliary variables · 61d53283
      Maged Michael authored
      Summary:
      Support for user-defined auxiliary variables and global invariants.
      - Add two fields to DSched:
        -- tls_aux: static FOLLY_TLS std::function<void(uint64_t, bool)>*. User-defined auxiliary function with parameters: count of synchronization steps, and boolean indicator of the success of the current step.
        -- step_: uint64_t. Count of shared accesses that correspond to user synchronization steps (atomic accesses for now).
      - Add two static functions to DSched:
        -- void setAux(std::function<void(uint64_t, bool)>*).
        -- void callAux(bool success). Calls the aux function with the step count and the bool success argument.
      - Add a version of afterSharedAccess(bool) that takes a bool success parameter and calls callAux(success). This version is used in every atomic operation of DeterministicAtomic.
      - Add direct load interface to  DeterministicAtomic for use by auxiliary functions.
      
      Note: This the base of a stacked diff with:
      - Test the new capabilities in DeterministicScheduleTest.h
      Next steps:
      - Use the new capabilities to test dynamic MPMCQueue
      Other possible additions:
      - Change the implementation of DeterministicMutex to allow inspecting its internal state.
      - Test the new capabilities for mutexes and semaphores in DeterministicScheduleTest.h
      - Performance optimization: e.g., user-space context switching, using regular variables to implements atomics.
      
      Reviewed By: djwatson
      
      Differential Revision: D3648146
      
      fbshipit-source-id: 4f838ff7cfd41ab71cfdf22bb67def3221948311
      61d53283
    • Sahil Jain's avatar
      Update folly/futures README · 1ddb975d
      Sahil Jain authored
      Summary: Regenerate README after updating dex_export.php
      
      Reviewed By: fugalh
      
      Differential Revision: D3654216
      
      fbshipit-source-id: aaae04803c480e2ecaf9b3cb8794c8d8f7df560b
      1ddb975d
    • Dave Watson's avatar
      Ensure getVia(eventbase) does not busy wait · 62cc0672
      Dave Watson authored
      Summary:
      Currently, getVia(eventbase) will busy wait if no work is scheduled on the event base.
      
      Tweak the DrivableExecutor API a bit to support sleeping/wakeups.
      There was already a similar fix for the only other existing DrivableExecutor, the ManualExecutor, in
      D2906858.
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3613954
      
      fbshipit-source-id: 9ff9f2e010040d9886fdf51a665e3afabbff57c0
      62cc0672
    • Aravind Anbudurai's avatar
      readFile to take in fd · 4bd3e568
      Aravind Anbudurai authored
      Summary:
      I want to be able to read from an fd into an std::string and this diffs helps
      with that.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3654709
      
      fbshipit-source-id: d48e8001a50f90c66cbe5b4a3b536c7b0074c39d
      4bd3e568
    • Igor Sugak's avatar
      folly: remove template argument to std::abs to fix build with libc++ · 42cd3696
      Igor Sugak authored
      Summary:
      libc++ doesn't implement `std::abs` as template.
      
      ```lang=bash
      ./../folly/fibers/Fiber.h:68:34: error: unexpected type name 'intptr_t': expected
            expression
          const size_t size = std::abs<intptr_t>(
                                       ^
      ```
      
      Reviewed By: markisaa
      
      Differential Revision: D3645584
      
      fbshipit-source-id: a2d672137f110b975412a94ae4c6d00da0bd0d43
      42cd3696
  4. 01 Aug, 2016 6 commits
    • Yedidya Feldblum's avatar
      Remove the glog header include from Assume.h · a251c84f
      Yedidya Feldblum authored
      Summary:
      [Folly] Remove the glog header include from `Assume.h`.
      
      Better to avoid unnecessary includes.
      
      Reviewed By: Orvid
      
      Differential Revision: D3652651
      
      fbshipit-source-id: 3fa6256e9571539c692b9c50c1c215b31eef394a
      a251c84f
    • Christopher Dykes's avatar
      Fix the ffs builtins under MSVC · fcd39524
      Christopher Dykes authored
      Summary: I was off by one in my implementation.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3651183
      
      fbshipit-source-id: 4d6a6d08c06bce332a00088920bf604a10c942e7
      fcd39524
    • Christopher Dykes's avatar
      Don't disable the shadowing warning just for a parameter name · 0b400104
      Christopher Dykes authored
      Summary: Just rename the parameter instead, it's not worth it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3651065
      
      fbshipit-source-id: ce11c35a7923ab7e10868cedb49c47c0b427fd0c
      0b400104
    • Christopher Dykes's avatar
      Fix nextPowTwo for 64-bit values under MSVC · 8fdd5f1b
      Christopher Dykes authored
      Summary: A `long` is only 32-bits on MSVC, so this is simply wrong. Shift a `T` left instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3651139
      
      fbshipit-source-id: 3bbfd18ed0c372287c4ec6cbcc543f6f1fcc4139
      8fdd5f1b
    • Christopher Dykes's avatar
      Switch some assertions to std::thread rather than pthread · 800802c8
      Christopher Dykes authored
      Summary: Because the check macros attempt to pipe the values to the error stream, but we can't do that with the Windows implementation. Switch to `std::this_thread::get_id()` instead because it's standard and can be piped.
      
      Reviewed By: djwatson
      
      Differential Revision: D3650362
      
      fbshipit-source-id: 8af65448a33949f310abc818d95bac843214b685
      800802c8
    • David Wilemski's avatar
      fix HHWheelTimer comment typo · 27945a69
      David Wilemski authored
      Summary: Noticed this while reading the code.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3648565
      
      fbshipit-source-id: c00940e5ce91fbc7e5cc6c42e35c5deee3e0bf65
      27945a69
  5. 30 Jul, 2016 1 commit
    • Aaryaman Sagar's avatar
      Added initlist_construct_t tag for explicit initializer list · 912d191d
      Aaryaman Sagar authored
      Summary:
      Initializer list construction can often have conflictingly similar
      syntax as uniform initialization.  As a result APIs and classes often either
      avoid using `std::initializer_list`s or deprecate construction with
      `std::initializer_list`s.  This change provides a tag similar to
      `std::piecewise_construct_t` to help out.
      
      Reviewed By: simpkins
      
      Differential Revision: D3617276
      
      fbshipit-source-id: 3c74802f946a22e1a4ee52eca0f89df4a028eb22
      912d191d
  6. 29 Jul, 2016 7 commits
    • Dave Watson's avatar
      More tests · 24e91815
      Dave Watson authored
      Summary:
      Test timers where we need to reschedule the wheel timer next tick.
      
      This wasn't tested before, since we were always ticking, and never needed to reschedule.
      
      Differential Revision: D3637103
      
      fbshipit-source-id: cb80e7b790bb6aac68bdb5f60f8aa00caa2e5b69
      24e91815
    • Giuseppe Ottaviano's avatar
      Limit symbol length in demangle() · acd8ed50
      Giuseppe Ottaviano authored
      Summary:
      GCC's `__cxa_demangle()` uses on-stack data structures for the parser
      state which are linear in the number of components of the symbol. For
      extremely long symbols, this can cause a stack overflow.
      
      This diff introduces an arbitrary symbol length limit above which we
      just return the mangled name.
      
      Reviewed By: philippv
      
      Differential Revision: D3641115
      
      fbshipit-source-id: ec360bb20ca499fd0eaf3a06c5bbcbd1e936d845
      acd8ed50
    • Anirudh Ramachandran's avatar
      Add a const getter for X509 used in handshake (server-side) · 342ce9ee
      Anirudh Ramachandran authored
      Summary:
      Similar to other getters such as getSSLCertSize, but returns a const X509*.
      This may be useful to get cert parameters after handshake is complete
      (or in error).
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3636598
      
      fbshipit-source-id: 98f0e2987de53d6343541ef0ed588f9ad18390cd
      342ce9ee
    • Dave Watson's avatar
      fix hhwheeltimertest · dd6e6b68
      Dave Watson authored
      Summary:
      Test doesn't match comments.  Remove extranous commented code.
      
      I think there was actually a subtle bug in the test: since 25 doesn't evenly divide in to 6, we could end up farther away than we were expecting.  The same is true of 10/3, but it remains within the threshold.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3637078
      
      fbshipit-source-id: d9881143c33c9b4f203f839e2e5106183301b530
      dd6e6b68
    • Sven Over's avatar
      futures: fix behaviour when executors don't exec callback · 9095cd53
      Sven Over authored
      Summary:
      When future callbacks are to be executed by an executor (via `via`)
      and the executor does not actually execute the callback function
      (for whatever reason), then waiting for the final future (the one
      returned by `via`) block forever. In case the callback function
      that got passed to the executor gets destroyed without being executed,
      the future should be set to a folly::BrokenPromise exception instead
      of remaining unset forever.
      
      This diff modifies the reference counting in folly::detail::Core
      to make sure the reference held by the callback function is
      properly removed not only after the callback gets executed, but
      also when the callback is destroyed without having been executed.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3455931
      
      fbshipit-source-id: debb6f3563384a658d1e0149a4aadbbcb268938c
      9095cd53
    • Jim Meyering's avatar
      folly/experimental/test/FutureDAGTest.cpp: fix ASAN-detected heap use-after-free · 0cc6ea39
      Jim Meyering authored
      Summary: Building/testing with ASAN would elicit a heap use-after-free.
      
      Differential Revision: D3639117
      
      fbshipit-source-id: 30b5fa7d3fe1d804c4fba5bada8197a3a05a8333
      0cc6ea39
    • Yuri Putivsky's avatar
      takeOwnershipOfPipes method releases memory · ff76c329
      Yuri Putivsky authored
      Summary: takeOwnershipOfPipes should left zero heap memory allocated in folly:Subprocess class instance.
      
      Reviewed By: snarkmaster
      
      Differential Revision: D3638503
      
      fbshipit-source-id: aac7b10bd7399c44868f32c01164f4123892598f
      ff76c329
  7. 27 Jul, 2016 3 commits
    • Adam Simpkins's avatar
      add an unlock() method to Synchronized<T>::LockedPtr · 38237272
      Adam Simpkins authored
      Summary:
      Add an unlock() method to Synchronized LockedPtr objects.  This will make it
      easier to replace current users of the UNSYNCHRONIZED macro.
      
      Of the handful of places currently using UNSYNCHRONIZED, many of them want to
      simply release the lock before logging a message and returning.  However,
      UNSYNCHRONIZED is a poor choice for this, since it will re-acquire the lock on
      scope exit.  In these situations where the function returns from inside an
      UNSYNCHRONIZED block the code unnecessarily re-acquires the lock just to
      immediately release it.  The unlock() method will provide a cleaner mechanism
      for these call sites to simply drop the lock early before returning.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3547652
      
      fbshipit-source-id: 4d28fe9f3aad0d7348e918d1a3d6c705bfec242b
      38237272
    • Christopher Dykes's avatar
      Don't shift an int left while assigning it to a size_t · 5d90c138
      Christopher Dykes authored
      Summary:
      MSVC gives warnings if you shift a 32-bit value left but then assign it to a 64-bit variable. This just makes it a 64-bit shift instead.
      If we really wanted, this doesn't need to be a size_t to begin with, but it already is, so just leave it alone.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3622935
      
      fbshipit-source-id: 25931e6df644df8a2160aa80fd5de21cd9c06159
      5d90c138
    • Wez Furlong's avatar
      folly: fix AtomicUnorderedMap compilation on macOS · 84e863f6
      Wez Furlong authored
      Summary:
      MAP_POPULATE is not defined on this system.  Instead we will `madvise` the kernel
      that we will need it so that it will populate the mapping.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3584325
      
      fbshipit-source-id: ece52f3d55c475bcd41367f4e9744d6f41001cd5
      84e863f6
  8. 26 Jul, 2016 6 commits
    • Christopher Dykes's avatar
      Support PicoSpinLock on MSVC · 369761f0
      Christopher Dykes authored
      Summary:
      It was using inline assembly in order to get atomic single-bit operations, so add a variant for MSVC that uses intrinsics.
      MSVC is also weird in-that it doesn't have a 16-bit variant of these, so use an atomic OR and AND to achieve the required effect.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3623220
      
      fbshipit-source-id: b4ff985ef2ed7787115f4d20de6f244123410dc8
      369761f0
    • Christopher Dykes's avatar
      Consistently reference an internal struct as a struct · d67d48ea
      Christopher Dykes authored
      Summary: That way the mismatch warning can stay as an error.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3613761
      
      fbshipit-source-id: 6e0ee42c658d95786f578f6500aba113c00d8f77
      d67d48ea
    • Christopher Dykes's avatar
      Fix the weak linking of JEMalloc under MSVC · cdcb98c4
      Christopher Dykes authored
      Summary: While the previous version did compile, it wouldn't actually work at link time.
      
      Reviewed By: meyering
      
      Differential Revision: D3614424
      
      fbshipit-source-id: 578677b65edca720330319594e1163d214e1400d
      cdcb98c4
    • Christopher Dykes's avatar
      Don't run the thread local tests requiring dlopen on Windows · 76551ae8
      Christopher Dykes authored
      Summary: When I initially added the surrounding `#ifdef` I failed at where I put my `#endif`, as I left the shared library test enabled. This disables it for Windows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3622769
      
      fbshipit-source-id: f263201239095bbef076300d5f40649ebee1173c
      76551ae8
    • Christopher Dykes's avatar
      Get MSVC able to construct an Indestructible · a955532d
      Christopher Dykes authored
      Summary: It didn't like using `decltype(args)`, which wasn't really necessary as we already have it's type.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3623424
      
      fbshipit-source-id: 994c23cbf486d427c6dd0fe4c6f768e51ea15ad1
      a955532d
    • Christopher Dykes's avatar
      Only try to use the membarrier on Linux · c6476cb3
      Christopher Dykes authored
      Summary: It doesn't exist anywhere else, and `syscall` isn't even defined on Windows, so this completely failed to compile before.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3623382
      
      fbshipit-source-id: 302093ddc96d6465e0dcc1883747229a7fb25a84
      c6476cb3