Lucian Grijincu [Thu, 17 Nov 2016 19:06:36 +0000 (11:06 -0800)]
folly: ExceptionWrapper: remove <iostream> from header
Summary: #accept2ship
Reviewed By: yfeldblum
Differential Revision:
D4192095
fbshipit-source-id:
eb0cad875bcc24d1c87a99890c51aea31f7024c9
Christopher Dykes [Thu, 17 Nov 2016 03:20:16 +0000 (19:20 -0800)]
Add folly::getCurrentThreadID()
Summary: And also use it in a couple of tests, so that they can be compiled on Windows, where `pthread_t` is a struct rather than a pointer or integer.
Reviewed By: yfeldblum
Differential Revision:
D4191560
fbshipit-source-id:
5bcf0a2952109b2a9bc5220c4640d42e2cdf8977
Delyan Kratunov [Thu, 17 Nov 2016 00:48:47 +0000 (16:48 -0800)]
Remove unneeded iostream include
Summary:
Including `iostream` in a header causes anything that uses this header to gain
an extra static initializer for an `std::ios_base::Init` object.
If there are N translation units in a library that use the header, that's N
more static initializers that need to run.
Reviewed By: yfeldblum
Differential Revision:
D4191798
fbshipit-source-id:
65b47401b9177177999cff65a47ac8dffa0e0546
Christopher Dykes [Thu, 17 Nov 2016 00:41:51 +0000 (16:41 -0800)]
Adjust the Function::NonCopyableLambda test to use a large struct rather than a C Array
Summary:
Because MSVC doesn't like it when you attempt to explicitly capture a c-style array in a lambda capture list.
See: https://developercommunity.visualstudio.com/content/problem/2444/cannot-explicitly-capture-c-style-array-in-lambda.html
Reviewed By: yfeldblum
Differential Revision:
D4191400
fbshipit-source-id:
305f8086c29f079ccf2c322f20da6393235bc76d
Geert Van Laethem [Wed, 16 Nov 2016 22:50:58 +0000 (14:50 -0800)]
Broken link to gtest 1.7.0 zip replaced with correct one
Summary: Closes https://github.com/facebook/folly/pull/517
Reviewed By: igorsugak
Differential Revision:
D4191764
Pulled By: Orvid
fbshipit-source-id:
5ab921bd0df0b9dbaca46cdf9ecdeea9ecda6f5a
Christopher Dykes [Wed, 16 Nov 2016 22:50:29 +0000 (14:50 -0800)]
Disable the CArray RangeFunc tests under MSVC
Summary: Because it won't compile due to an MSVC bug. See the link in the comment for more info.
Reviewed By: yfeldblum
Differential Revision:
D4191233
fbshipit-source-id:
523deebe12379ff56934a4259b601d4ab677b9b6
Nathan Bronson [Wed, 16 Nov 2016 22:01:49 +0000 (14:01 -0800)]
folly: fbvector: ubsan: avoid memset(nullptr, 0, 0)
Summary:
Constructing an empty FBVector by length results in a call to
memset with a null destination, which is undefined behavior. This diff
fixes it.
Reviewed By: luciang, meyering, Gownta
Differential Revision:
D4191612
fbshipit-source-id:
3dcc091396fc33ac2230bd2d90906325131b0a3b
Christopher Dykes [Wed, 16 Nov 2016 21:20:32 +0000 (13:20 -0800)]
Mark a few constexpr locals in ThreadLocalTest as static
Summary:
Because, as discussed in past diffs, MSVC currently requires them to be static in order to resolve them from within the scope of a lambda when they aren't captured.
The only one that actually needs to be marked as `static` is `numReps`, but I like consistency, so I marked them all as static.
Reviewed By: yfeldblum
Differential Revision:
D4191610
fbshipit-source-id:
7246170f30551d2079b4373eefbf3d02aab6dfa9
Christopher Dykes [Wed, 16 Nov 2016 21:19:59 +0000 (13:19 -0800)]
Hint that the port is numeric when binding an AsyncServerSocket
Summary: Because it had better be numeric or something is very wrong.
Reviewed By: yfeldblum
Differential Revision:
D4190568
fbshipit-source-id:
52a5ebfcedb545201191fc48f66a4419eee8f748
Lucian Grijincu [Wed, 16 Nov 2016 04:24:38 +0000 (20:24 -0800)]
folly: MemoryMapping: less verbose warning on TRY_LOCK+ENOMEM failures
Reviewed By: philippv
Differential Revision:
D4184097
fbshipit-source-id:
2f1f82b845528fea4667af612c92c348f8d9ec25
Christopher Dykes [Wed, 16 Nov 2016 02:46:23 +0000 (18:46 -0800)]
Qualify a field name in NotificationQueueTest
Summary: MSVC currently has a bug that causes it to incorrectly resolve it to `std::queue`: https://developercommunity.visualstudio.com/content/problem/2342/c-failure-to-resolve-instance-member-in-lambda-con.html
Reviewed By: lbrandy
Differential Revision:
D4187256
fbshipit-source-id:
207eafa339f7255ae881d8ab80f4847222c3b8c9
Christopher Dykes [Wed, 16 Nov 2016 01:30:09 +0000 (17:30 -0800)]
Don't assume standard library types are relocatable
Summary: Although currently the only one of these that isn't relocatable is `std::string`, making assumptions about the standard library is a terrible idea, so disable all of them.
Reviewed By: yfeldblum
Differential Revision:
D4186024
fbshipit-source-id:
4d2a54d232df0cb05959a8d9cb1a2d2cf34d1302
Andrii Grynenko [Tue, 15 Nov 2016 22:52:48 +0000 (14:52 -0800)]
Thread-safe version of loopKeepAlive()
Reviewed By: yfeldblum
Differential Revision:
D4152380
fbshipit-source-id:
8b3c6dc4b14b9138bb5012e05f50496e51c0fa4b
Christopher Dykes [Tue, 15 Nov 2016 19:38:18 +0000 (11:38 -0800)]
Mark FingerprintPolynomial.size() constexpr
Summary: Because it is, and so that MSVC doesn't complain about things in the fingerprint table generator.
Reviewed By: yfeldblum
Differential Revision:
D4178562
fbshipit-source-id:
8816f413bc100b42dd72f0e991aec8559b328e9b
Lucian Grijincu [Tue, 15 Nov 2016 04:39:13 +0000 (20:39 -0800)]
folly: MemoryMapping: isolate _MSC_VER-related changes
Summary: Cleaner to isolate the #ifdefs to a constant than different code based on platform.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4179949
fbshipit-source-id:
5b9975a78cf234f29a379c1dbe489373b7f1c253
Andrii Grynenko [Tue, 15 Nov 2016 02:13:02 +0000 (18:13 -0800)]
Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This is useful to add more TimeoutManager implementations.
Reviewed By: yfeldblum
Differential Revision:
D4178511
fbshipit-source-id:
9167cfe40e7487da1c35c537f9db8a2bdf085626
Andrii Grynenko [Tue, 15 Nov 2016 02:07:46 +0000 (18:07 -0800)]
Make Observer stress test pass a stress run
Reviewed By: yfeldblum
Differential Revision:
D4179908
fbshipit-source-id:
493b302cd7e9f7ebc851599b2ca5988af817387d
yizhiren [Tue, 15 Nov 2016 00:19:37 +0000 (16:19 -0800)]
correct the description about the thread to run
Summary:
exchange A and B in this sentence :
"Or, maybe x will execute in Thread B, but y and/or z will execute in Thread A".
I think x in B and y,z in A is impossible. but x in A and y,z in B is possible, in that example.
Closes https://github.com/facebook/folly/pull/514
Reviewed By: yfeldblum
Differential Revision:
D4176766
Pulled By: Orvid
fbshipit-source-id:
cf3a47a30d7e43e5291d6b6401198025beba33f8
Alejandro Peláez [Mon, 14 Nov 2016 00:19:32 +0000 (16:19 -0800)]
Revert
D4164236: [EventBase] Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This reverts commit
5f2057f6ebfbdc971bc0b5594e3bc4b5a337aaef
Differential Revision:
D4164236
fbshipit-source-id:
a397e6ba8c9d7a691cc6381b8f60bfcea3eb91b0
Subodh Iyengar [Sun, 13 Nov 2016 01:13:44 +0000 (17:13 -0800)]
Add ecdsa smart ptr
Summary: Add ecdsa smart ptr.
Reviewed By: knekritz
Differential Revision:
D4173310
fbshipit-source-id:
abd5f799b3414b70128635c4390af6f2de329e11
Andrii Grynenko [Sat, 12 Nov 2016 03:49:34 +0000 (19:49 -0800)]
Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This is useful to add more TimeoutManager implementations.
Reviewed By: yfeldblum
Differential Revision:
D4164236
fbshipit-source-id:
5f2057f6ebfbdc971bc0b5594e3bc4b5a337aaef
Marcin Pawlowski [Sat, 12 Nov 2016 02:37:38 +0000 (18:37 -0800)]
try to improve folly/io/async/test:async_test - AsyncSocketTest.Write
Summary:
the test fails a lot as seen on the task.
To kill the connection in said test, we depeneded
on destructor, however this uses a delayed destruction
patter so I guess we did not destroy on time and
we were failing the tests.
I close socket explicitly. No idea if this misses
the point of whole test.
Reviewed By: yfeldblum
Differential Revision:
D4171111
fbshipit-source-id:
01b8c97a04a2bcdfaeeea522ca8bcae343d6bb5d
Mirek Klimos [Sat, 12 Nov 2016 02:17:17 +0000 (18:17 -0800)]
Revert DLOG_INFO warnings about RequestContext being overriden
Summary: This is causing a log spew on some services, let's remove it until we figure out where the problem is and fix
Differential Revision:
D4171379
fbshipit-source-id:
2afdab6917a2498c376559f9171f6e93ab9c8ad7
Andrii Grynenko [Sat, 12 Nov 2016 02:12:11 +0000 (18:12 -0800)]
Make Observer.Stress test not fail under load
Reviewed By: marcinpe
Differential Revision:
D4171655
fbshipit-source-id:
e6ef33c50d5d91e05250520171c959a893470460
Martin Martin [Sat, 12 Nov 2016 00:08:46 +0000 (16:08 -0800)]
When you read from a default-constructed MPMCQueue, assert instead of SIGFPE.
Summary:
I accidentally forgot to specify the capacity for my
MPMCQueue. When I then did a blockingRead(), I got a SIGFPE. Thanks
to a custom signal handler that doesn't print stack traces, and a few
more comedy of errors, I lost a day to this. With this patch, I would
have gotten an assertion failure instead.
Reviewed By: yfeldblum
Differential Revision:
D4169033
fbshipit-source-id:
fab97ea0d5afc3c06885758b31a5e8c91ae75a45
Mirek Klimos [Fri, 11 Nov 2016 19:15:55 +0000 (11:15 -0800)]
Add warnings when overriding RequestContext
Summary: We currently store the previous value on creation of RequestContextScopeGuard and reset it to the previous one when it goes out of scope - this means that if it's not unset properly somewhere, we'll prolong its life by saving it and restoring later. We need to do this because of some edge cases but a RequestContext should generally never be overridden by a different RequestContext - let's add a warning if this happens
Reviewed By: djwatson, palmtenor
Differential Revision:
D3971904
fbshipit-source-id:
e72b5f01102d18977d8aa5f8dca5a7802545098a
Andrew Gallagher [Fri, 11 Nov 2016 06:44:43 +0000 (22:44 -0800)]
folly/test/SingletonTestStructs: move inlined function to impl file
Reviewed By: yfeldblum
Differential Revision:
D4162763
fbshipit-source-id:
25c9bfae2e7679f4b98a3d64ee9f2319eb6e7f4a
Yedidya Feldblum [Fri, 11 Nov 2016 06:02:17 +0000 (22:02 -0800)]
Let folly::range(const std::array<...>&) be constexpr
Summary:
[Folly] Let `folly::range(const std::array<...>&)` be `constexpr`.
This may be useful for future work.
Reviewed By: simpkins
Differential Revision:
D4165608
fbshipit-source-id:
8f1064c3cdc07301e198acd596ff26724d603cdd
Jim Meyering [Fri, 11 Nov 2016 00:50:45 +0000 (16:50 -0800)]
folly/Foreach.h: fix FOR_EACH_R and FOR_EACH_KV to avoid shadowing warnings
Summary:
Fix these macros not to self-shadow for nested uses.
How? Make each local variable name include __LINE__.
This works in most cases, but not all: if you put the
nested uses all on one line, you'll still get shadowing warnings.
Reviewed By: yfeldblum
Differential Revision:
D4161553
fbshipit-source-id:
9e11ae6778272c733a4c820cfb30c5db59998a5b
Christopher Dykes [Thu, 10 Nov 2016 20:46:19 +0000 (12:46 -0800)]
Always use inline-asm version on GCC/Clang
Summary:
Because the intrinsic version requires explicitly adding `__target__` attributes, which results in things not being inlined. Although the code generated with the `__target__` attribute is strictly better, ensuring it's applied on all the relevant functions is error-prone, so just use the inline assembly version for GCC/Clang so that it can be inlined elsewhere. MSVC will inline the intrinsic version without any issue.
This also marks the functions as `ALWAYS_INLINE`, as the diff that is getting reverted made that change as well.
Reviewed By: yfeldblum, philippv, ot
Differential Revision:
D3963935
fbshipit-source-id:
47175d64e7be351eb455a4d053b91ce9392bf152
Tudor Bosman [Thu, 10 Nov 2016 20:40:38 +0000 (12:40 -0800)]
Add include files necessary to use symbolizer
Summary:
Some include files are not installed, causing including symbolizer/Symbolizer.h to fail.
Closes https://github.com/facebook/folly/pull/512
Reviewed By: philippv
Differential Revision:
D4161113
Pulled By: luciang
fbshipit-source-id:
5a5f8577f8d84ba33f89073781d374b99ba37df6
Christopher Dykes [Thu, 10 Nov 2016 20:32:51 +0000 (12:32 -0800)]
Don't try to call _free_osfhnd when not compiling agains the static CRT
Summary:
Because, unfortunately, it isn't exported from the dynamic CRT dlls :(
There's not really a nice way to handle this when using the dynamic CRT without doing very fragile hocus-pocus that relies on the exact layout and implementation details of the file descriptor table in the CRT, so the best we can really do is close the socket and just let the file descriptor itself leak.
Reviewed By: yfeldblum
Differential Revision:
D4156558
fbshipit-source-id:
32cb4bf357f6746cf6597b66649ff9f018fb1bed
Phil Willoughby [Thu, 10 Nov 2016 12:09:21 +0000 (04:09 -0800)]
Use std::cerr for folly/Singleton.cpp error printing
Summary:
Create a local std::ios_base::Init instance to ensure that it is valid, then
use std::cerr.
Reviewed By: yfeldblum, nbronson
Differential Revision:
D4139681
fbshipit-source-id:
03377dd417710e320a6b53298d507fd0168592f6
Andrii Grynenko [Thu, 10 Nov 2016 04:19:57 +0000 (20:19 -0800)]
Fix wrong use of upgrade lock
Reviewed By: yfeldblum, nbronson
Differential Revision:
D4149681
fbshipit-source-id:
37bd1b0b7d1ad6e6fa813228307abebfe772012f
Christopher Dykes [Wed, 9 Nov 2016 23:13:35 +0000 (15:13 -0800)]
Don't try to install the failure signal handler in folly::init on Windows
Summary: Because GTest doesn't support it on platforms that don't implement `sigaction`.
Reviewed By: yfeldblum
Differential Revision:
D4155882
fbshipit-source-id:
fe8df316242b293afaf94c2a5d0f8a5e60b51285
Christopher Dykes [Wed, 9 Nov 2016 23:13:25 +0000 (15:13 -0800)]
Disable a couple of warnings generated by the GTest and GMock headers
Summary: As the comment says, this disables a couple of warnings related to exporting classes derived from stdlib classes that aren't explicitly exported.
Reviewed By: yfeldblum
Differential Revision:
D4155978
fbshipit-source-id:
6e732b53c280a3bc3a39b2128cd577ba7cb70408
Christopher Dykes [Wed, 9 Nov 2016 22:35:17 +0000 (14:35 -0800)]
Don't generate empty statements in DeterministicScheduleTest
Summary: Because MSVC generates warnings if you have a control-flow statement followed by a single trailing semicolon.
Reviewed By: yfeldblum
Differential Revision:
D4155588
fbshipit-source-id:
dfd8774fc6a62675764f7e069c26b799b622a9af
Christopher Dykes [Wed, 9 Nov 2016 22:31:44 +0000 (14:31 -0800)]
Request lower privilege crypt context when generating random numbers
Summary: Without this flag, we were unintentionally requesting a context with access to private keys.
Reviewed By: yfeldblum
Differential Revision:
D4155525
fbshipit-source-id:
f33d18451b06e32b81d03bf6180efc1671cfa204
Christopher Dykes [Wed, 9 Nov 2016 19:20:55 +0000 (11:20 -0800)]
Use ASSERT_EQ rather than CHECK_EQ in the socket tests
Summary: Because `CHECK_EQ` is a fatal error, and makes it impossible to keep running the other tests if it fails, even if it was just a timeout.
Reviewed By: yfeldblum
Differential Revision:
D4151084
fbshipit-source-id:
db88dc2ef875e5d1fe31792f26a3dc2d223ded5e
Christopher Dykes [Wed, 9 Nov 2016 19:07:51 +0000 (11:07 -0800)]
Split the benchmarks out of UriTest
Summary: So that they can be run independently of the tests.
Reviewed By: yfeldblum
Differential Revision:
D4150331
fbshipit-source-id:
3ab39024795add84885436b757f2505527297a3d
Christopher Dykes [Wed, 9 Nov 2016 19:07:23 +0000 (11:07 -0800)]
Return the correct resolution for clock_getres
Summary: When the implementation of `clock_gettime` for `REALTIME` and `MONOTONIC` was switched to use `std::chrono`, this didn't get switched over to the resolution of the new implementation.
Reviewed By: yfeldblum
Differential Revision:
D4150297
fbshipit-source-id:
a4578af85cae538a3ebb6da7e759058927c31d3e
Ali Zaveri [Wed, 9 Nov 2016 08:29:32 +0000 (00:29 -0800)]
Expose isFamilyInet() to check if SocketAddress is a valid ipv4 or ipv6
Summary: Expose isFamilyInet() in SocketAddress. This cleans up code and provides a way to validate if SocketAddress is a ipv4 or ipv6
Differential Revision:
D4150650
fbshipit-source-id:
dc8883e904b6577fc27bdd54064fcc50de93b0d2
Christopher Dykes [Tue, 8 Nov 2016 18:40:14 +0000 (10:40 -0800)]
Make NeedleFinderTest::Needles256 actually do things
Summary:
The min value of a `char` is `-128`, but we're initializing our `size_t` i's with it, so, as MSVC quite rightly warns (as C6294) the condition is never true and the loop never loops.
Fix it by signing our i's.
Reviewed By: yfeldblum
Differential Revision:
D4145419
fbshipit-source-id:
87591d0f84c54472b1b5847e025d091de3f98bca
James Sedgwick [Tue, 8 Nov 2016 07:13:30 +0000 (23:13 -0800)]
add tryReadUntil and make fixes along the way
Summary:
this diff adds tryReadUntil, which is a mirror of tryWriteUntil in both function and implementation.
Two bugs were exposed in the process of implementing and testing tryWriteUntil; they are fixed as well and are as follows:
1. tryObtainPromisedPopTicket didn't assign to the passed ticket return reference in the failure case
2. TurnSequencer::tryWaitForTurn() didn't distinguish between past turns and timeouts in the failure case; they need to be
differentiated because SingleElementQueue::tryWaitFor{De/En}queue() should only fail in the timeout case, not if the turn has passed.
The two added unit tests are admittedly clumsy, but making the obvious simplifications to them keeps them from triggering the premature timeout race caused by bug 2 above, so I kept them as is.
Reviewed By: magedm
Differential Revision:
D4050515
fbshipit-source-id:
b0a3dd894d502c44be62d362ea347a1837df4c2f
Andrew Gallagher [Tue, 8 Nov 2016 00:10:41 +0000 (16:10 -0800)]
Mark implicitly inlined static locals with default visibility
Summary:
These functions contain static locals which need to be exported to
the global dynamic symbol table to get deduplicated at runtime. Since
using `-fvisibility-inlines-hidden` demotes the visibility of these
static locals, explicitly tag them.
Reviewed By: yfeldblum
Differential Revision:
D4139154
fbshipit-source-id:
08b81721c6c945ac5556472481ae771d0eeb5f88
Stepan Palamarchuk [Mon, 7 Nov 2016 20:37:52 +0000 (12:37 -0800)]
Remove noexcept from AsyncSocket::prepareReadBuffer
Summary:
`prepareReadBuffer` is calling a callback function that is not a noexcept
also `prepareReadBuffer` is being called only from one place, that wraps this function call with try/catch.
Reviewed By: jmswen
Differential Revision:
D4138424
fbshipit-source-id:
a05bdd6f741761567a7d0291017c285b0bf15522
Andrew Gallagher [Mon, 7 Nov 2016 04:06:46 +0000 (20:06 -0800)]
Annotate some static locals as "library-local"
Summary:
This tags certain static locals, wich may get duplicated via dynamic
linking and inlining, as safe to have multiple copies at runtime,
making this subtle behavior explicit.
Reviewed By: igorsugak
Differential Revision:
D4082929
fbshipit-source-id:
ba4e23cb121e957a43f5659a1ca3432cb89cb8f3
Yedidya Feldblum [Sun, 6 Nov 2016 21:09:44 +0000 (13:09 -0800)]
Let folly::range be constexpr
Summary:
[Folly] Let `folly::range` be `constexpr`.
It will be useful to have this helper function be `constexpr` to support further compile-time code.
Reviewed By: juchem
Differential Revision:
D4135943
fbshipit-source-id:
a62be93f9e492ca302130d1a3b190ed4b69f7a80
Christopher Small [Sat, 5 Nov 2016 19:36:36 +0000 (12:36 -0700)]
operator== for ReadMostlySharedPtr to nullptr_t
Summary: add operator== against nullptr_t for ReadMostlySharedPtr
Reviewed By: andriigrynenko, nbronson, yfeldblum
Differential Revision:
D4128722
fbshipit-source-id:
40d08bb85bfe2f96ad4ed4995f5829e0616d0661
Zach Amsden [Fri, 4 Nov 2016 19:59:59 +0000 (12:59 -0700)]
Add StringKeyedMap/Set.h to OSS build
Summary: Eden uses this and won't build with OSS folly without it.
Reviewed By: Orvid
Differential Revision:
D4132103
fbshipit-source-id:
68d6c7dc642a7401eca60b0713db9f90cc11ced1
Mirek Klimos [Fri, 4 Nov 2016 18:10:46 +0000 (11:10 -0700)]
Trying to improve the efficiency of RequestContext callbacks
Summary: Changed RWSpinLock to a SharedMutex in the RequestContext to see if this would lower the overhead of the onSet/onUnset callbacks.
Reviewed By: djwatson
Differential Revision:
D3780396
fbshipit-source-id:
3d91f8194357533072fe053d23e0454a36faecff
Kyle Nekritz [Thu, 3 Nov 2016 22:53:52 +0000 (15:53 -0700)]
Add splitAtMost to IOBufQueue.
Summary: This allows getting up to n bytes from the queue without first having to check the length.
Reviewed By: yfeldblum
Differential Revision:
D4083484
fbshipit-source-id:
2a468992c97f036c22f1a0d9f830e6d5286a4bc2
Kyle Nekritz [Thu, 3 Nov 2016 22:53:50 +0000 (15:53 -0700)]
Allow folly::io::Cursor to move backwards.
Summary: This is helpful for parsing data IOBufs in reverse.
Reviewed By: siyengar
Differential Revision:
D4082810
fbshipit-source-id:
6a201d25e7d22befe28f92e4a1d7aa41ad7d6817
Louis Brandy [Thu, 3 Nov 2016 17:35:18 +0000 (10:35 -0700)]
quiet -Wmaybe-uninitialized
Summary: gcc-4.9 doesn't appreciate this clever loop and worries about `prev` being uninitialized on first use. Assuming the rest of the program behaves properly and preserves the invariant this code is expecting, this isn't bugged. But let's initialize it anyway.
Reviewed By: meyering
Differential Revision:
D4120746
fbshipit-source-id:
1a7c323a4b6296a81768a62dd7d72337c5c35bf0
Jim Meyering [Thu, 3 Nov 2016 02:02:20 +0000 (19:02 -0700)]
folly/test/RangeFindBenchmark.cpp: avoid shadowing warning: rename inner "n": s/\<n\>/c/
Reviewed By: yfeldblum
Differential Revision:
D4120553
fbshipit-source-id:
87c202232bcfabeff7eb62a8133b9b5577b09cbc
Jim Meyering [Thu, 3 Nov 2016 02:02:00 +0000 (19:02 -0700)]
folly/test/ThreadLocalBenchmark.cpp: avoid shadowing warning
Summary:
There was a doubly-nested loop, both with index "i".
Change the inner for-loop index from i to j.
Reviewed By: yfeldblum
Differential Revision:
D4120589
fbshipit-source-id:
c786d8f7bb1ee05fc990db898b15836032e93940
Jim Meyering [Thu, 3 Nov 2016 02:00:24 +0000 (19:00 -0700)]
folly/test/ExceptionWrapperBenchmark.cpp: avoid shadowing warnings
Reviewed By: jsedgwick
Differential Revision:
D4120563
fbshipit-source-id:
c97645a068662e41d5038bcd1e9805bdf6f0490c
Ameya Limaye [Thu, 3 Nov 2016 01:01:53 +0000 (18:01 -0700)]
Allow getting the sequence number of a token via a read only getter function
Summary: Allow getting the sequence number of a token via a read only getter function
Reviewed By: yfeldblum
Differential Revision:
D4120900
fbshipit-source-id:
b664dda29d13a1755e041ab9c33c0d7324690ba7
Andrii Grynenko [Thu, 3 Nov 2016 00:39:29 +0000 (17:39 -0700)]
Use loopKeepAlive() mechanism in FiberManager
Reviewed By: yfeldblum
Differential Revision:
D4086486
fbshipit-source-id:
bd0cca8dd2c9b74d5c30e4cd095191c1d1ecab79
Tudor Bosman [Wed, 2 Nov 2016 22:00:45 +0000 (15:00 -0700)]
Compile RangeSse42.cpp with -msse4.2
Summary:
Solves #509 by creating a libtool convenience library that's compiled with -msse4.2.
Closes https://github.com/facebook/folly/pull/510
Differential Revision:
D4120400
Pulled By: yfeldblum
fbshipit-source-id:
bf5d937dc37ef8707e755c89f1883d65b4d21b0f
Philip Pronin [Wed, 2 Nov 2016 04:24:55 +0000 (21:24 -0700)]
fix race between StaticMetaBase::destroy() and StaticMetaBase::onThreadExit()
Summary:
We would like to guarantee that after `folly::ThreadLocal<>` dtor
returns no per-thread instances are longer alive. Currently this is not a case:
* T1 is excuting `StaticMetaBase::onThreadExit()`, it acquired all per-thread
instances and erased them from meta under `accessAllThreadsLock_`.
* T2 destroys `folly::ThreadLocal<>`, it executes `StaticMetaBase::destroy()`,
collects all per-thread instances (thus missing the ones being destroyed by
T1), destroys them and returns.
* T1 executes dtor of per-thread instances, after parent `folly::ThreadLocal<>`
dtor is finished.
Reviewed By: ot
Differential Revision:
D4109820
fbshipit-source-id:
d547b8cc77c9871126538c38644c2e98ddccf220
Ameya Limaye [Wed, 2 Nov 2016 03:28:09 +0000 (20:28 -0700)]
Make sequence number in AtomicBatchDispatcher<....>::Token non-const
Summary:
Make sequence number in AtomicBatchDispatcher<....>::Token non-const:
- The field is already private and having it as const prevents a
move assignment operator from getting defined
Reviewed By: yfeldblum
Differential Revision:
D4114851
fbshipit-source-id:
9f7a4003daff02c007c01747cca6ae9da17fcb79
Christopher Dykes [Tue, 1 Nov 2016 23:50:28 +0000 (16:50 -0700)]
Don't declare the extern FingerprintTable specializations under MSVC
Summary:
MSVC doesn't allow uninitialized non-`extern` `const` declarations, but we can't mark them `extern` because they are part of a template specialization. We also can't initialize them, because they'd conflict with the definition specializations in the generated tables.
As the forward-declarations aren't required for it to work under MSVC, as the specializations are found appropriately, just don't declare the specializations under MSVC.
Reviewed By: yfeldblum
Differential Revision:
D4098282
fbshipit-source-id:
84b73d63bbe6cf9c54b7fe7a3bfc2488699df7c2
David Callahan [Tue, 1 Nov 2016 19:56:08 +0000 (12:56 -0700)]
Fix CLANG compilation: folly/TokenBucket.h
Summary:
In the next revision of clang, compilation generates multiple erroes of the form
folly/TokenBucket.h:127:29: error: exception specification is not available until end of class definition
double nowInSeconds = defaultClockNow()) {
which are eliminated by reordering the method declaration for defaultClockNow()
Refer https://llvm.org/bugs/show_bug.cgi?id=30860
Reviewed By: philippu, yfeldblum
Differential Revision:
D4107443
fbshipit-source-id:
ce64f2ae7983e533c2fcb5cb043dbdd3da5c00f7
Christopher Dykes [Tue, 1 Nov 2016 18:24:18 +0000 (11:24 -0700)]
Eliminate more VLAs
Summary:
MSVC doesn't support them, so use dynamic allocation instead.
This also fixes a place where MSVC wasn't propogating the constexpr-ness of a local into the body of a lambda, resulting in an attempt to create a VLA.
Reviewed By: yfeldblum
Differential Revision:
D4098932
fbshipit-source-id:
742b2fcd96f7f6eceb5043159403d557f7fc9673
Christopher Dykes [Tue, 1 Nov 2016 18:24:09 +0000 (11:24 -0700)]
uint8_t isn't a valid template argument for uniform_int_distribution
Summary: Clang and GCC allow it, but the spec, and MSVC, don't, so use uint16_t instead.
Reviewed By: yfeldblum
Differential Revision:
D4099285
fbshipit-source-id:
cdf7ba14b6c00e1bcdfc3650b76e6e4a47a61929
Christopher Dykes [Tue, 1 Nov 2016 18:23:40 +0000 (11:23 -0700)]
Silence a couple of warnings for MSVC in Optional.h
Summary: Silence a couple of warnings that get very spammy for MSVC.
Reviewed By: yfeldblum
Differential Revision:
D4098682
fbshipit-source-id:
b410b56062cdf82367675ea9c3dd22975e7b91bd
Andrii Grynenko [Tue, 1 Nov 2016 01:16:50 +0000 (18:16 -0700)]
Fix BoostContextCompatibility for boost >= 1.61
Reviewed By: yfeldblum
Differential Revision:
D4100221
fbshipit-source-id:
7778b48f1bba9be85f5712f61d6e1731524901c3
Andrii Grynenko [Tue, 1 Nov 2016 01:05:31 +0000 (18:05 -0700)]
Simplify the API exposed by BoostContextCompatibility
Summary: Instead of exposing raw jumpContext, it now exposes a higher-level FiberImpl class, which can be extended for newer versions of jump_fcontext.
Reviewed By: yfeldblum
Differential Revision:
D4099849
fbshipit-source-id:
28c7ce32284a0109cf040c264d46a31a45867934
Andrii Grynenko [Mon, 31 Oct 2016 23:08:47 +0000 (16:08 -0700)]
Simplify activateFiber()/deactivateFiber()
Summary: A cleanup in preparation to make folly::fibers work with newer boost.
Reviewed By: jsedgwick
Differential Revision:
D4093947
fbshipit-source-id:
e9a0aaeb915c40af96282169d4758afe572f2dd8
Maged Michael [Mon, 31 Oct 2016 21:47:41 +0000 (14:47 -0700)]
Update hazard pointers interface and implementation
Summary:
The main purpose of this diff and this library at this point is to be a public reference for the C++ standard committee and whoever is interested in the proposal to the committee.
This diff aims to be consistent with the latest version of the proposal (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0233r2.pdf).
The current interface proposal focuses on the core components (domain, object base, and raii owner). Once, that part is settled we can add to the interface:
- Thread local options (thread caching of hazard pointers and private storage of retired objects)
- Programmer control of reclamation (when and by which threads)
Also, at this point the implementation does not optimize memory ordering.
I removed hazptr_domain::try_reclaim() from the public interface at this point. The latest update to interface aims to relieve the programmer from the need to take spacial precautions against shutdown fiascos involving reclamation functions of objects stored by the default domain. Please let me know if you have any concerns about this.
Having said that about the current purpose of this library, I really appreciate any comments (in this diff or separately) on the interface in general and any suggestions for the eventual optimized implementation.
Reviewed By: davidtgoldblatt
Differential Revision:
D4104381
fbshipit-source-id:
df98adf6fd9b7a93406cb8eeca8fe2ad12388139
Lucian Grijincu [Mon, 31 Oct 2016 19:56:26 +0000 (12:56 -0700)]
folly: AsyncSignalHandler: update comments to match code
Summary: #accept2ship
Reviewed By: jsedgwick
Differential Revision:
D4105140
fbshipit-source-id:
eca1f7066e514ec3c5d316f974edc34e03872784
Christopher Dykes [Mon, 31 Oct 2016 19:00:28 +0000 (12:00 -0700)]
Access the individual words of an IPv6 address correctly in IPAddressTest on Windows
Summary: Winsock defines the internals of `in6_addr` in its own way, so we have to account for that.
Reviewed By: jsedgwick
Differential Revision:
D4099453
fbshipit-source-id:
c0ebb4e2017f61bed7d5d63058161ef3f16f9a65
Christopher Dykes [Mon, 31 Oct 2016 18:59:37 +0000 (11:59 -0700)]
In the portability implementation of sendmsg return a partial message send if it would block
Summary: If multiple iovs are passed to sendmsg, sendmsg is supposed to return the number of bytes sent if it would block, but only if the number of bytes sent is greater than 0.
Reviewed By: yfeldblum
Differential Revision:
D4099691
fbshipit-source-id:
e58fa71604966129b1fbd418c24b1bf012060428
Ameya Limaye [Mon, 31 Oct 2016 16:26:16 +0000 (09:26 -0700)]
Implement AtomicBatchDispatcher in folly::fibers
Summary:
Implement AtomicBatchDispatcher in folly::fibers
- Details about how to use the added functionality can be found
in the doc comment for class AtomicBatchDispatcher.
Reviewed By: andriigrynenko
Differential Revision:
D4054148
fbshipit-source-id:
090272eeab8c8abb15d5e400e52725853fcfc364
Kyle Nekritz [Mon, 31 Oct 2016 15:09:06 +0000 (08:09 -0700)]
Use MSG_MORE instead of 2 setsockopt calls on every AsyncSSLSocket write.
Summary: Previously we set the cork option on the socket before making multiple writes, and then unset it after, which elip found was hurting perf with 2 extra syscalls. The cork logic was also not the same as the buffer combining logic, which made us often set cork even when only doing one write.
Reviewed By: djwatson
Differential Revision:
D4058357
fbshipit-source-id:
1a07447ff5e027751e455a2403e0042bf67cb1c5
Nathan Bronson [Mon, 31 Oct 2016 01:12:26 +0000 (18:12 -0700)]
improvements to folly::doNotOptimizeAway
Summary:
A common failure mode for folly::doNotOptimizeAway is to pass it a
pointer to a complex object that the caller wants to ensure is fully
calculated, which doesn't actually ensure that. Also, the GCC and
MSVC implementations used inline assembly with an in-out parameter,
which causes a store. A survey of many usages of doNotOptimizeAway
found only 1 that relies on this make-unpredictable behavior.
This diff makes doNotOptimizeAway(&x) equivalent to doNotOptimizeAway(x)
for GCC and clang, and makes it a read-only sink. For the rare
case that the benchmark wants to disable subexpression elimination,
constant propagation, or power reduction, there is a new function
makeUnpredictable. It also merges the clang and GCC implementations,
removing a potential bias in our microbenchmarks.
Reviewed By: davidtgoldblatt
Differential Revision:
D4074670
fbshipit-source-id:
43f02e7fe149147bb172babe77787dea06e098fa
Christopher Dykes [Sat, 29 Oct 2016 00:20:16 +0000 (17:20 -0700)]
Include the Time.h portability header where needed
Summary: In this case, the SpookyHash tests, which call `clock_gettime`.
Reviewed By: yfeldblum
Differential Revision:
D4098997
fbshipit-source-id:
e402fd6626e59ccc555513384e93ef0ef891bbf3
Christopher Dykes [Fri, 28 Oct 2016 21:20:34 +0000 (14:20 -0700)]
Don't abort when calling qfind_first_byte_of_sse42 without compiler support for SSE 4.2
Summary:
If Folly was compiled without support for SSE 4.2, but this function ends up getting called, we'd abort due to the check failing.
To solve this, just don't do the check and fall back to the non-sse version.
This is reasonable because it means that the code calling `qfind_first_byte_of_sse42` only needs to care whether there is CPU support for SSE 4.2, not whether we were able to actually implement the search with SSE 4.2 based on compiler support.
Reviewed By: yfeldblum
Differential Revision:
D4096645
fbshipit-source-id:
d26a791c09f61595e40c84c47a7a2596b9b69c1e
Andrew Gallagher [Thu, 27 Oct 2016 18:38:46 +0000 (11:38 -0700)]
folly/experimental/hazptr: mark static local as "library-local"
Summary:
When using `-fvisibility-inlines-hidden` or using C/C++ shared libs
transitively from a Python binary, static locals in inline functions
can potentially have more than one definition at runtime. This diff
explicitly marks this static local as safe for this scenario.
Reviewed By: djwatson
Differential Revision:
D4082831
fbshipit-source-id:
75616ac26a39f44691ef59b889ea555e9daa391b
Giuseppe Ottaviano [Wed, 26 Oct 2016 23:47:00 +0000 (16:47 -0700)]
Add default constructor to dynamic, make other constructors simpler and stricter
Summary:
Now that the initializer list syntax has been removed we can add a default constructor.
Also,
- The `dynamic(T)` constructor was unconstrained, so it would match any type but then fail to compile (as a side effect, `is_convertible<T, dynamic>` would be always true). This also leaked the implementation details of `Array` and `Object`, as they were accepted as arguments. The diff makes the constructor accept only integral and float arguments, and all other types are SFINAEd out.
- `dynamic(Iterator, Iterator)` is made `explicit` to avoid accepting statements like `dynamic d = {"a", "b"};`.
- `object(...)` methods are simplified.
Reviewed By: luciang
Differential Revision:
D4065021
fbshipit-source-id:
ac289da7bece67c674b7036b7b51d5e016b297e5
Andrew Gallagher [Wed, 26 Oct 2016 08:24:23 +0000 (01:24 -0700)]
Move inline functions with static-locals to implementation files
Summary:
This refactors inline functions defined in headers which had static locals
so that their definition is moved to the corresponding implementation file.
Reviewed By: yfeldblum
Differential Revision:
D4049175
fbshipit-source-id:
56eeb82eb23b04c3b9940d803d05050949aa5ef9
Matthieu Martin [Tue, 25 Oct 2016 23:50:39 +0000 (16:50 -0700)]
Small rewording in folly Benchmark comment
Summary: A bit more clear
Reviewed By: yfeldblum
Differential Revision:
D4075931
fbshipit-source-id:
1398500336d412b5e7663ef1e67b20a329ce2979
Michael Lee [Tue, 25 Oct 2016 16:45:49 +0000 (09:45 -0700)]
Fix maybe-uninitialized warning in Conv.h
Summary: Some compilers think result may be uninitialized
Reviewed By: francis-ma
Differential Revision:
D4074526
fbshipit-source-id:
5df4568cfa5eb8f3b2993a82b831fd5e4028a281
Philip Pronin [Tue, 25 Oct 2016 06:27:16 +0000 (23:27 -0700)]
fix Expected<..., eUnion> move / copy ctor
Summary:
Consider `Expected<..., eUnion>(Expected&&)` ctor, where
`ExpectedUnion` move ctor would be called first, which is noop leaving
`which_` uninitialized; then `MoveConstructible` ctor is executed, calling
`assignValue()`, which performs action depending on uninitialized `which_`.
Reviewed By: yfeldblum
Differential Revision:
D4073199
fbshipit-source-id:
623660e7047afcebf9f72d83f91f84ff6078090f
Ben Maurer [Tue, 25 Oct 2016 03:14:08 +0000 (20:14 -0700)]
prevPowTwo / faster bit operations
Summary:
Add a prevPowTwo method to bits.h and optimize the current code for
GCCs output.
Reviewed By: ot
Differential Revision:
D4072341
fbshipit-source-id:
6e949d0bfcf88ff8500022939d08a2b5aa9e00c9
Tudor Bosman [Tue, 25 Oct 2016 03:04:41 +0000 (20:04 -0700)]
No need for libdwarf, only the header file matters
Summary:
folly/experimental/symbolizer doesn't actually link with libdwarf, it only requires dwarf.h.
Closes https://github.com/facebook/folly/pull/501
Differential Revision:
D4068438
Pulled By: djwatson
fbshipit-source-id:
6339eabf8fceac300caafb478c003833768125fd
Subodh Iyengar [Mon, 24 Oct 2016 20:51:50 +0000 (13:51 -0700)]
Add smart pointer types for ec
Summary:
Add smart pointer types for ec groups
and points
Reviewed By: yfeldblum
Differential Revision:
D4066848
fbshipit-source-id:
f8a5c59cf902584e5a4bea7265834fcc8898677b
James Sedgwick [Mon, 24 Oct 2016 17:29:14 +0000 (10:29 -0700)]
sync README
Summary: as above
Reviewed By: yfeldblum
Differential Revision:
D4066250
fbshipit-source-id:
7dfe07656dd338ec42fcd966328e46331202bf58
Sven Over [Mon, 24 Oct 2016 05:06:45 +0000 (22:06 -0700)]
add folly::Function::asSharedProxy
Summary:
This diff adds a method to folly::Function that moves the
Function object into a copyable, callable proxy object.
folly::Function already has the asStdFunction method, which
does the same, but wraps the proxy object in a std::function.
When a copyable shared-state proxy of a folly::Function is needed,
it is not necessarily to turn it into a std::function.
If instead the shared proxy will be passed to several functions
taking folly::Function, what happens is the folly::Function
is moved on the heap, a shared_ptr is put into a std::function,
and that is wrapped in a new folly::Function, which always
requires a memory allocation, because std::function is not
noexcept-movable. When using asSharedProxy instead, an
unspecified copyable type is returned that can implicitly
converted into a folly::Function, but without an additional
memory allocation at this point.
Reviewed By: yfeldblum
Differential Revision:
D4048621
fbshipit-source-id:
b642027b0a6957058fe0089cceeb657ec52e8669
Giuseppe Ottaviano [Sat, 22 Oct 2016 18:31:19 +0000 (11:31 -0700)]
Remove dynamic's initializer_list constructor
Summary: It has been deprecated for several months, time to nuke it.
Reviewed By: yfeldblum
Differential Revision:
D4045250
fbshipit-source-id:
21b55a7c99602c42b1a87ced6a59788fe0ac25d7
Eric Niebler [Thu, 20 Oct 2016 23:57:29 +0000 (16:57 -0700)]
Reverted commit
D3927397
Summary: Someone debugged a runtime crash and traced it back to code like: `vector<fbstring>{{"this", "that"}}`. Presumably the user thought they were passing an initializer list of strings to the vector constructor. Instead, they constructed a single fbstring with two char pointers pointing into //different// strings. With the appropriate fbstring constructors, we can flag this as invalid at compile-time.
Reviewed By: yfeldblum
Differential Revision:
D3927397
fbshipit-source-id:
ab61e1e8498ec99592a2a7726eaf1cb6324f1455
Laurent Demailly [Thu, 20 Oct 2016 23:42:56 +0000 (16:42 -0700)]
improve documentation of custom singleton creation through an example
Summary:
improve documentation of custom singleton creation through an example
(from fbcode SIOF thread suggestion)
Reviewed By: yfeldblum
Differential Revision:
D4053322
fbshipit-source-id:
e9c2ef3d1ef43d52c0bf0a601d94c017047a23a3
Eric Niebler [Thu, 20 Oct 2016 22:20:48 +0000 (15:20 -0700)]
Prevent erroneous code like vector<fbstring>{{"this", "that"}} from compiling
Summary: Someone debugged a runtime crash and traced it back to code like: `vector<fbstring>{{"this", "that"}}`. Presumably the user thought they were passing an initializer list of strings to the vector constructor. Instead, they constructed a single fbstring with two char pointers pointing into //different// strings. With the appropriate fbstring constructors, we can flag this as invalid at compile-time.
Reviewed By: yfeldblum
Differential Revision:
D3927397
fbshipit-source-id:
a5f335073fb55bbb703a23f06874238cbdb5d91a
Jim Meyering [Thu, 20 Oct 2016 16:57:12 +0000 (09:57 -0700)]
folly/Synchronized.h: avoid shadowing warnings
Summary:
Nested uses of SYNCHRONIZED (and related) macros leads
inevitably to shadowed variable declarations.
There is already a use of FOLLY_GCC_DISABLE_WARNING(shadow)
to disable -Wshadow in that code, but obviously, that cannot
help with the new options, so do similar for them via
the new FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS.
Depends on
D4041696
Reviewed By: markisaa
Differential Revision:
D4041728
fbshipit-source-id:
b85fb3452f6855d359f9b910abbd02cf8433f3f7
Jim Meyering [Thu, 20 Oct 2016 14:50:18 +0000 (07:50 -0700)]
configure.ac: check for -Wshadow-local and -Wshadow-compatible-local
Summary:
Add a configure-time check for whether -Wshadow-local and
-Wshadow-compatible-local are supported. If so, arrange to
define HAVE_SHADOW_LOCAL_WARNINGS.
In Portability.h, use that new symbol to choose whether
to define FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS, which
used pragmas to disable those new warnings.
Differential Revision:
D4041696
fbshipit-source-id:
520ee88ae55147a13d0a045aca7d86567a8da99d
Shubhanshu Agrawal [Thu, 20 Oct 2016 01:24:30 +0000 (18:24 -0700)]
add missing includes
Summary: add missing includes in folly fibers.q
Reviewed By: A5he
Differential Revision:
D4036830
fbshipit-source-id:
4dcb87377979f2875ba31b4869c2637a82298957
Dmitry Pleshkov [Wed, 19 Oct 2016 22:57:39 +0000 (15:57 -0700)]
Fix ExceptionCounter.oneThread test case
Summary: Test fails because of loop unrolling: frames are not being grouped up
Reviewed By: ot
Differential Revision:
D4034910
fbshipit-source-id:
159d3a4f116f90fdd0d51ee9de38634167ed0dc4
Andrii Grynenko [Wed, 19 Oct 2016 18:51:44 +0000 (11:51 -0700)]
Reverted commit
D4035769
Summary: This diff adapts the fibers code to the modified `fcontext` API from Boost 1.61
Reviewed By: Orvid
Differential Revision:
D4035769
fbshipit-source-id:
d3f4b6b03efdd3b6e4b92e0e1c7373747bb74fbb
Jim Meyering [Wed, 19 Oct 2016 16:00:05 +0000 (09:00 -0700)]
folly/experimental: avoid shadowing warnings
Summary: Fix warnings exposed by the upstream-proposed -Wshadow-compatible-local option.
Reviewed By: philippv
Differential Revision:
D4041749
fbshipit-source-id:
9e0dcec3b35c60e5588a2e53dfdb8605e74721c4