Christopher Dykes [Thu, 4 Aug 2016 22:40:16 +0000 (15:40 -0700)]
Fix a pair of non-ascii quotes that made their way into AsyncSocket
Summary: Because the lint error was annoying me.
Reviewed By: yfeldblum
Differential Revision:
D3671252
fbshipit-source-id:
2962db7616077f531e64c6f2b26ad708c7adf6ed
Christopher Dykes [Thu, 4 Aug 2016 22:38:29 +0000 (15:38 -0700)]
Eliminate the atomic porability header's dependence on Windows.h
Summary:
This is done by using the intrinsic directly instead.
This also marks the input parameter as `volatile`, to make it more clear that that's how it is handled by `_InterlockedExchangeAdd64`.
Reviewed By: yfeldblum
Differential Revision:
D3671320
fbshipit-source-id:
6010085ec3b6952a3eb1e952965ec6ad87566db2
Christopher Dykes [Thu, 4 Aug 2016 22:38:00 +0000 (15:38 -0700)]
Don't assume boost::path contains narrow characters
Summary: Because it contains `wchar_t`'s on Windows.
Reviewed By: yfeldblum
Differential Revision:
D3672098
fbshipit-source-id:
b49db642dedf48bf7379cf339130c93f52a22f9a
Christopher Dykes [Thu, 4 Aug 2016 22:37:49 +0000 (15:37 -0700)]
Don't try to ignore the SIGPIPE signal if it isn't defined
Summary: Which is the case when compiling under MSVC.
Reviewed By: pixelb
Differential Revision:
D3671357
fbshipit-source-id:
b7e51479cae44933c3f1caa21d45775a32f294a3
Christopher Dykes [Thu, 4 Aug 2016 22:05:50 +0000 (15:05 -0700)]
Assume p is not nullptr in storeUnaligned
Summary:
Because we're constructing the value with a placement new, which has some of C++'s most unhelpful behavior ever put into the spec: If `p` is `nullptr` and we are not compiling in C++14 mode, where the restriction was changed, then the placement new will do absolutely nothing at all. By adding the assumption that `p` is not `nullptr`, we'll trip a segfault in release mode rather than failing silently.
Note that MSVC would generate the nullptr check regardless of which mode it's in, so this assume forces the removal of the check.
Reviewed By: yfeldblum
Differential Revision:
D3651116
fbshipit-source-id:
ee15a38f85ce4e3cb3186fda0b7bcca39acda27a
Mirek Klimos [Thu, 4 Aug 2016 19:09:50 +0000 (12:09 -0700)]
RequestContext::create should call onUnset callback
Summary: melaniesubbiah introduced onSet / onUnset callbacks on RequestData in
D3604948; we need unset() to be called when an RC is overriden with RequestContext::create() so that things work as expected. Also, change the order of calling onSet / onUnset - from RequestData perspective, it shouldn't look like there are two contexts set at the same time
Reviewed By: palmtenor
Differential Revision:
D3667017
fbshipit-source-id:
b9bfb858fe65ffb11de8e6d6f13b8f4cf6266bc9
Christopher Dykes [Thu, 4 Aug 2016 17:50:19 +0000 (10:50 -0700)]
Include the fcntl.h portability header where it's needed
Summary: There are a few places that need this, so make it so.
Reviewed By: yfeldblum
Differential Revision:
D3667234
fbshipit-source-id:
84c16e1b036d9c2afddf03aa84c43210c5672f0a
Christopher Dykes [Thu, 4 Aug 2016 17:49:23 +0000 (10:49 -0700)]
Support TimeUtil under MSVC
Summary: Well, make it compile anyways. There's no simple equivelant for Windows, so just return 0 instead.
Reviewed By: yfeldblum
Differential Revision:
D3667474
fbshipit-source-id:
02224c6666dfcfdec237bfbbd4714170407a952a
Christopher Dykes [Thu, 4 Aug 2016 17:48:08 +0000 (10:48 -0700)]
Fix the Windows portability implementations of mmap and munmap
Summary: Because they simply didn't work before.
Reviewed By: yfeldblum
Differential Revision:
D3666894
fbshipit-source-id:
7a34073b2bbc43c489ad963c28fac24dcbb187f2
Nick Terrell [Thu, 4 Aug 2016 00:53:52 +0000 (17:53 -0700)]
Fix Enumerate C++17 Support
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
Christopher Dykes [Thu, 4 Aug 2016 00:45:28 +0000 (17:45 -0700)]
Don't use a macro for no reason
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
Christopher Dykes [Thu, 4 Aug 2016 00:22:57 +0000 (17:22 -0700)]
Don't name a member small
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
Christopher Dykes [Wed, 3 Aug 2016 22:09:29 +0000 (15:09 -0700)]
Fix the mode being used in the implementation of open in the Fcntl portability header
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
Christopher Dykes [Wed, 3 Aug 2016 22:09:04 +0000 (15:09 -0700)]
Force the overflow in BitVectorCoding::skipTo to be 64-bit
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
Mirek Klimos [Wed, 3 Aug 2016 21:40:28 +0000 (14:40 -0700)]
Unset RequestContext properly in EventBase::runLoopCallbacks
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
lpathy [Wed, 3 Aug 2016 21:13:44 +0000 (14:13 -0700)]
Added DiscriminatedPtr support to arm64
Summary: Closes https://github.com/facebook/folly/pull/429
Reviewed By: mzlee
Differential Revision:
D3649806
Pulled By: Orvid
fbshipit-source-id:
77288e0a1aedf15a18f558e18fbc1dc3a56e5fd6
Christopher Dykes [Wed, 3 Aug 2016 21:04:35 +0000 (14:04 -0700)]
Fix a typo in PicoSpinLock
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
Alexander Stocko [Wed, 3 Aug 2016 20:16:12 +0000 (13:16 -0700)]
Add libfollytestmain.la to mallctl's LDADD
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
Yuri Putivsky [Wed, 3 Aug 2016 19:02:26 +0000 (12:02 -0700)]
folly AsyncPipeReader supports IOBuf
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
Maged Michael [Wed, 3 Aug 2016 00:23:18 +0000 (17:23 -0700)]
Test of DeterministicSchedule support for global invariants and auxiliary vari
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
Gustavo Serra Scalet [Wed, 3 Aug 2016 00:04:52 +0000 (17:04 -0700)]
Fix compiler warnings
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
Maged Michael [Tue, 2 Aug 2016 23:29:54 +0000 (16:29 -0700)]
DeterministicSchedule support for global invariants and auxiliary variables
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
Sahil Jain [Tue, 2 Aug 2016 21:55:16 +0000 (14:55 -0700)]
Update folly/futures README
Summary: Regenerate README after updating dex_export.php
Reviewed By: fugalh
Differential Revision:
D3654216
fbshipit-source-id:
aaae04803c480e2ecaf9b3cb8794c8d8f7df560b
Dave Watson [Tue, 2 Aug 2016 21:05:35 +0000 (14:05 -0700)]
Ensure getVia(eventbase) does not busy wait
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
Aravind Anbudurai [Tue, 2 Aug 2016 16:55:15 +0000 (09:55 -0700)]
readFile to take in fd
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
Igor Sugak [Tue, 2 Aug 2016 01:06:41 +0000 (18:06 -0700)]
folly: remove template argument to std::abs to fix build with libc++
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
Yedidya Feldblum [Mon, 1 Aug 2016 23:46:59 +0000 (16:46 -0700)]
Remove the glog header include from Assume.h
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
Christopher Dykes [Mon, 1 Aug 2016 22:26:51 +0000 (15:26 -0700)]
Fix the ffs builtins under MSVC
Summary: I was off by one in my implementation.
Reviewed By: yfeldblum
Differential Revision:
D3651183
fbshipit-source-id:
4d6a6d08c06bce332a00088920bf604a10c942e7
Christopher Dykes [Mon, 1 Aug 2016 22:13:39 +0000 (15:13 -0700)]
Don't disable the shadowing warning just for a parameter name
Summary: Just rename the parameter instead, it's not worth it.
Reviewed By: yfeldblum
Differential Revision:
D3651065
fbshipit-source-id:
ce11c35a7923ab7e10868cedb49c47c0b427fd0c
Christopher Dykes [Mon, 1 Aug 2016 22:09:57 +0000 (15:09 -0700)]
Fix nextPowTwo for 64-bit values under MSVC
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
Christopher Dykes [Mon, 1 Aug 2016 20:17:30 +0000 (13:17 -0700)]
Switch some assertions to std::thread rather than pthread
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
David Wilemski [Mon, 1 Aug 2016 15:47:36 +0000 (08:47 -0700)]
fix HHWheelTimer comment typo
Summary: Noticed this while reading the code.
Reviewed By: yfeldblum
Differential Revision:
D3648565
fbshipit-source-id:
c00940e5ce91fbc7e5cc6c42e35c5deee3e0bf65
Aaryaman Sagar [Sat, 30 Jul 2016 03:30:00 +0000 (20:30 -0700)]
Added initlist_construct_t tag for explicit initializer list
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
Dave Watson [Fri, 29 Jul 2016 21:28:53 +0000 (14:28 -0700)]
More tests
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
Giuseppe Ottaviano [Fri, 29 Jul 2016 21:24:41 +0000 (14:24 -0700)]
Limit symbol length in demangle()
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
Anirudh Ramachandran [Fri, 29 Jul 2016 19:20:33 +0000 (12:20 -0700)]
Add a const getter for X509 used in handshake (server-side)
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
Dave Watson [Fri, 29 Jul 2016 18:28:50 +0000 (11:28 -0700)]
fix hhwheeltimertest
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
Sven Over [Fri, 29 Jul 2016 11:45:35 +0000 (04:45 -0700)]
futures: fix behaviour when executors don't exec callback
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
Jim Meyering [Fri, 29 Jul 2016 03:01:21 +0000 (20:01 -0700)]
folly/experimental/test/FutureDAGTest.cpp: fix ASAN-detected heap use-after-free
Summary: Building/testing with ASAN would elicit a heap use-after-free.
Differential Revision:
D3639117
fbshipit-source-id:
30b5fa7d3fe1d804c4fba5bada8197a3a05a8333
Yuri Putivsky [Fri, 29 Jul 2016 02:19:25 +0000 (19:19 -0700)]
takeOwnershipOfPipes method releases memory
Summary: takeOwnershipOfPipes should left zero heap memory allocated in folly:Subprocess class instance.
Reviewed By: snarkmaster
Differential Revision:
D3638503
fbshipit-source-id:
aac7b10bd7399c44868f32c01164f4123892598f
Adam Simpkins [Wed, 27 Jul 2016 19:32:20 +0000 (12:32 -0700)]
add an unlock() method to Synchronized<T>::LockedPtr
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
Christopher Dykes [Wed, 27 Jul 2016 19:21:19 +0000 (12:21 -0700)]
Don't shift an int left while assigning it to a size_t
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
Wez Furlong [Wed, 27 Jul 2016 04:07:55 +0000 (21:07 -0700)]
folly: fix AtomicUnorderedMap compilation on macOS
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
Christopher Dykes [Tue, 26 Jul 2016 23:17:39 +0000 (16:17 -0700)]
Support PicoSpinLock on MSVC
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
Christopher Dykes [Tue, 26 Jul 2016 22:54:14 +0000 (15:54 -0700)]
Consistently reference an internal struct as a struct
Summary: That way the mismatch warning can stay as an error.
Reviewed By: yfeldblum
Differential Revision:
D3613761
fbshipit-source-id:
6e0ee42c658d95786f578f6500aba113c00d8f77
Christopher Dykes [Tue, 26 Jul 2016 22:53:34 +0000 (15:53 -0700)]
Fix the weak linking of JEMalloc under MSVC
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
Christopher Dykes [Tue, 26 Jul 2016 22:53:04 +0000 (15:53 -0700)]
Don't run the thread local tests requiring dlopen on Windows
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
Christopher Dykes [Tue, 26 Jul 2016 22:52:25 +0000 (15:52 -0700)]
Get MSVC able to construct an Indestructible
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
Christopher Dykes [Tue, 26 Jul 2016 22:52:13 +0000 (15:52 -0700)]
Only try to use the membarrier on Linux
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
Christopher Dykes [Tue, 26 Jul 2016 22:50:47 +0000 (15:50 -0700)]
Add folly::assume_unreachable
Summary: So that the `[[noreturn]]` attribute can be applied.
Reviewed By: yfeldblum
Differential Revision:
D3614122
fbshipit-source-id:
4b95cb553e85c85c277c00b8165671dcc75afac8
Christopher Dykes [Tue, 26 Jul 2016 22:48:54 +0000 (15:48 -0700)]
Make RangeEnumerator C++17 compliant (Generalizing the Range-Based For Loop)
Summary:
Specifically the loosening of the definition of a range where-by the end of an iterator may be represented by a different type than the beginning of the range.
Oh, and it also fixes compilation on MSVC, which didn't like the decltype being used to determine the iterator type.
Reviewed By: yfeldblum
Differential Revision:
D3613993
fbshipit-source-id:
2940a15d0f93c5b6310d0b1896f5d12ca9aec639
Michael Lee [Tue, 26 Jul 2016 22:43:00 +0000 (15:43 -0700)]
Add a dummy FlagSaver class.
Summary: Add a declaration to mock out FlagSaver on platforms that don't support gflags.
Reviewed By: ivmaykov, yfeldblum
Differential Revision:
D3620421
fbshipit-source-id:
c1047f34f384f34276b18f53e966a65cdd5c8075
Andrii Grynenko [Tue, 26 Jul 2016 21:45:42 +0000 (14:45 -0700)]
Support custom loop runner for EventBaseLoopController
Summary: This allows having some logic executed before and after FiberManager loop (e.g. grabbing a Python GIL).
Reviewed By: A5he
Differential Revision:
D3616752
fbshipit-source-id:
3be35d54ced458328816d583133457a44a863acd
Yang Chi [Tue, 26 Jul 2016 20:49:40 +0000 (13:49 -0700)]
A BufferCallback was created but never deleted in AsyncSocketTest2
Summary: This crashes unit test with asan, since we never deletes it.
Reviewed By: djwatson
Differential Revision:
D3622847
fbshipit-source-id:
f7ea7c4f464843353b24a59adefd5d66b95bc169
Yang Chi [Tue, 26 Jul 2016 20:45:01 +0000 (13:45 -0700)]
No need to go through the list when you just want the size
Summary: cb is an unused variable, and i got error in android. It seems like we don't need to go through the list to increase count.
Differential Revision:
D3622772
fbshipit-source-id:
fe1f81a1fcad5bacad052e14b7b0b370beb3f3e5
Christopher Dykes [Tue, 26 Jul 2016 15:37:22 +0000 (08:37 -0700)]
Handle MSVC's preprocessor oddities in the SharedMutex test
Summary: MSVC needs a bit more glue to expand the varargs.
Reviewed By: yfeldblum
Differential Revision:
D3614681
fbshipit-source-id:
901d8c5138b1d2d28434c51bdff31f6d21f26681
Christopher Dykes [Tue, 26 Jul 2016 15:36:28 +0000 (08:36 -0700)]
Include sys/types.h portability header in Enumerate
Summary: Because it's using `ssize_t`, which MSVC defines weirdly.
Reviewed By: yfeldblum
Differential Revision:
D3614050
fbshipit-source-id:
422621ea0dc92b374fa6dfc32a5391c1093d039e
Neel Goyal [Tue, 26 Jul 2016 15:09:18 +0000 (08:09 -0700)]
Refactor socket peeker
Summary:
Refactor the socket peeker into its
own class so that it can be used in
other places as well, for example
for peeking at plaintext traffic.
Reviewed By: knekritz
Differential Revision:
D3521899
fbshipit-source-id:
fcd5615dd5d7cd1ddece4c624efbdecfbbc88a09
Misha Shneerson [Tue, 26 Jul 2016 05:14:37 +0000 (22:14 -0700)]
Fix gcpu regression associated with 1ms tick in HHWheelTimer
Summary:
We should go back to 10ms granularity.
Because regressions -
https://www.facebook.com/groups/wfi/permalink/
1107102889338325/
Reviewed By: haijunz
Differential Revision:
D3616784
fbshipit-source-id:
dc1d7ff5195ae836df4a334a9ac5c41164c0627b
Giuseppe Ottaviano [Sun, 24 Jul 2016 18:48:49 +0000 (11:48 -0700)]
Fix typo in SharedMutex comment
Reviewed By: yfeldblum
Differential Revision:
D3611881
fbshipit-source-id:
3991c18cc2956e9d0b50a20e6daf913ec58ee501
Giuseppe Ottaviano [Sun, 24 Jul 2016 17:21:07 +0000 (10:21 -0700)]
Fix a namespace issue
Reviewed By: dkgi
Differential Revision:
D3586189
fbshipit-source-id:
ce817233a0293e19400b5689c283531be6302c10
Qinfan Wu [Sun, 24 Jul 2016 04:34:49 +0000 (21:34 -0700)]
Add helper functions for mallctl
Summary: As more code is using mallctl, it's worth making these helper functions available everywhere.
Reviewed By: yfeldblum
Differential Revision:
D3576190
fbshipit-source-id:
968e80e00f2ed93542e117c24861c21745b63f20
Yedidya Feldblum [Sat, 23 Jul 2016 22:44:57 +0000 (15:44 -0700)]
Move RequestContext definitions to source files
Summary:
[Folly] Move `RequestContext` definitions to source files.
Keeping headers lightweight can help with build times.
Reviewed By: djwatson
Differential Revision:
D3609809
fbshipit-source-id:
20608e3ff764c86c24355a328da1dcca9a08fce4
Melanie Subbiah [Fri, 22 Jul 2016 22:01:39 +0000 (15:01 -0700)]
RequestContext changes to facilitate thread tracing
Summary: In order to trigger trace points when a new thread begins/finishes executing, I added functionality to call onSet and onUnset methods on all RequestData objects whenever setContext is called. The main question: will this approach cost us too much overhead?
Reviewed By: djwatson
Differential Revision:
D3604948
fbshipit-source-id:
3b704ca0f2b713458427aa49be12f776939057f8
Mark Isaacson [Fri, 22 Jul 2016 17:47:38 +0000 (10:47 -0700)]
Fix ASAN exposed heap-use-after-free
Summary: This code very obviously wrote past the end of the buffer when the length was 1. Furthermore, it was just downright broken for all values. The author obviously meant to type * instead of +. I took the time to verify that the algorithm is actually correct, while I was working on this. My proof is in the test plan.
Reviewed By: yfeldblum, meyering
Differential Revision:
D3603255
fbshipit-source-id:
5f2a0011ff5401a70ba03993eab6e53e29d87c1c
Christopher Dykes [Fri, 22 Jul 2016 17:16:18 +0000 (10:16 -0700)]
Rename GetTickCount to GetClockTickCount
Summary: Because Windows already defines a funtion named `GetTickCount` with a different signature.
Reviewed By: yfeldblum
Differential Revision:
D3601877
fbshipit-source-id:
fa0fb422156a3dc71e149e02a000ccdf3479eea5
Christopher Dykes [Fri, 22 Jul 2016 17:15:29 +0000 (10:15 -0700)]
Update FB_ONE_OR_NONE in Preproc.h to work with MSVC
Summary: There was an MSVC section, but it's much simpler to just use the glue to solve the issue instead.
Reviewed By: yfeldblum
Differential Revision:
D3601184
fbshipit-source-id:
f95bd3dfc4b244e1bce21997f44de2970575ad7f
Christopher Dykes [Fri, 22 Jul 2016 17:15:00 +0000 (10:15 -0700)]
Always use the 64-bit conversion function in ConvBenchmark.cpp
Summary: A `long` on MSVC is only 4 bytes, so the `static_assert` will fail. Remove the static assert and use the `long long` version instead. Do the same for the unsigned version.
Reviewed By: yfeldblum
Differential Revision:
D3601064
fbshipit-source-id:
70c5f4bca597ba05c3729f5d15feeea3cc8fde57
Christopher Dykes [Fri, 22 Jul 2016 17:14:46 +0000 (10:14 -0700)]
Include the Builtins portability header in Bits.h
Summary: Because we need it for MSVC.
Reviewed By: yfeldblum
Differential Revision:
D3601138
fbshipit-source-id:
4d2ba3f9c972717745289686b025d2763f9ef30d
Christopher Dykes [Fri, 22 Jul 2016 17:14:15 +0000 (10:14 -0700)]
Include the sys/types.h portability header
Summary: As the comment in the file says, this has to be included in a weird order due to issues on Windows.
Reviewed By: yfeldblum
Differential Revision:
D3601008
fbshipit-source-id:
fca4b6d906eb0d1f001c28197987165cd075752d
Christopher Dykes [Fri, 22 Jul 2016 17:13:42 +0000 (10:13 -0700)]
Use decltype to get the type of a non-static local
Summary: As the `sizeof()` is being evaluated in a static context, MSVC doesn't let you reference non-static locals. Solve the issue by getting the type of the local via `decltype` instead.
Reviewed By: yfeldblum
Differential Revision:
D3600845
fbshipit-source-id:
825d93ced8f09d9f4bf0dcf02142f47a0ec32605
Christopher Dykes [Fri, 22 Jul 2016 17:13:30 +0000 (10:13 -0700)]
Don't typedef types to the same name in different namespaces
Summary:
This was causing MSVC to complain due to `DSched` already being declared in `BatonTestHelpers.h` as `::folly::DSched`, but it's then typedef'd again in `BatonTest.cpp`, this time as `::DSched`. MSVC complains about the duplicate definitions even though they resolve to the same type, so kill the one in the source file and keep the one in the header.
The same is the case with `GroupVarint32Decoder` and `GroupVarint64Decoder`, which are both declared in `GroupVarint.h` and then again, this time in an anon namespace, in `GroupVarintTest.cpp`.
Reviewed By: yfeldblum
Differential Revision:
D3600948
fbshipit-source-id:
401790aa918289fe4a34dd5af683f8c6ca50d847
Wez Furlong [Fri, 22 Jul 2016 00:51:38 +0000 (17:51 -0700)]
folly: fixup folly::Random FixedSeed test expectations on macOS
Summary:
uniform_int_distribution is implemented differently on this system and
always returns the generated number from our constant random number generator.
Reviewed By: yfeldblum
Differential Revision:
D3585418
fbshipit-source-id:
754076599ba77b49c17f03bb0c92264a3bed4ab0
Christopher Dykes [Thu, 21 Jul 2016 23:56:32 +0000 (16:56 -0700)]
Don't use ?:
Summary:
Because it doesn't exist in the C++ standard.
This switches them to the explicitly expanded form, which is in the spec.
It also removes a few that were doing absolutely nothing. (MSVC still complained about the division by zero)
Reviewed By: yfeldblum
Differential Revision:
D3479260
fbshipit-source-id:
5386e27057beeb4b228f5d6be4e1cf9941cf3176
Christopher Dykes [Thu, 21 Jul 2016 23:16:12 +0000 (16:16 -0700)]
Support StlVectorTest for MSVC
Summary:
Sure, it's big, but it compiles.
There are a few different changes to make this happen, the first is to deal with quite a few places where MSVC was complaining about the implicit coersion of template and noexcept parameters to bool.
Next, the gating that disabled this for 4.7 is now gone.
MSVC's runtime expected `difference_type` to be defined on our custom allocator, so it now is.
`ReadTSC()` was changed to use MSVC's intrinsic for this.
And finally, the named variadic parameters to macros were switched to normal variadic macro params, as MSVC doesn't support named ones.
Reviewed By: yfeldblum
Differential Revision:
D3479761
fbshipit-source-id:
703a5ef942ffc9b63381d13fc3960ac6f2780aa0
Christopher Dykes [Thu, 21 Jul 2016 23:12:57 +0000 (16:12 -0700)]
Mark a couple of local constants as static constexpr
Summary: Because they aren't captured, and thus aren't accessible, in the callback used further on in the function.
Reviewed By: yfeldblum
Differential Revision:
D3600874
fbshipit-source-id:
699b3d4caa0a310b1ccc7810d670671850f4366b
Christopher Dykes [Thu, 21 Jul 2016 23:09:26 +0000 (16:09 -0700)]
Disable a test of ThreadLocal across forks for Windows
Summary: We don't have `fork()` to begin with, so disable the test and the includes it required if we're compiling on Windows.
Reviewed By: yfeldblum
Differential Revision:
D3600600
fbshipit-source-id:
5399705753b456139105f4ac757190e1ba1765f2
Yedidya Feldblum [Wed, 20 Jul 2016 22:07:31 +0000 (15:07 -0700)]
allocate_sys_buffer
Summary:
[Folly] `allocate_sys_buffer`.
For when a `malloc`'d buffer is required, with an associated deleter that calls `free`.
Reviewed By: JonCoens
Differential Revision:
D3590516
fbshipit-source-id:
644f4b5d5e8f19dbc8f29efe3e93517fba0ad72f
Mingtian Yin [Wed, 20 Jul 2016 18:43:19 +0000 (11:43 -0700)]
Record whether cached certificate was used
Summary: Record whether cached certificate was used
Reviewed By: anirudhvr
Differential Revision:
D3582807
fbshipit-source-id:
246107ce383ff31718ee7dcccf8bbea459b559a8
Wez Furlong [Wed, 20 Jul 2016 17:58:54 +0000 (10:58 -0700)]
folly: allow folly::init to build on systems without the symbolizer (macOS)
Summary:
This makes folly/init/Init.cpp compile on macOS by leveraging
equivalent functionality in the glog library when the folly symbolizer is not
available. This is true for macOS and also for Windows. I haven't done
anything to handle Windows in this diff.
Reviewed By: yfeldblum
Differential Revision:
D3585509
fbshipit-source-id:
2e0c29520a53826acbf656a7a02659b4e905802f
Christopher Dykes [Tue, 19 Jul 2016 22:58:01 +0000 (15:58 -0700)]
Wrappers folly::chrono::clock_gettime and clock_gettime_ns
Summary:
On Linux hosts, the fast path to get the current time in
nanoseconds without doing a syscall to the kernel is available via the
VDSO kernel-runtime interface.
In this diff, I:
1. Expose portability wrappers `folly::chrono::clock_gettime()` and
`folly::chrono::clock_gettime_ns()`
2. Implement a VDSO wrapper on Linux hosts to implement those without
a round-trip to the kernel
Depends On
D3418054
Reviewed By: bmaurer
Differential Revision:
D3418087
fbshipit-source-id:
3fb99f0dd946f19ba29d0d52a1038dad3556bafd
Steve Muir [Tue, 19 Jul 2016 22:48:41 +0000 (15:48 -0700)]
Generate a pkg-config file for Folly
Summary: First cut at autoconf rules for generating a pkg-config file for Folly. The only interesting part is that we want to handle packages that provide their own .pc files as dependencies rather than just stuffing them into the list of libraries required from packages that don't provide .pc.
Reviewed By: simpkins
Differential Revision:
D3556611
fbshipit-source-id:
d1c5f89416d1d96d2cdf5ccdc5bd7117fb822a82
Christopher Dykes [Tue, 19 Jul 2016 22:44:31 +0000 (15:44 -0700)]
Handle small_vectors with 0 inline capacity correctly
Summary: It is an error to attempt to get the size of a zero length array, such as `unsigned char[0]`, which is what you get if `MaxInline` has been passed in as 0. We can work around this by simply defining `InlineStorageType` to be `void*` if the size is exactly 0, which will result in the capacity correctly being stored out of line.
Reviewed By: yfeldblum
Differential Revision:
D3572898
fbshipit-source-id:
c96bb7cc6a890044bb74b0f6d5238c503552ee25
Elliott Clark [Tue, 19 Jul 2016 22:30:08 +0000 (15:30 -0700)]
Correctly use iters_ in ProducerConsumerQueueBenchmark
Summary: iters was only being used on one side of the producer/consumer.
Reviewed By: yfeldblum
Differential Revision:
D3588593
fbshipit-source-id:
5e9a8a02bb9addbd6f936b8cc411d58cdf82b6e2
Yedidya Feldblum [Tue, 19 Jul 2016 21:38:12 +0000 (14:38 -0700)]
Make the mprotect variant of asymmetricHeavyBarrier work when mlock fails
Summary: [Folly] Make the `mprotect` variant of `asymmetricHeavyBarrier` work when `mlock` fails.
Reviewed By: djwatson
Differential Revision:
D3585948
fbshipit-source-id:
c3a46884434b7f9da9caa9cf203573f9e3ce7444
Michael Lee [Tue, 19 Jul 2016 20:26:37 +0000 (13:26 -0700)]
Fix macro check in SysMembarrier
Summary:
FOLLY_X64 is usually defined, so check whehter it is defined
to 0 or 1. In addition, memory barriers are not necessarily widely
available on the mobile platforms. What leads me to believe this is
that, at least for older ndk's, atomics are not guaranteed to work for
multicore platforms.
Reviewed By: andriigrynenko
Differential Revision:
D3586806
fbshipit-source-id:
3ac8c4b74cac09e41bc3cb65c8adc2732b8b2256
Wez Furlong [Tue, 19 Jul 2016 16:45:24 +0000 (09:45 -0700)]
folly: unconditionally include boost mutex definitions on macOS
Summary:
macOS doesn't have timedwait functionality and this header file was
gating including the boost headers on that check which caused dependent modules
to fail to compile because `boost::mutex` and `boost::recursive_mutex` were not
known to the compiler.
Reviewed By: yfeldblum
Differential Revision:
D3585470
fbshipit-source-id:
7f8d9603e95ce01328103c7c6ac0bc75a35ddf4d
Christopher Dykes [Tue, 19 Jul 2016 02:49:24 +0000 (19:49 -0700)]
Make sure to return from atomicHashArrayInsertRaceThread
Summary: Because, unfortunately, `pthread_exit` is not marked as noreturn in the pthread library primarily used on Windows, we need to return something to avoid errors.
Reviewed By: yfeldblum
Differential Revision:
D3571465
fbshipit-source-id:
4713b2364d6584ae255fb83cd21406fdc33ee299
Andrii Grynenko [Tue, 19 Jul 2016 01:17:06 +0000 (18:17 -0700)]
Use membarrier in TLRefCount
Summary: membarrier guarantees that there's at most one update to thread-local counter, which collecting thread may not see.
Reviewed By: djwatson
Differential Revision:
D3532952
fbshipit-source-id:
6106bfe87c70c5f864573a424662778e20423bbb
Wez Furlong [Mon, 18 Jul 2016 23:33:31 +0000 (16:33 -0700)]
folly: improve setThreadName for macOS
Summary:
Since OS X 10.6 it is possible to set the name of the current thread.
This diff adjusts our setThreadName routine to do this, partially fixing
the associated test case. Even though this doesn't completely cover
all cases it is still a valid improvement: most callers are
threads setting their own name.
I've amended the tests so that they can accomodate systems that cannot
set the names of other threads.
Reviewed By: yfeldblum
Differential Revision:
D3576281
fbshipit-source-id:
13caf0dca6496aa2da897631e8d7327a6ee452bb
Andrii Grynenko [Mon, 18 Jul 2016 20:26:59 +0000 (13:26 -0700)]
Fix mocking to support multiple overrides
Summary: When installing the mock, we should make sure to remove singleton from the creation_order list.
Differential Revision:
D3580725
fbshipit-source-id:
dfb489de1be860ab639380644eab0b45a07a1450
Christopher Dykes [Mon, 18 Jul 2016 16:58:00 +0000 (09:58 -0700)]
Always pack small_vector
Summary:
The check was overly restrictive, the conditional packing was originally used to limit it to GCC only (as it used the `__attribute__` directly), but that restriction is no longer needed as `FOLLY_PACK_*` will be defined appropriately for whatever platform we are currently on.
This just switches it to unconditionally use the `FOLLY_PACK_*` macros rather than defining it's own `FB_PACK_*` macros.
See https://github.com/facebook/folly/commit/
aafd8ff9151615a8de09682d41d1c29966e4c8fe for where the `FB_PACK_*` macros could originally have been removed.
Reviewed By: yfeldblum
Differential Revision:
D3373779
fbshipit-source-id:
9e41b0836f8ba12de4f37aba58c51f841be08b41
Christopher Dykes [Mon, 18 Jul 2016 16:56:55 +0000 (09:56 -0700)]
Make static analysis happy about the length of patternBuf
Summary: The static analysis doesn't quite understand that we are assigning a NUL to, at most, `patternBuf[MAX_PATH + 1]` so increase the buffer size slightly to make it happy.
Reviewed By: yfeldblum
Differential Revision:
D3571923
fbshipit-source-id:
c027e2b253dc3e56d13e9a15a0e960a6aa3a0e6c
Christopher Dykes [Mon, 18 Jul 2016 16:48:58 +0000 (09:48 -0700)]
Add an Atomic portability header
Summary: Because there are situations where we need to do an atomic write to a plain pointer, rather than an atomic value. Unfortunately, there is no support in the standard library for this, so different compilers implement the primitives differently. This specifically implements an `int64_t` overload for `__sync_fetch_and_add` for use in the atomic hash map test.
Reviewed By: yfeldblum
Differential Revision:
D3571830
fbshipit-source-id:
c27d8d2a5238bbc9aba6a9e48e4b3412a199288f
Wez Furlong [Sun, 17 Jul 2016 06:02:32 +0000 (23:02 -0700)]
folly: fix initialization for CLOCK_PROCESS_CPUTIME_ID emulation on macOS
Summary:
this fixes TimeTest on macOS.
The problem was that `task_info_count` is an in/out parameter and it wasn't correctly initialized due to a typo. The lack of initialization meant that the `task_info()` call would fail at runtime.
Reviewed By: yfeldblum
Differential Revision:
D3576262
fbshipit-source-id:
8388fa3c5020309d64a0fa7e01fd6cea80200219
Wez Furlong [Sat, 16 Jul 2016 21:32:38 +0000 (14:32 -0700)]
folly: fix constexpr methods in RandomTest on macos
Summary:
the RNG max and min methods must be marked constexpr in order to
compile. The macos compiler doesn't know to propagate the constexpr-ness from
numeric_limits::max on its own, so we have to be explicit (this also matches
the annotations in ThreadLocalPRNG in Random.h)
Reviewed By: yfeldblum
Differential Revision:
D3576189
fbshipit-source-id:
e4eeb3361d1c48f582dad5a52e35cae133f007a1
Wez Furlong [Sat, 16 Jul 2016 21:13:32 +0000 (14:13 -0700)]
folly: fixup CompressionTest compilation on macos
Summary:
The compiler on macos is pedantic about the size of the 9UL not
matching the size of the type returned by `oneBasedMsbPos`. Cast it to
the appropriate size.
Reviewed By: meyering
Differential Revision:
D3576183
fbshipit-source-id:
41e9afc78eed2994e34238da119774e9bf6b7cea
Qinfan Wu [Sat, 16 Jul 2016 05:52:10 +0000 (22:52 -0700)]
Fix FBStringTest build failure and hash computation for wchar
Summary:
Getting some build errors when doing `buck test folly/...`. This seems to be fixing it.
folly/test/FBStringTest.cpp:1290:23: error: unknown type name 'basic_fbstring'; did you mean 'basic_fstream'?
using u16fbstring = basic_fbstring<char16_t>;
^~~~~~~~~~~~~~
basic_fstream
Also the test `testHashChar16` was failing because only part of the string is used when computing hash.
Reviewed By: yfeldblum
Differential Revision:
D3575858
fbshipit-source-id:
cdd5bdb9653d50beaf0ec82b659d31354b345441
Tom Jackson [Sat, 16 Jul 2016 00:07:29 +0000 (17:07 -0700)]
get_or_throw(map, key) returns references
Differential Revision:
D3572671
fbshipit-source-id:
a80390921b41e47ed2794d48d943a9e4060c7135
Matthieu Martin [Fri, 15 Jul 2016 23:49:20 +0000 (16:49 -0700)]
Fix compilation issue related to Fibers WhenN
Summary: In a separate diff, I made changes that switched include order, and suddently this file failed to compile. This fixes it.
Reviewed By: andriigrynenko
Differential Revision:
D3574775
fbshipit-source-id:
02422d803708aa8490123d19aab5a16c10fdc36e