Sven Over [Tue, 22 Mar 2016 13:10:19 +0000 (06:10 -0700)]
Introducing folly::Function
Summary:std::function is copy-constructible and requires that the callable that it wraps
is copy-constructible as well, which is a constraint that is often inconvenient.
In most cases when using a std::function we don't make use of its
copy-constructibility.
This diff introduces a templated type called folly::Function that is very
similar to a std::function, except it is not copy-constructible and doesn't
require the callable to be either.
Like std::function, Function is a templated type with template parameters
for return type and argument types of the callable, but not the callable's
specific type. It can store function pointers, static member function pointers,
std::function objects, std::reference_wrapper objects and arbitrary callable
types (functors) with matching return and argument types.
Much like std::function, Function will store small callables in-place, so
that no additional memory allocation is necessary. For larger callables,
Function will allocate memory on the heap.
Function has two more template parameters: firstly, an enum parameter of
type folly::FunctionMoveCtor, which defaults to NO_THROW and determines
whether no-except-movability should be guaranteed. If set to NO_THROW,
callables that are not no-except-movable will be stored on the heap, even
if they would fit into the storage area within Function.
Secondly, a size_t parameter (EmbedFunctorSize), which determines the size of
the internal callable storage. If you know the specific type of the callable you
want to store, you can set EmbedFunctorSize to sizeof(CallableType).
The original motivation of this diff was to allow to pass lambdas to
folly::Future::then that are not copy-constructible because they capture
non-copyable types, such as a promise or a unique pointer.
Another diff will shortly follow that changes folly::Future to use
folly::Function instead of std::function for callbacks, thus allowing to
pass non-copyable lambdas to folly::Future::then.
Reviewed By: fugalh
Differential Revision:
D2844587
fb-gh-sync-id:
3bee2af75ef8a4eca4409aaa679cc13762cae0d0
shipit-source-id:
3bee2af75ef8a4eca4409aaa679cc13762cae0d0
Michael Lee [Tue, 22 Mar 2016 01:02:31 +0000 (18:02 -0700)]
Use FOLLY_MOBILE to split some functionality
Summary: The guards already look for __APPLE__, but __ANDROID__ needs this as well.
Reviewed By: yfeldblum
Differential Revision:
D3053976
fb-gh-sync-id:
a9ba7a612d29502d4a7e691c6741837d4a8b42f0
shipit-source-id:
a9ba7a612d29502d4a7e691c6741837d4a8b42f0
Orvid King [Tue, 22 Mar 2016 17:21:25 +0000 (10:21 -0700)]
Revert "Changed AC_LANG from PROGRAM to SOURCE to prevent double definition of main"
This reverts commit
bb733f43b5674294a12c99ac3e686c4b54427917.
Anirudh Ramachandran [Mon, 21 Mar 2016 23:25:46 +0000 (16:25 -0700)]
Add support for probabilistically choosing server ciphers
Summary:Since SSLContextManager sets SSL_OP_CIPHER_SERVER_PREFERENCE on the SSL_CTX
when it creates contexts, we may be unable to accommodate any clients who
prefer a different ciphersuite. Having differently weighted cipher preference
lists allows SSLContext to set a list with a different most-preferred cipher
for some fraction of new handshakes.
Note: resumption will work with the previously negotiated ciphersuite even if
the server doesn't explicitly prefer/support it anymore, provided the cipher is
supported in OpenSSL.
Reviewed By: knekritz
Differential Revision:
D3050496
fb-gh-sync-id:
1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
shipit-source-id:
1c3b77ce3af87f939f8b8c6fe72b6a64eeaeeeb4
Michael Lee [Mon, 21 Mar 2016 22:52:19 +0000 (15:52 -0700)]
Have StringTest use PRI*64 instead
Summary: This helps account for 32-bit vs. 64-bit compilation targets.
Reviewed By: benyl
Differential Revision:
D3076523
fb-gh-sync-id:
56f49daaf55d242ac48f8b8d38a40c6d6230818b
shipit-source-id:
56f49daaf55d242ac48f8b8d38a40c6d6230818b
Anirudh Ramachandran [Mon, 21 Mar 2016 22:46:23 +0000 (15:46 -0700)]
Add option to retrieve hex representation of client ciphers
Summary: A more compact hex representation of ciphers in ClientHello can be useful, e.g., for logging.
Reviewed By: knekritz
Differential Revision:
D3052308
fb-gh-sync-id:
beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
shipit-source-id:
beaf6fcd4705d4d7fae652d8d8b95b52ca9e07a9
Christopher Dykes [Mon, 21 Mar 2016 22:05:49 +0000 (15:05 -0700)]
Add Windows support to portability/Memory.h
Summary: This adds Windows support to portability/Memory.h and also does some refactoring to be more correct about when to use posix_memalign, and also changes it to fall back to memalign rather than posix_memalign.
Reviewed By: mzlee
Differential Revision:
D3069990
fb-gh-sync-id:
88861583c6028e9fb02a3e3804bd6d476956c555
shipit-source-id:
88861583c6028e9fb02a3e3804bd6d476956c555
Giuseppe Ottaviano [Mon, 21 Mar 2016 03:34:23 +0000 (20:34 -0700)]
Optimize fbstring::append()
Summary:Instead of relying on `push_back()` to guarantee exponential growth,
delegate to `expand_noinit`. This removes the duplication of logic
between the two functions, and significantly speeds up short appends.
```
$ _bin/folly/test/fbstring_benchmark_using_jemalloc --bm_min_usec=100000
Before: After:
============================================================================ ===================
./folly/test/FBStringTestBenchmarks.cpp.h relative time/iter iters/s time/iter iters/s
============================================================================ ===================
...
BM_push_back_fbstring(1) 7.51ns 133.20M 6.87ns 145.49M
BM_push_back_fbstring(23) 175.08ns 5.71M 173.92ns 5.75M
BM_push_back_fbstring(127) 586.02ns 1.71M 585.70ns 1.71M
BM_push_back_fbstring(1024) 3.30us 302.81K 3.41us 293.13K
BM_short_append_fbstring(23) 367.01ns 2.72M 179.45ns 5.57M
BM_short_append_fbstring(1024) 9.33us 107.20K 5.72us 174.95K
...
============================================================================ ===================
```
Reviewed By: philippv
Differential Revision:
D3075249
fb-gh-sync-id:
497775ba3fc707bf50821a3cf10fb9d247b9352d
shipit-source-id:
497775ba3fc707bf50821a3cf10fb9d247b9352d
Christopher Dykes [Sun, 20 Mar 2016 18:06:56 +0000 (11:06 -0700)]
Add features to portability/Config.h
Summary: It is perfectly reasonable to need to feature macros when checking configuration, and the configuration is needed to know if features.h exists, so put it in the same file.
Reviewed By: yfeldblum
Differential Revision:
D3072255
fb-gh-sync-id:
0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
shipit-source-id:
0f253dd1fa2f4a95adb11f11c45e6b86ef9c25bc
Christopher Dykes [Sun, 20 Mar 2016 18:06:40 +0000 (11:06 -0700)]
Split iovec out of SysUio.h
Summary: This is needed to avoid a circular dependency.
Reviewed By: yfeldblum
Differential Revision:
D3072037
fb-gh-sync-id:
546a46fd68f25f0c5b027d4d938335b2711d8fdd
shipit-source-id:
546a46fd68f25f0c5b027d4d938335b2711d8fdd
Mark Reitblatt [Sun, 20 Mar 2016 09:00:17 +0000 (02:00 -0700)]
fix typo in log printing in AsyncSSLSocket
Reviewed By: pritamdamania
Differential Revision:
D3068807
fb-gh-sync-id:
0b45ab678e2ec5565eb379540576527cf8b1d308
shipit-source-id:
0b45ab678e2ec5565eb379540576527cf8b1d308
Jeremy Wright [Sat, 19 Mar 2016 00:11:23 +0000 (17:11 -0700)]
Upgrade ScopeGuard for Visual Studio 2015
Summary:Upgrade UncaughtExceptionCounter to use std::uncaught_exceptions on Visual Studio 2015 Update 1
Closes https://github.com/facebook/folly/pull/358
Reviewed By: yfeldblum
Differential Revision:
D3066005
Pulled By: Orvid
fb-gh-sync-id:
6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
shipit-source-id:
6bc7129aa794257b1f6e7a084139d8a3a52fa4a8
Christopher Dykes [Fri, 18 Mar 2016 21:57:46 +0000 (14:57 -0700)]
Create the sys/mman.h portability header
Summary: Something that Windows very definitely lacks. This is a fun one.
Reviewed By: yfeldblum
Differential Revision:
D2979661
fb-gh-sync-id:
e23c1db0cb8655b22308b874bd421a7cc1e4759e
shipit-source-id:
e23c1db0cb8655b22308b874bd421a7cc1e4759e
Yedidya Feldblum [Thu, 17 Mar 2016 21:08:38 +0000 (14:08 -0700)]
Remove pthread_yield support
Summary:[Folly] Remove `pthread_yield` support.
* It is not actually part of POSIX - rather, `sched_yield` is.
* In C++, we should be using `std::this_thread::yield` anyway.
Reviewed By: Gownta
Differential Revision:
D3056221
fb-gh-sync-id:
2fea55dd7b715149327987d61e5a573ad0455330
shipit-source-id:
2fea55dd7b715149327987d61e5a573ad0455330
Subodh Iyengar [Thu, 17 Mar 2016 20:06:21 +0000 (13:06 -0700)]
Allow override of session context
Summary:We currently set the session context to the
default of common name, this allows session
context to be set to a different value
for different applications
Reviewed By: ngoyal
Differential Revision:
D3059769
fb-gh-sync-id:
185afeb487c2c62dcf44f96076bd05871692c7ab
shipit-source-id:
185afeb487c2c62dcf44f96076bd05871692c7ab
Andrew Cox [Thu, 17 Mar 2016 14:09:07 +0000 (07:09 -0700)]
Tell ASAN about fiber stacks
Summary:ASAN needs to know about the stack extents. Currently it has no knowledge of
fibers and so it can give false positives, particularly in cases of no-return
(think exceptions).
See: https://github.com/google/sanitizers/issues/189
This change along with a related ASAN diff fixes that, and I've verified it
fixes false positive test failures I'm seeing when throws happen from fibers.
Also rips out some hacks that attempted to work around the limitations of
ASAN these changes should fix.
This change depends on:
D3017630
D2952854
D3017619
And will also depend on rollout of libasan.so to /usr/local/fbcode platform dirs on all machines.
Reviewed By: andriigrynenko
Differential Revision:
D2952899
fb-gh-sync-id:
19da779227c6c0f30c5755806325aa4cba364cfe
shipit-source-id:
19da779227c6c0f30c5755806325aa4cba364cfe
Christopher Dykes [Wed, 16 Mar 2016 22:15:52 +0000 (15:15 -0700)]
Create portability/Config.h
Summary: Because including the root portability header just to get a couple of defines to be able to enable things is a waste. In addition, it would be nice if the config defines are never needed outside of the portability headers.
Reviewed By: yfeldblum
Differential Revision:
D3059651
fb-gh-sync-id:
1cb9910d850ea015616a598808556b4815b3fb74
shipit-source-id:
1cb9910d850ea015616a598808556b4815b3fb74
Eric Niebler [Wed, 16 Mar 2016 16:54:38 +0000 (09:54 -0700)]
move StaticMeta::onThreadExit into libfolly_thread_local.so
Summary: Fix folly/test:thread_local_test in the shared library scenario by moving onThreadExit into libfolly_thread_local.so, avoiding the crash when a user's .so is dlclosed.
Reviewed By: andriigrynenko
Differential Revision:
D2919287
fb-gh-sync-id:
ecc4220fd40203289366eb1a6391b8b6d971e65f
shipit-source-id:
ecc4220fd40203289366eb1a6391b8b6d971e65f
Phil Willoughby [Wed, 16 Mar 2016 14:22:26 +0000 (07:22 -0700)]
Remove `using std::make_unique`
Summary: Older compilers do not have have `std::make_unique`. We have `folly::make_unique` which does the same job, and because we already have `using namespace folly` in this file it suffices to erase the `using std::make_unique` line.
Reviewed By: eduardosuarez
Differential Revision:
D3058089
fb-gh-sync-id:
a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37
shipit-source-id:
a5a5eb54e2bc0ba7ef0880f2b5680a79d1f41d37
Yedidya Feldblum [Wed, 16 Mar 2016 07:28:24 +0000 (00:28 -0700)]
Remove an outdated/inapplicable comment
Summary: [Folly] Remove an outdated/inapplicable comment from `folly/Portability.h`.
Reviewed By: Gownta
Differential Revision:
D3055909
fb-gh-sync-id:
c17fdcc7de13fe5a9bb38bb4498a006ec71a61e2
shipit-source-id:
c17fdcc7de13fe5a9bb38bb4498a006ec71a61e2
Christopher Dykes [Tue, 15 Mar 2016 20:23:20 +0000 (13:23 -0700)]
Add portability header for sys/file.h
Summary: We don't have it on Windows :(
Reviewed By: yfeldblum
Differential Revision:
D2978397
fb-gh-sync-id:
388bc450ce269559825ebfb78e3646533c2e1153
shipit-source-id:
388bc450ce269559825ebfb78e3646533c2e1153
Igor Sugak [Tue, 15 Mar 2016 20:00:36 +0000 (13:00 -0700)]
folly/subprocess: fix one -Wsign-conversion and clag 3.9 test
Summary:easy:
`options.parentDeathSignal_` is `int`, and second argument of `prctl` is `unsigned long`. Adding explicit cast.
hard:
this change is fixing a real problem when building folly with Clang 3.9.0. The [[ https://github.com/llvm-mirror/clang/commit/
f4ddf94ecbd9899a497151621f3871545e24e93b | new alignment implementation ]] in `-O3` generates code that breaks folly's `ParentDeathSubprocessTest.ParentDeathSignal`.
For the following snipped of code:
```lang=cpp
if (options.parentDeathSignal_ != 0) {
if (prctl(PR_SET_PDEATHSIG, options.parentDeathSignal_, 0, 0, 0) == -1) {
return errno;
}
}
```
LLVM generates the following assembly:
```lang=asm
0x000000000040a77b <+347>: mov 0x28(%r14),%rsi
0x000000000040a77f <+351>: test %esi,%esi
0x000000000040a781 <+353>: je 0x40a7a1 <folly::Subprocess::prepareChild(folly::Subprocess::Options const&, __sigset_t const*, char const*) const+385>
0x000000000040a783 <+355>: mov $0x1,%edi
0x000000000040a788 <+360>: xor %edx,%edx
0x000000000040a78a <+362>: xor %ecx,%ecx
0x000000000040a78c <+364>: xor %r8d,%r8d
0x000000000040a78f <+367>: xor %eax,%eax
0x000000000040a791 <+369>: callq 0x405ad0 <prctl@plt>
```
`%rsi` is a 64-bit register, on the line 1 value of `0x28(%r14)` is loaded to this register. That address points to `options.parentDeathSignal_`, which is a 32-bit value, set to 10 somewhere in a test. After that load:
```
rsi 0x7f000000000a
```
Notice it is not 10 (0xa), there is some garbage value in the upper part of the register. On the line 2, the lower part of this register is checked if it is zero, which corresponds to the first if statement. Then lines 4-8 prepare for `prctl` call. The value of the second argument is passed via `%rsi`, but the upper 32 bits were not cleared. This makes the function call generate `Invalid argument` error.
With the added explicit cast, notice a call `movslq %eax,%rsi`, which moves a signed 32-bit value of `%eax` (which contains `options.parentDeathSignal_`) to unsigned 64-bin `%rsi`:
```
0x000000000040a77b <+347>: mov 0x28(%r14),%rax
0x000000000040a77f <+351>: test %eax,%eax
0x000000000040a781 <+353>: je 0x40a7a4 <folly::Subprocess::prepareChild(folly::Subprocess::Options const&, __sigset_t const*, char const*) const+388>
0x000000000040a783 <+355>: movslq %eax,%rsi
0x000000000040a786 <+358>: mov $0x1,%edi
0x000000000040a78b <+363>: xor %edx,%edx
0x000000000040a78d <+365>: xor %ecx,%ecx
0x000000000040a78f <+367>: xor %r8d,%r8d
0x000000000040a792 <+370>: xor %eax,%eax
0x000000000040a794 <+372>: callq 0x405ad0 <prctl@plt>
```
Reviewed By: yfeldblum
Differential Revision:
D3051611
fb-gh-sync-id:
fc0f809bc4be0eed79dc5a701717efa27fedc022
shipit-source-id:
fc0f809bc4be0eed79dc5a701717efa27fedc022
Phil Willoughby [Tue, 15 Mar 2016 08:39:48 +0000 (01:39 -0700)]
Convert a polling loop to a futex wait
Summary:Add a new method to MPMCQueue:
```
template <class Clock, typename... Args>
bool tryWriteUntil(const std::chrono::time_point<Clock>& when,
Args&&... args) noexcept
```
This allows you to write producers which terminate reliably in the absence of consumers.
Returns `true` if `args` was enqueued, `false` otherwise.
`Clock` must be one of the types supported by the underlying call to `folly::detail::Futex::futexWaitUntil`; at time of writing these are `std::chrono::steady_clock` and `std::chrono::system_clock`.
Reviewed By: nbronson
Differential Revision:
D2895574
fb-gh-sync-id:
bdfabcd043191c149f1271e30ffc28476cc8a36e
shipit-source-id:
bdfabcd043191c149f1271e30ffc28476cc8a36e
Subodh Iyengar [Tue, 15 Mar 2016 06:08:18 +0000 (23:08 -0700)]
Allow httpsession to be movable readCB
Summary:Allow HTTPSession to have a movable read
callback independent of the openssl check.
This allows other downstream transports to
deliver app data more efficiently.
Reviewed By: w-o-o, knekritz
Differential Revision:
D3023517
fb-gh-sync-id:
ff27c0e14f7364ad7d7b0028ef740b2678dbcb4c
shipit-source-id:
ff27c0e14f7364ad7d7b0028ef740b2678dbcb4c
Michael Lee [Tue, 15 Mar 2016 01:54:37 +0000 (18:54 -0700)]
Missing guards for FOLLY_TLS in test
Summary:defined(FOLLY_TLS) is guarded once in the test, so we should
guard for it throughout. Also a missing header for some platforms.
Reviewed By: yfeldblum
Differential Revision:
D3049797
fb-gh-sync-id:
5d66c71dda94c57a2e50aee96d55be1c574bf921
shipit-source-id:
5d66c71dda94c57a2e50aee96d55be1c574bf921
Sven Over [Mon, 14 Mar 2016 18:43:33 +0000 (11:43 -0700)]
folly/portability/Constexpr.h: add missing include statement
Summary:This commit fixes compiler errors when Constexpr.h was included
on gcc before cstring (or string.h) was included. Also, qualify
the call to strlen with the std namespace.
Reviewed By: yfeldblum
Differential Revision:
D3047417
fb-gh-sync-id:
7a50dac2e9449b149062896f34fa5e864f767943
shipit-source-id:
7a50dac2e9449b149062896f34fa5e864f767943
Michael Lee [Mon, 14 Mar 2016 16:34:01 +0000 (09:34 -0700)]
Fix a typo in portability/Memory.cpp
Summary: Also, add error checking back in, and remove the empty WIN32 implementation.
Reviewed By: francis-ma
Differential Revision:
D3047494
fb-gh-sync-id:
5a2a18cd1ca675a081ad2a9252c765ab56527b6b
shipit-source-id:
5a2a18cd1ca675a081ad2a9252c765ab56527b6b
Jimmy Saade [Mon, 14 Mar 2016 12:07:14 +0000 (05:07 -0700)]
folly::FunctionScheduler: Adding capability to reset a function's timer
Summary:Adding support for resetting a specified function's timer.
"Resetting a function's timer" effectively means "canceling whatever next runs it would have had, and treating it as though it were just added".
When `resetFunctionTimer` is called, the specified function's interval (timer) will be reset, and it will execute after its initially-specified `startDelay`. If the `startDelay` is zero, the function will execute immediately, and then be scheduled as before - once every `interval` milliseconds.
Motivation: batch processing of updates, where both a size and time limit are in play. If the size limit is reached, it makes sense to reset the timer for the scheduled function.
Differential Revision:
D3045868
fb-gh-sync-id:
a5ceb0069c04a77fdab16b61679987ee55484e89
shipit-source-id:
a5ceb0069c04a77fdab16b61679987ee55484e89
Giuseppe Ottaviano [Sun, 13 Mar 2016 00:12:44 +0000 (16:12 -0800)]
Fix warning in MicroLock initialization
Summary:The `init()` function uses the previous value of `lock_`, but that is
uninitialized and the compiler can issue a warning about it. It is
also potentially undefined behavior because it is not guaranteed that
the address of `lock_` is taken before `init()` (in which case the it
would be just an indeterminate value).
Since it is not very useful to initialize only one slot and leave the
others uninitialized, we can just have a single `init()` that
zero-initializes all the slots.
Reviewed By: dcolascione
Differential Revision:
D3042629
fb-gh-sync-id:
de1633b02eb1c891e310f2d5d2cfc5376cd41d5f
shipit-source-id:
de1633b02eb1c891e310f2d5d2cfc5376cd41d5f
Daniel Colascione [Sat, 12 Mar 2016 21:31:46 +0000 (13:31 -0800)]
Explain union safety in MicroLock comment
Reviewed By: ot
Differential Revision:
D3045850
fb-gh-sync-id:
ee19b146c43410d8d8804c9bfe79c3811394b10e
shipit-source-id:
ee19b146c43410d8d8804c9bfe79c3811394b10e
Wez Furlong [Sat, 12 Mar 2016 00:36:37 +0000 (16:36 -0800)]
folly: fix gflags<->glog configure check ordering
Summary:On systems that do not have gflags or glog installed globally,
but only locally as static libraries, our configure check failed for
glog because we were checking it prior to gflags.
glog depends on gflags, but when the libraries are static, there is
no explicit dependency information available and the linker fails.
This resolves the issue by checking for gflags first; this causes
configure to add an implicit `-lgflags` for the subsequent glog
tests.
Reviewed By: yfeldblum
Differential Revision:
D3044138
fb-gh-sync-id:
5e07ce52842c6e4cff796560672bf950e2fafe6c
shipit-source-id:
5e07ce52842c6e4cff796560672bf950e2fafe6c
Michael Lee [Sat, 12 Mar 2016 00:08:55 +0000 (16:08 -0800)]
Remove portability/Stdlib.{h,cpp}
Summary: This was wrong and is like better solved, not with a shim layer, but by not using such a platform-specific function in the first place.
Reviewed By: yfeldblum
Differential Revision:
D3001253
fb-gh-sync-id:
460cc46b1c9adc3d229a07cb290270f7afbbb1e0
shipit-source-id:
460cc46b1c9adc3d229a07cb290270f7afbbb1e0
Michael Lee [Fri, 11 Mar 2016 00:50:53 +0000 (16:50 -0800)]
Adding portability to gating PicoSpinLock.
Summary:PicoSpinLock only works on x86_64, Arm64, and ppc64 (i.e.,
not 32-bit). Add a bit of gating so we can continue to run tests and
use headers when compiling for i386.
Reviewed By: yfeldblum
Differential Revision:
D2991328
fb-gh-sync-id:
b0d0c229508f65dff62b24fdd9d80c799cd97935
shipit-source-id:
b0d0c229508f65dff62b24fdd9d80c799cd97935
Eric Niebler [Thu, 10 Mar 2016 21:25:07 +0000 (13:25 -0800)]
Fix an exception safety hole in ScopeGuard
Summary: Address the exception safety hole described in https://fburl.com/scopeguard-oops. Addnditional noexcept to the places that need it.
Reviewed By: dcolascione
Differential Revision:
D3033015
fb-gh-sync-id:
8dfec103bbc86abef425585371994756d3df0a14
shipit-source-id:
8dfec103bbc86abef425585371994756d3df0a14
Giuseppe Ottaviano [Wed, 9 Mar 2016 22:35:35 +0000 (14:35 -0800)]
Port easy instances to folly::dynamic::array
Summary:The vast majority of `folly::dynamic` array initializations are
single-line and with no nested arrays, so we can fix them with a
syntactic codemod. This also fixes a couple of singletons.
For empty arrays:
```
codemod '((?:folly::)?)(dynamic\s+\w+\s*=\s*)({\s*})' '\1\2\1dynamic::array'
```
For non-empty ones:
```
codemod '((?:folly::)?)(dynamic\s+\w+\s*=\s*)(?:{\s*([^{}]+?)\s*})' '\1\2\1dynamic::array(\3)'
```
Reviewed By: igorsugak
Differential Revision:
D3030338
fb-gh-sync-id:
3e56704a6c6294d6f6270e42a1776d991a7938df
shipit-source-id:
3e56704a6c6294d6f6270e42a1776d991a7938df
Kyle Nekritz [Wed, 9 Mar 2016 19:18:37 +0000 (11:18 -0800)]
Add replay safety connector/handler to delay transactions scheduled on a replay-unsafe transport.
Summary: This allows HTTPTransactions to be held back until the transport is replay-safe.
Reviewed By: siyengar
Differential Revision:
D2974083
fb-gh-sync-id:
037b14c24a80c828a25e483b6873a8e782af0cb4
shipit-source-id:
037b14c24a80c828a25e483b6873a8e782af0cb4
Christopher Dykes [Wed, 9 Mar 2016 18:30:53 +0000 (10:30 -0800)]
Create the sys/stat.h portability header
Summary: Windows has it, but it doesn't define lstat, and a few other functions have other names.
Reviewed By: yfeldblum
Differential Revision:
D3003096
fb-gh-sync-id:
e7bc210390d18806c8c89cbc18711bb7a728e12f
shipit-source-id:
e7bc210390d18806c8c89cbc18711bb7a728e12f
Kyle Nekritz [Wed, 9 Mar 2016 17:33:14 +0000 (09:33 -0800)]
Make Bits.h respect FOLLY_HAVE_UNALIGNED_ACCESS.
Summary: This was causing a bunch of SIGBUS's on ARM platforms.
Reviewed By: yfeldblum, mzlee
Differential Revision:
D3013458
fb-gh-sync-id:
6d3f60c3f59d16cd3454e3a4231b967e5378724a
shipit-source-id:
6d3f60c3f59d16cd3454e3a4231b967e5378724a
Anirudh Ramachandran [Wed, 9 Mar 2016 02:09:22 +0000 (18:09 -0800)]
SSL cleanup: moving some OpenSSL definitions to new dir folly/io/async/ssl
Summary:SSLContext and AsyncSSLSocket are growing with a lot of code that is
OpenSSL-specific, and it may be good to refactor some of these before it gets
out of hand.
This is also useful to reduce complexity as we some additional features such as ServerHello parsing and TLS Cached Info (
D2936570)
Main changes:
* Created a subdirectory folly/io/async/ssl to refactor code from folly/io/async. We may want to consider moving this out of folly/io/async
* Moved OpenSSLPtrTypes.h to folly/io/async/ssl/OpenSSLPtrTypes.h
* Moved 'OpenSSLUtils' from SSLContext to separate file OpenSSLUtils.{h,cpp}
* Moved TLSExtensions and ClientHelloInfo from AsyncSSLSocket to TLSDefinitions.h
Reviewed By: siyengar
Differential Revision:
D2978707
fb-gh-sync-id:
a21f02947aeffccc447da2124a91cc99315df1c7
shipit-source-id:
a21f02947aeffccc447da2124a91cc99315df1c7
Nathan Bronson [Mon, 7 Mar 2016 21:36:59 +0000 (13:36 -0800)]
minor tweak to MicroLock slow path
Summary:This diff uses the x86 "pause" instruction or its equivalent when
spinning in the MicroLock slow loop. This gives a hint to the processor
that it should devote more resources to the other execution contexts
sharing the same core. This diff also removes an mfence on x86 by using
a slightly stronger memory model on the preceding compare_exchange_weak,
and switches to a more portable way of invoking sched_yield().
Reviewed By: dcolascione
Differential Revision:
D3018568
fb-gh-sync-id:
02e0ab3a9d9bb9901eddf54e45b71cbb7758a227
shipit-source-id:
02e0ab3a9d9bb9901eddf54e45b71cbb7758a227
Giuseppe Ottaviano [Mon, 7 Mar 2016 19:53:13 +0000 (11:53 -0800)]
Deprecate dynamic::dynamic(std::initializer_list<dynamic>)
Summary:After DR95 the single braces dispatch to the copy constructor
(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1467),
so it is not possible anymore to initialize a singleton dynamic array
using the braces syntax. The initializer list constructor already had
a special case for empty lists, which unconditionally called the
default constructor if defined.
This diff deprecates the braces syntax and defines the following alternative:
```
dynamic empty = dynamic::array;
dynamic a = dynamic::array(1, 2, "foo");
```
Reviewed By: luciang, yfeldblum
Differential Revision:
D3013423
fb-gh-sync-id:
a0cf09dfd96e9806044f7c3bf3592c637a9bc932
shipit-source-id:
a0cf09dfd96e9806044f7c3bf3592c637a9bc932
Michael Lee [Mon, 7 Mar 2016 15:41:07 +0000 (07:41 -0800)]
Guard Getcpu in test.
Summary:Guarding this the same way it is done in
detail/CacheLocality.cpp
Reviewed By: yfeldblum
Differential Revision:
D3013288
fb-gh-sync-id:
a1cc65cccc5cdf32339a739853c27a11ecd98ba0
shipit-source-id:
a1cc65cccc5cdf32339a739853c27a11ecd98ba0
Christopher Dykes [Sat, 5 Mar 2016 01:55:27 +0000 (17:55 -0800)]
Create the Windows portability header
Summary: Because Windows' defines seem to get in the way more than they help.
Reviewed By: yfeldblum
Differential Revision:
D2989507
fb-gh-sync-id:
148f390ef6adf977bffa2262aa76839b2bf4f507
shipit-source-id:
148f390ef6adf977bffa2262aa76839b2bf4f507
Yedidya Feldblum [Sat, 5 Mar 2016 00:48:27 +0000 (16:48 -0800)]
A warning for the portability headers
Summary: [Folly] A warning for the `portability` headers.
Reviewed By: mzlee, Orvid, meyering
Differential Revision:
D3014442
fb-gh-sync-id:
f6557d8021dc2a50a656685492d717fdbff1124a
shipit-source-id:
f6557d8021dc2a50a656685492d717fdbff1124a
Michael Lee [Sat, 5 Mar 2016 00:06:40 +0000 (16:06 -0800)]
Switch from tmpdir to TemporaryDirectory
Summary: tmpdir does not work on all platforms. TemporaryDirectory is more robust.
Reviewed By: yfeldblum
Differential Revision:
D3013866
fb-gh-sync-id:
51e2b7ec2348eb95b99c125a27bb2aca2b87ac21
shipit-source-id:
51e2b7ec2348eb95b99c125a27bb2aca2b87ac21
Christopher Dykes [Fri, 4 Mar 2016 23:43:26 +0000 (15:43 -0800)]
Create the sys/types.h portability header
Summary: Windows has it, but it doesn't define pid_t. It also doesn't define ssize_t, and it's not worth a separate header for a single typedef, so define it here as well.
Reviewed By: yfeldblum
Differential Revision:
D3001168
fb-gh-sync-id:
3722270181c200bbcf39043960f81609c854b132
shipit-source-id:
3722270181c200bbcf39043960f81609c854b132
Max Warsewa [Fri, 4 Mar 2016 22:32:48 +0000 (14:32 -0800)]
Fix clang build for MicroLock
Summary: clang would complain about losing integer precision. Use unsigned for offset calculation.
Reviewed By: luciang
Differential Revision:
D3011253
fb-gh-sync-id:
10cb603708a22bf0e57f41b2486ffca4f5bf7a14
shipit-source-id:
10cb603708a22bf0e57f41b2486ffca4f5bf7a14
Kyle Nekritz [Fri, 4 Mar 2016 22:28:22 +0000 (14:28 -0800)]
Add replay safety method and callback to AsyncTransport.
Summary: This allows the transport to signal to a higher layer when it has become replay-safe.
Reviewed By: siyengar
Differential Revision:
D2974057
fb-gh-sync-id:
436f0c66b78f72ad34cdf4fe117771ea96b4388b
shipit-source-id:
436f0c66b78f72ad34cdf4fe117771ea96b4388b
Michael Lee [Fri, 4 Mar 2016 21:01:27 +0000 (13:01 -0800)]
Make the test portable for different libc
Summary:The class name for std::runtime_erorr is sometimes
St13runtime_error instead. And there is simlar mapping for other
classes.
Reviewed By: yfeldblum
Differential Revision:
D3013228
fb-gh-sync-id:
6a162de348eeaa51c059f9619e25ecf051615bfc
shipit-source-id:
6a162de348eeaa51c059f9619e25ecf051615bfc
Yang Chi [Fri, 4 Mar 2016 16:54:08 +0000 (08:54 -0800)]
fix liger contbuild: cast offset_bytes to unsigned
Summary: Apparently I don't know what I'm doing. But given lock_ is 8bit and the assert, I suppose cast offset_bytes to unsigned is safe.
Reviewed By: dcolascione
Differential Revision:
D3010732
fb-gh-sync-id:
1f3440a72d2f0b2fb145ab36966f0382a3009e0c
shipit-source-id:
1f3440a72d2f0b2fb145ab36966f0382a3009e0c
Yang Chi [Fri, 4 Mar 2016 03:47:53 +0000 (19:47 -0800)]
Remove persistentCork in native land
Summary: Remove persistent cork
Reviewed By: francis-ma
Differential Revision:
D3008550
fb-gh-sync-id:
a5ce492876d98d74f5669c5ec5ff3486c0cb0b2c
shipit-source-id:
a5ce492876d98d74f5669c5ec5ff3486c0cb0b2c
Den Raskovalov [Fri, 4 Mar 2016 01:34:39 +0000 (17:34 -0800)]
Add a missed glog header.
Summary: Instructions.h depends on glog/logging.h because of DCHECK_GT macros.
Reviewed By: ot
Differential Revision:
D3009084
fb-gh-sync-id:
05012e635a8c623ca1e653cc41a460778942c39e
shipit-source-id:
05012e635a8c623ca1e653cc41a460778942c39e
Daniel Colascione [Fri, 4 Mar 2016 00:33:07 +0000 (16:33 -0800)]
Add MicroLock as an alternative to MicroSpinLock
Summary:MicroLock is a full-featured lock that fills the niche that
MicroSpinLock and PicoSpinLock currently inhabit. Unlike these two
classes, MicroLock is a sleeping lock. MicroLock requires two bits of
a single word and has no particular alignment requirements.
Reviewed By: ot
Differential Revision:
D3004474
fb-gh-sync-id:
a9bd28bd3f48e894d5bff407612ee4b228466209
shipit-source-id:
a9bd28bd3f48e894d5bff407612ee4b228466209
Michael Lee [Thu, 3 Mar 2016 23:51:18 +0000 (15:51 -0800)]
Have internal tests use folly::Random instead of rand_r
Summary: rand_r is not provided on all platforms, so use `folly::Random` instead.
Reviewed By: yfeldblum
Differential Revision:
D3000351
fb-gh-sync-id:
45df3e1957c4b529ab2d2cb4db13b71d13dcef5d
shipit-source-id:
45df3e1957c4b529ab2d2cb4db13b71d13dcef5d
Marcelo Juchem [Thu, 3 Mar 2016 21:48:36 +0000 (13:48 -0800)]
Adding DynamicConverter support for enums
Summary:DynamicConverter doesn't currently support reading enums.
This diff addresses that by adding an enum specialization that uses integers as its underlying implementation.
A follow-up is to handle both integers and strings, but that would require a way to parse strings into enums like Thrift static reflection provides (see https://github.com/facebook/fbthrift/blob/
d17b072daddbd318f9afaa5562100eaba0f890e3/thrift/lib/cpp2/fatal/folly_dynamic-inl.h#L88,L92.
Reviewed By: yfeldblum
Differential Revision:
D3002569
fb-gh-sync-id:
27bf4a9d5a7844762f5311e2c777606a0e7753f0
shipit-source-id:
27bf4a9d5a7844762f5311e2c777606a0e7753f0
Michael Lee [Thu, 3 Mar 2016 21:14:30 +0000 (13:14 -0800)]
Fix printing of uint64_t in ConvTest
Summary:uint64_t is an unsigned long for 64-bit, but a long long int
for 32-bit. `%lu` can cause truncation in certain implementations of
libc.
Reviewed By: ngoyal
Differential Revision:
D3007568
fb-gh-sync-id:
bbb1896c9727cbff413ac73ff0caa12bae5d8a6a
shipit-source-id:
bbb1896c9727cbff413ac73ff0caa12bae5d8a6a
Neel Goyal [Thu, 3 Mar 2016 20:29:48 +0000 (12:29 -0800)]
Add service identity to SSL socket and use in ticket cache
Summary:Allow applications to specify a service identity tied to an SSLSocket
that can be used as a ticket cache key.
Further, add the cache key to the SSL_SESSION object and serialize it.
Reviewed By: siyengar
Differential Revision:
D2991005
fb-gh-sync-id:
25a5ddbb66bd9da2084159136cbe4d55b9e00f28
shipit-source-id:
25a5ddbb66bd9da2084159136cbe4d55b9e00f28
Kyle Nekritz [Thu, 3 Mar 2016 18:33:19 +0000 (10:33 -0800)]
Use false start with ALPN.
Summary: All the work we do in SSLContext to check the cipher and NPN usage is actually completely unnecessary since OpenSSL internally checks the cipher and use of ALPN/NPN after you set the SSL_MODE option (see `ssl3_can_cutthrough()` in ssl_lib.c). This just sets the option on the SSLContext instead.
Reviewed By: siyengar
Differential Revision:
D3002063
fb-gh-sync-id:
4514faf9ed2eb42a6e41d9e682b2c8aa52c46691
shipit-source-id:
4514faf9ed2eb42a6e41d9e682b2c8aa52c46691
Kyle Nekritz [Thu, 3 Mar 2016 16:51:53 +0000 (08:51 -0800)]
Fix AsyncSSLSocket handshake error reporting.
Summary:https://www.openssl.org/docs/manmaster/ssl/SSL_get_error.html
OpenSSL errors are a pain to deal with and we were handling several cases
incorrectly, resulting in a ton of "DH lib" errors when none were likely
actually DH lib errors.
Reviewed By: siyengar
Differential Revision:
D2999084
fb-gh-sync-id:
b3182be2c199f79ed341af7dbf7524197a838584
shipit-source-id:
b3182be2c199f79ed341af7dbf7524197a838584
Christopher Dykes [Wed, 2 Mar 2016 21:41:41 +0000 (13:41 -0800)]
Create the strings.h portability header
Summary: Windows doesn't have it.
Reviewed By: yfeldblum
Differential Revision:
D2990219
fb-gh-sync-id:
e9fe96905ec415874f0e2732b0685f3e7ad5d018
shipit-source-id:
e9fe96905ec415874f0e2732b0685f3e7ad5d018
Michael Lee [Wed, 2 Mar 2016 16:28:19 +0000 (08:28 -0800)]
Android does not always provide posix_memalign
Summary: We could provide `posix_memalign` instead as part of portability, but I am not sure how to tell whether or not it will be available.
Reviewed By: yfeldblum
Differential Revision:
D2991432
fb-gh-sync-id:
587314d43779f3b8fead2c41ed05016e6350f2ee
shipit-source-id:
587314d43779f3b8fead2c41ed05016e6350f2ee
Daniel Colascione [Wed, 2 Mar 2016 03:48:45 +0000 (19:48 -0800)]
Improve RWSpinLock.h cautionary comment
Reviewed By: yfeldblum
Differential Revision:
D2998122
fb-gh-sync-id:
a113ba1a474da8a46052091acadb90c95d3c0c28
shipit-source-id:
a113ba1a474da8a46052091acadb90c95d3c0c28
Michael Lee [Wed, 2 Mar 2016 01:32:43 +0000 (17:32 -0800)]
i386 -fPIC requires `%ebx`
Summary:On i368 (until, I'm lead to believe i686) `%ebx` is used for the PIC register. Thus, when we use cpuid, we clobber that register and gcc loudly complains:
folly/CpuId.h: In member function 'virtual void CpuId_Simple_Test::TestBody()':
folly/CpuId.h:67:61: error: PIC register clobbered by 'ebx' in 'asm'
__asm__("cpuid" : "=a"(n) : "a"(0) : "ebx", "edx", "ecx");
Reviewed By: yfeldblum
Differential Revision:
D2991229
fb-gh-sync-id:
ee8795e36a4c173147d61e26c9590ec5da1d02b5
shipit-source-id:
ee8795e36a4c173147d61e26c9590ec5da1d02b5
Christopher Dykes [Wed, 2 Mar 2016 00:10:58 +0000 (16:10 -0800)]
Create the portability header for time.h
Summary: Although MSVC does have time.h, and does have equivelents of these functions, those have slightly different semantics so we have to wrap them.
Reviewed By: yfeldblum
Differential Revision:
D2983613
fb-gh-sync-id:
676cd524ffa834a4250a2acc76aa1200eefe62cc
shipit-source-id:
676cd524ffa834a4250a2acc76aa1200eefe62cc
Daniel Colascione [Tue, 1 Mar 2016 22:57:44 +0000 (14:57 -0800)]
Stern warning about spinlocks
Summary: Spinlocks are a bad idea most of the time.
Reviewed By: rickbrew
Differential Revision:
D2996558
fb-gh-sync-id:
e86f1f0a084bda0c16759e979201db2e18102555
shipit-source-id:
e86f1f0a084bda0c16759e979201db2e18102555
Michael Lee [Tue, 1 Mar 2016 20:09:28 +0000 (12:09 -0800)]
Enclose global variables in an anonymous namespace.
Summary: This causes a symbol collision tests are compiled into a library.
Differential Revision:
D2991357
fb-gh-sync-id:
912be0df42216004a07213d62b68ff3f4713beb0
shipit-source-id:
912be0df42216004a07213d62b68ff3f4713beb0
Christopher Dykes [Tue, 1 Mar 2016 18:01:25 +0000 (10:01 -0800)]
Listen to the Windows docs in portability/SysTime.cpp
Summary:As-per the documenation of FILETIME:
"Do not cast a pointer to a FILETIME structure to either a ULARGE_INTEGER* or __int64* value because it can cause alignment faults on 64-bit Windows."
Reviewed By: yfeldblum
Differential Revision:
D2989434
fb-gh-sync-id:
cf57d569a785e0eb7225b346730bf2ed4c50dc55
shipit-source-id:
cf57d569a785e0eb7225b346730bf2ed4c50dc55
Christopher Dykes [Tue, 1 Mar 2016 17:59:36 +0000 (09:59 -0800)]
Add timeradd and timersub to the sys/time.h portability header
Summary: I missed these in my initial diff.
Reviewed By: yfeldblum
Differential Revision:
D2989977
fb-gh-sync-id:
0efb92286a8aed91ec1d394572cd709e5b6b37ab
shipit-source-id:
0efb92286a8aed91ec1d394572cd709e5b6b37ab
Dave Watson [Tue, 1 Mar 2016 17:52:58 +0000 (09:52 -0800)]
Fix narenas size
Summary:Changed from size_t to unsigned in a recent tp2 update
https://github.com/jemalloc/jemalloc/blame/
3c07f803aa282598451eb0664cc94717b769a5e6/test/unit/mallctl.c
Reviewed By: jasone, mhlakhani
Differential Revision:
D2991755
fb-gh-sync-id:
46f2be722a30706333eac6428f4183ca9cb85543
shipit-source-id:
46f2be722a30706333eac6428f4183ca9cb85543
Michael Lee [Tue, 1 Mar 2016 15:51:30 +0000 (07:51 -0800)]
to_string is not supported everywhere
Summary: Also remove an extra `#include <strstream>` from JsonTest.cpp as it is no longer necessary.
Reviewed By: yfeldblum
Differential Revision:
D2991381
fb-gh-sync-id:
386b8281726d034933ebdc26733dd35dc5ace949
shipit-source-id:
386b8281726d034933ebdc26733dd35dc5ace949
Michael Lee [Tue, 1 Mar 2016 15:48:18 +0000 (07:48 -0800)]
Remove unecessary int main from MemoryTest
Summary: We do not need this main function, so remove it.
Reviewed By: markisaa
Differential Revision:
D2992000
fb-gh-sync-id:
30bc0734af0f61e047276dab9639ae29cc999bbb
shipit-source-id:
30bc0734af0f61e047276dab9639ae29cc999bbb
Subodh Iyengar [Tue, 1 Mar 2016 03:38:32 +0000 (19:38 -0800)]
Add conversion constructors for Future
Summary:previously we were not able to do
Future<Base> f = makeFuture<Derived>();
This is because Future did not declare a conversion
constructor.
Adding a proper conversion ctor for Future is very
tricky because of the way Core is managed under the hood.
Core is not movable, and cannot be moved otherwise we
would have to retain pointers to the Future and Promises which
pointed to a particular core. This would be inefficient.
Instead we compromise and allow a very small subset of conversions
from objects whose templated types are convertible and also the
sizes of their Cores are also the same. As a result, we can
convert between types like unique_ptrs however not always between
full objects.
Reviewed By: jsedgwick
Differential Revision:
D2943775
fb-gh-sync-id:
7c2388f2fb49d789c80ae2477814e960a099771b
shipit-source-id:
7c2388f2fb49d789c80ae2477814e960a099771b
Pavlo Kushnir [Mon, 29 Feb 2016 20:02:27 +0000 (12:02 -0800)]
Fix SingletonThreadLocal
Summary: it's really thread local at this point :)
Reviewed By: jmswen
Differential Revision:
D2989668
fb-gh-sync-id:
423b9214922c92318181a62c583f58cd204b52e3
shipit-source-id:
423b9214922c92318181a62c583f58cd204b52e3
Scott Wolchok [Sat, 27 Feb 2016 20:39:23 +0000 (12:39 -0800)]
Use yield, not wfe, for asm_volatile_pause on ARM and ARM64
Summary:Found this hunting down LockFreeRingBuffer iOS perf problems. `wfe` and `yield` are similar, but `yield` is the instruction meant for "hey, I'm doing a spinlock", whereas `wfe` tries to wait for certain processor events. See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204j/Cjafcggi.html
Conveniently, it's the same instruction on 32-bit and 64-bit ARM.
Reviewed By: yfeldblum
Differential Revision:
D2986160
fb-gh-sync-id:
34671256112e605bf857f9db54a56cf6bb6f1ee2
shipit-source-id:
34671256112e605bf857f9db54a56cf6bb6f1ee2
Andrii Grynenko [Fri, 26 Feb 2016 18:28:31 +0000 (10:28 -0800)]
Fix folly::ThreadLocal to have unique singleton in dev builds
Summary:This re-uses StaticSingletonManager which was previously used to fix the same issue in folly::Singleton.
Because of the same issue we can no longer use static thread_local for the ThreadEntry. We now rely on pthread_getspecific/pthread_setspecific instead and use static thread_local ThreadEntry* only as a cache (to improve perf).
Reviewed By: yfeldblum
Differential Revision:
D2978526
fb-gh-sync-id:
cf1d9044afc27b62bd50a1ed931c0c420ae7107e
shipit-source-id:
cf1d9044afc27b62bd50a1ed931c0c420ae7107e
Christopher Dykes [Fri, 26 Feb 2016 17:28:51 +0000 (09:28 -0800)]
Create the sys/time.h portability header
Summary: Windows doesn't have it.
Reviewed By: yfeldblum
Differential Revision:
D2979215
fb-gh-sync-id:
030bdcaa44deb18834903705a26369ce0b13abc6
shipit-source-id:
030bdcaa44deb18834903705a26369ce0b13abc6
Michael Lee [Thu, 25 Feb 2016 22:58:16 +0000 (14:58 -0800)]
Split tests into test and benchmarks.
Summary:Split up
io/test/IOBufCursorTest
test/BitsTest
test/CacheLocalityTest
test/CallOnceTest
test/ConvTest
test/LoggingTest
test/MemoryIdlerTest
test/RandomTest
test/ThreadLocalTest
Reviewed By: yfeldblum
Differential Revision:
D2973132
fb-gh-sync-id:
9dadbdf49a31e82c3a2e34c2fdb6a2b47aa0928d
shipit-source-id:
9dadbdf49a31e82c3a2e34c2fdb6a2b47aa0928d
Michael Lee [Thu, 25 Feb 2016 21:51:28 +0000 (13:51 -0800)]
Split FileTest to a smaller test and an extended test
Summary: FileTest pulls in subprocess and does a lot more than just directly test File.h
Reviewed By: yfeldblum
Differential Revision:
D2971641
fb-gh-sync-id:
16e1096ab3b0f6434a26f84c889ebb082ee3f210
shipit-source-id:
16e1096ab3b0f6434a26f84c889ebb082ee3f210
Christopher Dykes [Thu, 25 Feb 2016 17:41:35 +0000 (09:41 -0800)]
Create a portability header for working with environment variables
Summary:Because `extern char** environ` is not the correct way to access environ on Windows.
This also implements setenv and unsetenv for Windows, which means that TestUtils no longer needs to be disabled for the Windows build.
Reviewed By: mzlee
Differential Revision:
D2973704
fb-gh-sync-id:
84db7db3494cf183fcbcc25063cb0482ef84ebf4
shipit-source-id:
84db7db3494cf183fcbcc25063cb0482ef84ebf4
Nathan Bronson [Thu, 25 Feb 2016 04:28:37 +0000 (20:28 -0800)]
shorten SharedMutex tests that timeout under ASAN
Summary:New ASAN options are more thorough but slower, resulting
in timeouts for some tests. Decreasing their internal loop count to
compensate.
Reviewed By: yfeldblum
Differential Revision:
D2973982
fb-gh-sync-id:
67391936d0b4930f99d00358ebb93a1b3ee87140
shipit-source-id:
67391936d0b4930f99d00358ebb93a1b3ee87140
Jonathan Kron [Thu, 25 Feb 2016 02:36:30 +0000 (18:36 -0800)]
Fixing AtomicHashArrayTest ASan Test Failure
Summary: Both of these tests will unavoidably fail on ASan because of shared library loads, and indestructable objects. Disabling ASAN testing for these test files.
Reviewed By: yfeldblum
Differential Revision:
D2968169
fb-gh-sync-id:
d2acc71b40541af5e10f15d5087a7c07da05453d
shipit-source-id:
d2acc71b40541af5e10f15d5087a7c07da05453d
Christopher Dykes [Thu, 25 Feb 2016 00:29:40 +0000 (16:29 -0800)]
Minor MSVC issues
Summary:MSVC doesn't let you have unicode characters in a narrow string without using a utf-8 literal string.
AsyncTransport needs the definition of IOBuf because of how the standard library implements a few things.
And longs are only 32-bit under Windows.
Reviewed By: yfeldblum
Differential Revision:
D2973973
fb-gh-sync-id:
c2f3e848e740a65c575598991d43dd79360ec1e3
shipit-source-id:
c2f3e848e740a65c575598991d43dd79360ec1e3
Orvid King [Thu, 25 Feb 2016 00:28:14 +0000 (16:28 -0800)]
Explicit vtordisp for MSVC
Summary:Because sometimes things are just different.
MSVC warns about the `dynamic_cast` done against this class because the class's declaration doesn't show that it would need a vtordisp. While I don't believe the `dynamic_cast` in question is actually called in either the constructor or destructor paths for the class, better to be safe and force the disp to be created.
Reviewed By: yfeldblum
Differential Revision:
D2887490
Pulled By: Orvid
fb-gh-sync-id:
821a6fc820087ac7120fffd9f8b95a26c2b4e71b
shipit-source-id:
821a6fc820087ac7120fffd9f8b95a26c2b4e71b
Sven Over [Wed, 24 Feb 2016 07:46:14 +0000 (23:46 -0800)]
folly/futures: keep Core alive until callback has returned
Summary:Callbacks passed to e.g. folly::Future::then (or
folly::Future::ensure) may delete the promise that keeps the
Core of the same future alive. The Core must protect itself from
destruction during callback execution.
This commit also adds a unit test to check for correct behaviour
in the "self destruction" scenario. The test should usually pass
even without the fix in Core.h. However, when you run the test
in Valgrind or ASAN, it will report problems unless the fix in
Core.h is applied.
Reviewed By: mhx
Differential Revision:
D2938094
fb-gh-sync-id:
22796e168e1876ef2e3c7d7619da020be6a22073
shipit-source-id:
22796e168e1876ef2e3c7d7619da020be6a22073
Andrii Grynenko [Wed, 24 Feb 2016 03:49:07 +0000 (19:49 -0800)]
Fix double definition for templated folly::Singletons
Summary: Allow createGlobal() to create dependent objects.
Reviewed By: yfeldblum
Differential Revision:
D2963111
fb-gh-sync-id:
8e4da48a7a1000934963396b423e8eff98a8aade
shipit-source-id:
8e4da48a7a1000934963396b423e8eff98a8aade
Yedidya Feldblum [Wed, 24 Feb 2016 00:35:17 +0000 (16:35 -0800)]
Fix Build: folly/test/IndestructibleTest.cpp under LSAN
Summary:[Folly] Fix Build: `folly/test/IndestructibleTest.cpp` under LSAN.
Leaks of Meyers singletons are ignored automatically, while normal locals are not. So we make our instances be Meyers singletons.
Differential Revision:
D2968368
fb-gh-sync-id:
385ac4491d9a105885af82d85354af929d69cc80
shipit-source-id:
385ac4491d9a105885af82d85354af929d69cc80
Andrii Grynenko [Tue, 23 Feb 2016 22:56:29 +0000 (14:56 -0800)]
Fix SIOF in folly/io/async/Request.cpp
Summary: Use Meyers singleton instead.
Reviewed By: afrind
Differential Revision:
D2963282
fb-gh-sync-id:
7aec36e7cc3b0ab09b2b093202f40d5b0d399f4d
shipit-source-id:
7aec36e7cc3b0ab09b2b093202f40d5b0d399f4d
Beny Luo [Tue, 23 Feb 2016 17:44:14 +0000 (09:44 -0800)]
AsyncSocketException: add detailed information in error message
Summary: AsyncSocketException: add detailed information in error message
Reviewed By: yfeldblum
Differential Revision:
D2953030
fb-gh-sync-id:
a5e26036657ecc6c74ad0369650730a2af13bead
shipit-source-id:
a5e26036657ecc6c74ad0369650730a2af13bead
Michael Lee [Tue, 23 Feb 2016 16:00:49 +0000 (08:00 -0800)]
Split benchmarks and tests
Summary:Benchmarks need their own main function, which means they
aren't really useful in cases we can't use a custom main function.
Reviewed By: yfeldblum
Differential Revision:
D2962104
fb-gh-sync-id:
25bdc6e5a8bdf8c3aa94d393207a74797b2e1234
shipit-source-id:
25bdc6e5a8bdf8c3aa94d393207a74797b2e1234
Lucian Grijincu [Tue, 23 Feb 2016 09:50:18 +0000 (01:50 -0800)]
folly: symbolizer: dwarf: don't fallback to linear scan if address missing from .debug_aranges
Summary:Presence of .debug_aranges implies user expects fast address lookup.
Some addresses might not be avaialble in .debug_aranges.
Don't do slow lookup in .debug_info, as it can lead to unexpected slowdowns.
override-unit-failures
Reviewed By: philippv
Differential Revision:
D2965323
fb-gh-sync-id:
405daefd57cdff4344fd231c5f5b7ff4dcd9df8c
shipit-source-id:
405daefd57cdff4344fd231c5f5b7ff4dcd9df8c
Neel Goyal [Mon, 22 Feb 2016 22:42:49 +0000 (14:42 -0800)]
Fix OSX build
Summary: Fixed the build using the homebrew instructions
Reviewed By: yfeldblum
Differential Revision:
D2960409
fb-gh-sync-id:
218b879f26b3baab09676cac51787bf36d0b4bed
shipit-source-id:
218b879f26b3baab09676cac51787bf36d0b4bed
Nathan Bronson [Mon, 22 Feb 2016 21:08:30 +0000 (13:08 -0800)]
fix SIOF in CacheLocality.h's AccessSpreader
Summary:This diff moves all data accessed during
AccessSpreader<>::current(x) into the .data segment, avoiding SIOF
without adding indirection or dynamic gating as would be the case for
normal singleton-like constructs. The diff also trims the AccessSpreader
API to include only those methods that people actually seem to use.
Reviewed By: djwatson
Differential Revision:
D2945205
fb-gh-sync-id:
847e31adc4450217f4ed0575686be261fb504d7c
shipit-source-id:
847e31adc4450217f4ed0575686be261fb504d7c
Michael Lee [Mon, 22 Feb 2016 16:42:18 +0000 (08:42 -0800)]
Remove extra `int main`s from unit tests.
Summary: test/common/TestMain.cpp should provide the necessary initialization.
Reviewed By: yfeldblum
Differential Revision:
D2947245
fb-gh-sync-id:
75b9d241673667badf4dc8fb81285c60cbb8166a
shipit-source-id:
75b9d241673667badf4dc8fb81285c60cbb8166a
Andrii Grynenko [Sat, 20 Feb 2016 09:08:28 +0000 (01:08 -0800)]
Move RequestContext::getStaticContext to .cpp
Summary: All singleton registration has to happen in .cpp. Otherwise singleton may be double registered if inlined.
Reviewed By: yfeldblum
Differential Revision:
D2956951
fb-gh-sync-id:
bea425c31270d614f4b8a780204694168602fe86
shipit-source-id:
bea425c31270d614f4b8a780204694168602fe86
Andrii Grynenko [Sat, 20 Feb 2016 00:13:42 +0000 (16:13 -0800)]
Support nested FiberManagers
Summary:It's possible to have nested loopUntilNoReady (with different FiberManagers). See unit test for a simple example.
This diff fixes currentFiberManager_ to be a stack.
Reviewed By: meyering
Differential Revision:
D2953468
fb-gh-sync-id:
0abdcb7f43c94e7bb0adef8440699dc8e138d21a
shipit-source-id:
0abdcb7f43c94e7bb0adef8440699dc8e138d21a
Andrii Grynenko [Fri, 19 Feb 2016 19:19:18 +0000 (11:19 -0800)]
Fix EventBaseOnDestructionCallback to loop FiberManager
Summary: EventBase loop should do it as well, but it's possible for LoopCallback to be removed before EventBaseOnDestructionCallback.
Reviewed By: pavlo-fb
Differential Revision:
D2951303
fb-gh-sync-id:
43f5a91e7ecffa7ab7feec32fa45e01b28db66a3
shipit-source-id:
43f5a91e7ecffa7ab7feec32fa45e01b28db66a3
Andrii Grynenko [Fri, 19 Feb 2016 19:02:35 +0000 (11:02 -0800)]
Fix folly::Singleton to work in dynamically linked binaries
Summary:This implements StaticSingletonManager which is then used to create all leaked Meyers singletons.
StaticSingletonManager is a singleton itself, which is created in a separate compilation unit (Singleton.cpp) and so we can be sure that other compilation units will always see a single instance of StaticSingletonManager, even if linked dynamically.
StaticSingletonManager then keeps a dictionary of typeid -> object pointer, which is used to de-duplicate same singleton being re-created from different compilation units (linked dynamically), usually because of code inlining.
override-unit-failures
Reviewed By: yfeldblum
Differential Revision:
D2913027
fb-gh-sync-id:
1f5015a79a7a8297ebf5f0fe3fd0cc7eb44f706b
shipit-source-id:
1f5015a79a7a8297ebf5f0fe3fd0cc7eb44f706b
Tianjiao Yin [Fri, 19 Feb 2016 18:40:46 +0000 (10:40 -0800)]
fix dangling pointer bug in IPAddressV6
Summary: `mask(numBits)` returns a temporary variable. After its lifetime ends, subbytes becomes a dangling pointer.
Reviewed By: yfeldblum
Differential Revision:
D2953699
fb-gh-sync-id:
5d5a35716ecaa1b3d96edb5a459615756848b92f
shipit-source-id:
5d5a35716ecaa1b3d96edb5a459615756848b92f
Yedidya Feldblum [Fri, 19 Feb 2016 07:10:20 +0000 (23:10 -0800)]
Indestructible
Summary:[Folly] `Indestructible`.
For when you need a Meyers singleton that will never be destructed, even at program exit.
Good for large data structures with many heap allocations, as long as they have no behavior. No point in ever destructing them.
HT: Proxygen, and Orvid.
Reviewed By: andriigrynenko
Differential Revision:
D2947959
fb-gh-sync-id:
7dd1f725edf137ba81fbf4032a0819fd7c627261
shipit-source-id:
7dd1f725edf137ba81fbf4032a0819fd7c627261
Lucian Grijincu [Fri, 19 Feb 2016 02:46:44 +0000 (18:46 -0800)]
folly: symbolizer: slow address->{file+line-number} lookup if `.debug_aranges` is missing (e.g. --strip-debug-non-line)
Summary:Binaries linked with `gold` and `--strip-debug-non-line` don't have an `.debug_aranges` section
We still want to map `address->{file+line-number}` to get nice stack
traces even though this might be slower (linear search all compilation unit entries in `.debug_info`).
Before:
```
$ # link with gold + --strip-debug-non-line
$ folly/experimental/exception_tracer/exception_tracer_test
E0217 15:02:13.694947
1321814 ExceptionTracer.cpp:179] Exception type: std::runtime_error (9 frames)
@
000000000040ad2d __cxa_throw
@
0000000000409df3 bar()
@
0000000000409eab baz()
@
0000000000407c77 main
@
00007f00dd9860f5 __libc_start_main
@
000000000040991b (unknown)
```
After (similar to the output without `--strip-debug-non-line`):
```
E0217 18:37:37.579596
1583124 ExceptionTracer.cpp:179] Exception type: std::runtime_error (9 frames)
@
000000000040ad6d __cxa_throw
./folly/experimental/exception_tracer/ExceptionTracerLib.cpp:57
@
0000000000409e33 bar()
./folly/experimental/exception_tracer/ExceptionTracerTest.cpp:24
@
0000000000409eeb baz()
./folly/experimental/exception_tracer/ExceptionTracerTest.cpp:51
@
0000000000407c87 main
./folly/experimental/exception_tracer/ExceptionTracerTest.cpp:96
@
00007f1d16ff80f5 __libc_start_main
@
000000000040995b (unknown)
```
Differential Revision:
D2947965
fb-gh-sync-id:
e517bab324b1dcb70cadc9a5211ce794e35c83a5
shipit-source-id:
e517bab324b1dcb70cadc9a5211ce794e35c83a5