Phil Willoughby [Fri, 24 Mar 2017 09:05:42 +0000 (02:05 -0700)]
Expand environment-handling in folly
Summary:
Extract the environment-as-STL-map logic out of `test::EnvVarSaver` and into a
separate class `experimental::EnvironmentState` so that other code which needs
to manipulate the environment can do so more easily.
Add routines to set the process environment from the state of an
`EnvironmentState`'s map, and to extract the environment in the forms required
by `Subprocess` and the UNIX routines `execve` etc.
Reviewed By: yfeldblum
Differential Revision:
D4713307
fbshipit-source-id:
6b1380dd29b9ba41c97b886814dd3eee91fc1c0f
Ted Percival [Thu, 23 Mar 2017 18:30:38 +0000 (11:30 -0700)]
Re-enable io tests
Summary:
Looks like some tests for the `io` directory were left behind when they were moved out of experimental. Re-enabled them in the new location, except for the compression test because it takes a lot longer. It's still built and can be executed manually.
Also added some preprocessor guards around compression codecs that might not be compiled in (and therefore fail during test SetUp).
Depends on #547 because the path to gtest appears in the new Makefile.am's `CPPFLAGS`.
Closes https://github.com/facebook/folly/pull/550
Reviewed By: yfeldblum
Differential Revision:
D4631244
Pulled By: Orvid
fbshipit-source-id:
496b2c272e4f7293822f159776a02f7dd0c9e04d
Andrii Grynenko [Thu, 23 Mar 2017 18:17:04 +0000 (11:17 -0700)]
Make sure singleton destructor is always called from main thread.
Reviewed By: yfeldblum, ot
Differential Revision:
D4742262
fbshipit-source-id:
7137bb8e1cb39c74e8ba726e76e9a8a6f3e1984c
Maxim Georgiev [Thu, 23 Mar 2017 17:31:34 +0000 (10:31 -0700)]
Randomize the Unix socket name in AsyncSocketTest.SendMessageAncillaryData test to avoid collisions.
Summary:
Our test framework reports frequent failures of AsyncSocketTest.SendMessageAncillaryData. According to the logs the socket fails to bind:
folly/io/async/test/AsyncSocketTest2.cpp:3098: Failure
Expected: (bind(lfd, (struct sockaddr*)&addr, sizeof(addr))) != (-1), actual: -1 vs -1
Bind failed: 98
This diff adds the socket name randomization to avoid name collisions between tests running concurrently on the same test box.
Reviewed By: yfeldblum
Differential Revision:
D4758942
fbshipit-source-id:
6066dbc18222a4521c40b2ff218cb7dab8bd789d
Jim Meyering [Thu, 23 Mar 2017 17:18:49 +0000 (10:18 -0700)]
change EXPECT_EQ(false, ... to EXPECT_FALSE(...; ditto for ASSERT_EQ
Summary:
Change every instance of EXPECT_EQ(false, ... to the simpler/shorter EXPECT_FALSE(...
Do the same for ASSERT_EQ, for consistency, and for true/TRUE.
Reviewed By: Orvid
Differential Revision:
D4751397
fbshipit-source-id:
045293dbf8be1167f0cb1b85a2f9cd59a6a30f73
Maged Michael [Thu, 23 Mar 2017 14:13:23 +0000 (07:13 -0700)]
Flat Combining
Summary:
Flat combining template that takes the following template parameters:
T Concurrent data structure using FC interface
Mutex Mutex type (default std::mutex)
Atom Atomic template (default std::atomic)
Req Optional request structure to hold custom info (default dummy type bool)
Flat combining (FC) was introduced in the SPAA 2010 paper Flat Combining and the Synchronization-Parallelism Tradeoff, by Danny Hendler, Itai Incze, Nir Shavit, and Moran Tzafrir.
http://mcg.cs.tau.ac.il/projects/projects/flat-combining
Reviewed By: djwatson
Differential Revision:
D4602402
fbshipit-source-id:
38327f752a3e92bb01e5496c321d8c87c818087a
Giuseppe Ottaviano [Wed, 22 Mar 2017 23:02:41 +0000 (16:02 -0700)]
Fix typo in Singleton
Summary: The "l" in "Haskell" is not a singleton. Also, friends don't let friends rely on operator precedence.
Reviewed By: yfeldblum
Differential Revision:
D4756653
fbshipit-source-id:
7b5360bfc1b26fac06062e4adbfae3a1e477c2dc
Christopher Dykes [Wed, 22 Mar 2017 18:04:04 +0000 (11:04 -0700)]
Fix the nested command line app test helper
Summary:
D4719112 changed the signature of the constructor but didn't update this callsite...
Reviewed By: djwatson
Differential Revision:
D4754745
fbshipit-source-id:
ae538a3ffb64cdc211f23220ea5e0d7bb7eff9b3
Michael Lee [Wed, 22 Mar 2017 17:41:23 +0000 (10:41 -0700)]
Android should also use a relaxed Singleton
Summary: On Android, we should also use a relaxed singleton
Reviewed By: andriigrynenko
Differential Revision:
D4754227
fbshipit-source-id:
157844e618d216b768bbb07f36c380ba2f4c9ab8
Brian Smith [Wed, 22 Mar 2017 03:26:02 +0000 (20:26 -0700)]
Add additional points to configure help output
Summary: Sometimes tools need to output a little more help context before or after help.
Reviewed By: yfeldblum
Differential Revision:
D4719112
fbshipit-source-id:
e6f59312d722e0669053644d862c81758855b538
Christopher Dykes [Wed, 22 Mar 2017 01:42:28 +0000 (18:42 -0700)]
Use the gflags portability header
Summary: The gflags portability header should always be used in Folly. There were a couple of places gflags was being used directly. This fixes that.
Reviewed By: yfeldblum
Differential Revision:
D4748674
fbshipit-source-id:
ba3c0564a39f870f1f5f9371e32d06eb84591ba7
Nathan Bronson [Tue, 21 Mar 2017 21:28:38 +0000 (14:28 -0700)]
fix sorted_vector_{set,map} insert with bad hint
Summary:
sorted_vector_{set,map} can silently drop insert if the hinted
insertion position is too small. This diff fixes it.
Reviewed By: yfeldblum
Differential Revision:
D4747319
fbshipit-source-id:
31e399d07a0b77b700edf034dc723cb997dc8e16
Nick Terrell [Tue, 21 Mar 2017 18:13:36 +0000 (11:13 -0700)]
Add IOBuf::cloneCoalesced()
Summary:
`LZ4Codec::doCompress()` and `doUncompress()` need to coalesce a `const IOBuf*`, so they `clone()` and then `coalesce()`.
It is more efficient to do this in one step, as shown by the benchmarks.
Reviewed By: yfeldblum, simpkins
Differential Revision:
D4727802
fbshipit-source-id:
f8d5f6187f2ee804301232b3c75b848330169fc5
Andrii Grynenko [Tue, 21 Mar 2017 16:45:01 +0000 (09:45 -0700)]
Don't allow singleton use w/o registrationComplete()
Summary: Submitting mostly to see what breaks.
Reviewed By: yfeldblum
Differential Revision:
D4249032
fbshipit-source-id:
d4e3fdfd57750c8dcabdb4c01ab3b528c4818624
Christopher Dykes [Tue, 21 Mar 2017 13:11:14 +0000 (06:11 -0700)]
Re-enable a couple of tests under MSVC
Summary: VS 2017 is here and the bugs these were hitting have been fixed, so re-enable them.
Reviewed By: yfeldblum
Differential Revision:
D4742829
fbshipit-source-id:
898e7cfea9de9ffa813c562c12e0e18e0577c8c3
Maxim Georgiev [Tue, 21 Mar 2017 02:31:48 +0000 (19:31 -0700)]
In AsyncSocketTest.SendMessageFlags test use folly::test::TemporaryFile object instead of directly creating a file with O_TMPFILE flag
Summary: O_TMPFILE flag is not available on older Linux systems (supported starting Linux 3.11). Got complains about it on GitHub (https://fburl.com/9d848m7i) Will use folly::test::TemporaryFile instead.
Reviewed By: yfeldblum
Differential Revision:
D4729733
fbshipit-source-id:
903563825c5b939e35c61725da559e33d21212c4
Louis Brandy [Mon, 20 Mar 2017 21:55:36 +0000 (14:55 -0700)]
call static function directly
Summary: This code looks really weird and is otherwise confusing.
Reviewed By: andriigrynenko
Differential Revision:
D4730812
fbshipit-source-id:
d9f4e73145e81f085ce959a76cdb568d3ae4eb52
Christopher Dykes [Mon, 20 Mar 2017 21:51:15 +0000 (14:51 -0700)]
Give observer manager threads a name
Summary: Re-landing
D4618623 after it had to be reverted due to it's use of `FixedString`, which had broken GCC 4.8. `FixedString` should now be compiling correctly on GCC 4.8 so this should be fine now.
Reviewed By: yfeldblum
Differential Revision:
D4727022
fbshipit-source-id:
f85c6952fd82e6cd6042f8055ef54d9422f8b0f9
Jason Fried [Mon, 20 Mar 2017 18:48:49 +0000 (11:48 -0700)]
Folly Futures to Python Asyncio Futures Bridge
Summary:
folly/python/futures.h provides some helper functions for bridging folly::future to asyncio.Future.
folly/python/NotificationQueueExecutor.h is a Driveable executor that has a fileno() method that can be monitored using (select, epoll) to determine if the drive method should be called.
folly/python/executor.pyx is an implementation of a "driver" for the NotificationQueueExecutor from the python asyncio side. It tracks also keeps track of asyncio eventloops to Executor mappings.
the getExecutor() from folly/python/futures.h uses that mapping to return the correct executor for this python thread.
Reviewed By: andriigrynenko, yfeldblum
Differential Revision:
D4687029
fbshipit-source-id:
e79314606ffa18cb6933fe6b749991bfea646cde
Jim Meyering [Sun, 19 Mar 2017 02:53:26 +0000 (19:53 -0700)]
folly/test/TimeseriesTest.cpp: avoid shadowing warnings
Summary:
Fix warnings exposed by gcc's -Wshadow-compatible-local.
Rename lambda parameter "ts" to "timeSeries".
This avoids the following errors:
folly/test/TimeseriesTest.cpp:802:27: error: declaration of 'ts' shadows a previous local [-Werror=shadow-compatible-local]
folly/test/TimeseriesTest.cpp:809:31: error: shadowed declaration is here [-Werror=shadow-compatible-local]
Reviewed By: yfeldblum, liuxuli
Differential Revision:
D4735180
fbshipit-source-id:
59b3fecf4031b3c6615e5b764fbc4ea04754eb50
Victor Zverovich [Sat, 18 Mar 2017 13:29:19 +0000 (06:29 -0700)]
Make EventBaseLocal::getOrCreate work with noncopyable args
Summary: Use perfect forwarding in `EventBaseLocal::getOrCreate` to make it work with noncopyable but moveable arguments.
Reviewed By: yfeldblum
Differential Revision:
D4730566
fbshipit-source-id:
fa02348b7a9217fef980ec5e743b5990b9d19e9a
Brian Smith [Fri, 17 Mar 2017 05:19:53 +0000 (22:19 -0700)]
Put the full help before the options
Summary: This is more in line with "traditional" output from cli tools on *nix.
Reviewed By: yfeldblum
Differential Revision:
D4719055
fbshipit-source-id:
2389a4a2a49f18d4b3d0257f68036f73f8fbc49e
Andreas C. Osowski [Fri, 17 Mar 2017 00:35:15 +0000 (17:35 -0700)]
Add hash and equal_to implementations to folly::Uri
Summary:
Adds a default inline implementation for `std::hash` and `std::equal_to` to `folly::Uri`.
Both do the comparison / hash based upon the return value of `folly::Uri::toString`.
Reviewed By: yfeldblum
Differential Revision:
D4711506
fbshipit-source-id:
f4c2a9de8d4302fd315a9f31329cc8ba9f5e0409
Michael Steinert [Thu, 16 Mar 2017 21:12:55 +0000 (14:12 -0700)]
Add support for OpenSSL 1.0
Summary:
I'm working on a project where the target platform is tiny a bit out of
date:
$ openssl version
OpenSSL 1.0.0-fips 29 Mar 2010
For various "reasons" I'm not able to update it at this time, however I
would like to use Proxygen (and hence Folly). This patch allows Folly to
compile with the above version of OpenSSL.
Closes https://github.com/facebook/folly/pull/562
Reviewed By: Orvid
Differential Revision:
D4715116
Pulled By: yfeldblum
fbshipit-source-id:
be38ffb78f1e5cee971ce8cb81936b7f16efe050
JiaJie Ye [Thu, 16 Mar 2017 06:03:20 +0000 (23:03 -0700)]
Add getPeerAddress/getLocalAddress folly::SocketAddress() function
Summary: Add getPeerAddress/getLocalAddress folly::SocketAddress() function
Reviewed By: yfeldblum
Differential Revision:
D4706693
fbshipit-source-id:
534e862f4168bc9e7bb02e41eac8e2ced6a02c59
Christopher Dykes [Wed, 15 Mar 2017 18:37:07 +0000 (11:37 -0700)]
Backport std::index_sequence and friends
Summary:
To GCC 4.8, because it's not *quite* dead yet.
This is needed to get FixedString working properly on GCC 4.8
Reviewed By: yfeldblum
Differential Revision:
D4646026
fbshipit-source-id:
075df04e479bd2b11f6538da2ed3e78b59956621
Michael Steinert [Wed, 15 Mar 2017 16:23:02 +0000 (09:23 -0700)]
Fix the pkg-config filter
Summary:
I encountered a situation where "pkg-config --libs openssl" included
some linker flags, i.e.
$ pkg-config --libs openssl
-Wl,-z,relro -lssl -lcrypto -ldl -lz
This resulted in these linker flags being passed to sed. This change
filters out the linker flags from the pkg-config output.
Closes https://github.com/facebook/folly/pull/559
Reviewed By: pixelb
Differential Revision:
D4700120
Pulled By: yfeldblum
fbshipit-source-id:
530d524caf965919418d19a1df53d2b418f67717
Felix Handte [Wed, 15 Mar 2017 15:48:25 +0000 (08:48 -0700)]
Add String Support to Compression Codec
Summary:
This diff adds string-based compress and uncompress support to
folly::io::Codec. By default, the string API is implemented by translating to
and from IOBufs. Room is left for individual implementations to override that
behavior and go straight to the underlying library.
Reviewed By: yfeldblum
Differential Revision:
D4690770
fbshipit-source-id:
7e2615da9add8328654505cdda6a2c79583b4558
Michael Steinert [Tue, 14 Mar 2017 17:54:57 +0000 (10:54 -0700)]
Ignore the generated file folly/libfolly.pc
Summary: Closes https://github.com/facebook/folly/pull/560
Reviewed By: pixelb
Differential Revision:
D4700198
Pulled By: yfeldblum
fbshipit-source-id:
5e251e5719c6783c9f8a4fd9bab357ed362340c0
Michael Steinert [Tue, 14 Mar 2017 14:35:08 +0000 (07:35 -0700)]
Fix the --disable-follytestmain option
Summary:
This option is useful when compiling on systems that do not want to
include libunwind.
Closes https://github.com/facebook/folly/pull/558
Reviewed By: andrewjcg
Differential Revision:
D4701878
Pulled By: yfeldblum
fbshipit-source-id:
61765e2e04ea1da510f06d7805c2c54381aa771e
Dmitry Pleshkov [Tue, 14 Mar 2017 06:33:57 +0000 (23:33 -0700)]
small_vector should not require a copy-ctr from its element type unless it needs it.
Summary:
Use default constructor directly, instead of copying the element introduced by default parameter value.
This behavior is compatible with `std::vector`.
Reviewed By: ot, bixue2010, luciang
Differential Revision:
D4700611
fbshipit-source-id:
d3bd82c46c2857f5abcbec5dd2a64aaa85eaefe4
Christopher Dykes [Mon, 13 Mar 2017 21:47:40 +0000 (14:47 -0700)]
Add a way to determine if a compression codec is supported at runtime
Summary: Folly supports being compiled without all of the compression libraries, so we need a way to determine at runtime what libraries Folly has been compiled to support.
Reviewed By: yfeldblum
Differential Revision:
D4692556
fbshipit-source-id:
0ec459db70a4b1d64f1e07c87a1f51ae584bccd0
Nick Terrell [Mon, 13 Mar 2017 19:50:55 +0000 (12:50 -0700)]
Fill buffer before allocating more
Summary:
Modify `QueueAppender::pushAtMost(const uint8_t*, size_t)` to fill the end of
the current buffer before it allocates another.
Reviewed By: yfeldblum
Differential Revision:
D4687832
fbshipit-source-id:
7c21f4359da9f0cf26d9577abddfd640b0c877e9
Tom Jackson [Mon, 13 Mar 2017 18:09:00 +0000 (11:09 -0700)]
get_ptr(mapOfMaps, key, key...)
Summary:
Since this is a not-uncommon pattern now:
```lang=cpp
if (auto found1 = get_ptr(m, k1)) {
if (auto found2 = get_ptr(*found, k2)) {
return use(*found2);
}
}
```
This diff enables:
```lang=cpp
if (auto found = get_ptr(m, k1, k2)) {
return use(*found);
}
```
Note that it works for const and non-const maps, returning a correspondingly mutable pointer.
Reviewed By: luciang, yfeldblum
Differential Revision:
D3812701
fbshipit-source-id:
77ace9f5dca6cdc4cae7e6dfb9e5fc1075b5b571
Phil Willoughby [Mon, 13 Mar 2017 10:03:16 +0000 (03:03 -0700)]
Update folly::Singleton documentation block
Summary:
With more experience of using folly::Singleton in our code we have found new
recommendations for how it should be used. This change updates the
documentation block to include those recommendations.
Reviewed By: yfeldblum
Differential Revision:
D4688700
fbshipit-source-id:
40350c2330084a28f1dc0744176d0ac8a0e64d39
Andrii Grynenko [Sat, 11 Mar 2017 01:06:58 +0000 (17:06 -0800)]
Make EventBaseLoopController only support VirtualEventBase
Summary: EventBase support is achieved through default VirtualEventBase mechanism.
Reviewed By: yfeldblum
Differential Revision:
D4685948
fbshipit-source-id:
15c8c789a55776984aa9087455e3f7b79d7604ad
Maged Michael [Fri, 10 Mar 2017 23:34:07 +0000 (15:34 -0800)]
Fix data race in IndexedMemPool
Summary:
IndexedMemPool uses regular memory for the global and local next links. There can be concurrent reads and writes of such links. In order to avoid C++ undefined behavior due to the data races, these links should be atomic. Relaxed loads and stores are sufficient for correctness.
Depends on
D4680286
Reviewed By: nbronson
Differential Revision:
D4680317
fbshipit-source-id:
27c0d888e08bd5d862aee4c6dc6ee393033b32e3
Christopher Dykes [Fri, 10 Mar 2017 21:52:11 +0000 (13:52 -0800)]
Fix problems with clock_gettime and OSX < 10.12 + XCode 8
Summary: It's a pain, so rely on macros to figure a few things about the build configuration.
Reviewed By: yfeldblum
Differential Revision:
D4229128
fbshipit-source-id:
78b414c21cae6ba51ade2ab75b117cccad5c608c
Andrii Grynenko [Fri, 10 Mar 2017 19:40:59 +0000 (11:40 -0800)]
Use VirtualEventBase in mcrouter
Summary:
This switches mcrouter to use VirtualEventBase as the unified way of managing its threads. This allows multiple mcrouters to be run on the same thread-pool, without having to keep separate shutdown logic.
As an immediate win - this eliminates any special shutdown logic from tcc and standalone mcrouter.
Reviewed By: jmswen
Differential Revision:
D4570982
fbshipit-source-id:
3974279005150e3e1db16230fde6b5951ae016b9
Kyle Nekritz [Fri, 10 Mar 2017 17:36:52 +0000 (09:36 -0800)]
Fix use after move in AsyncSSLSocket constructor.
Summary: The new AsyncSocket is already constructed at this point so just use the event base from it.
Reviewed By: djwatson
Differential Revision:
D4689395
fbshipit-source-id:
aac898c1c6e6e0e0ffcb20b16bbf2b842cc31d54
Maxim Georgiev [Fri, 10 Mar 2017 06:19:15 +0000 (22:19 -0800)]
Implementing a callback interface for folly::AsyncSocket allowing to supply an ancillary data buffer with msghdr structure to sendmsg() system call
Summary: Implementing a callback interface for folly::AsyncSocket allowing to supply an ancillary data buffer with msghdr structure to sendmsg() system call.
Reviewed By: afrind
Differential Revision:
D4422168
fbshipit-source-id:
29a23b05f704aff796d368f4ac9514c49b7ce578
Andrii Grynenko [Fri, 10 Mar 2017 04:34:14 +0000 (20:34 -0800)]
Remove runInLoop
Summary: Existing runInLoop implementation was generally not safe (it did not capture the KeepAlive token). runInLoop() is mostly used in library code though, and often times it's ok not capture the KeepAlive token. It's better to just have the caller make the decision, rather then keep runInLoop() and make it always capture the KeepAlive token.
Reviewed By: yfeldblum
Differential Revision:
D4684025
fbshipit-source-id:
65907bbe9c774e2a7b92580d0c0387d346b495d5
Adam Simpkins [Fri, 10 Mar 2017 01:54:21 +0000 (17:54 -0800)]
teach gtest how to pretty-print StringPiece values
Summary:
Even though an ostream operator<<() is defined for StringPiece, gtest doesn't
use it when printing StringPiece values in test failure messages. Because
StringPiece defines a nested iterator type gtest instead treats StringPiece as
a container, and prints each of its elements (characters) one-by-one. This is
fairly awkward to read.
This diff defines an explicit PrintTo() function for StringPiece in
folly/test/TestUtils.h. This makes gtest print StringPiece values nicely if
you include TestUtils.h in your test sources.
Reviewed By: yfeldblum
Differential Revision:
D4672257
fbshipit-source-id:
4b39ccc116e5382c29c37c2abe879293d310faf5
Maged Michael [Thu, 9 Mar 2017 19:21:50 +0000 (11:21 -0800)]
Detect data race in IndexedMemPool
Summary: IndexedMemPool uses regular memory for the global and local next links. There is a data race as there can be concurrent reads and writes of such links. Added a test for data races.
Reviewed By: nbronson
Differential Revision:
D4680286
fbshipit-source-id:
9ef3ed439b9df07d69afe570e516c146caa53a6c
Kyle Nekritz [Thu, 9 Mar 2017 16:25:27 +0000 (08:25 -0800)]
Replace MSG_PEEK with a pre-received data interface.
Summary: MSG_PEEK was difficult if not impossible to use well since we do not provide a way wait for more data to arrive. If you are using setPeek on AsyncSocket, and you do not receive the amount of data you want, you must either abandon your peek attempt, or spin around the event base waiting for more data. This diff replaces the peek interface on AsyncSocket with a pre-received data interface, allowing users to insert data back onto the front of connections after reading some data in another layer.
Reviewed By: djwatson
Differential Revision:
D4626315
fbshipit-source-id:
c552e64f5b3ac9e40ea3358d65b4b9db848f5d74
Andrii Grynenko [Wed, 8 Mar 2017 22:13:08 +0000 (14:13 -0800)]
Fixes to always call Singleton's registrationComplete()/initFacebook()
Reviewed By: yfeldblum
Differential Revision:
D4671818
fbshipit-source-id:
80154adfef238f0be62da12fb843e22de1ae65ca
Christopher Dykes [Wed, 8 Mar 2017 20:38:27 +0000 (12:38 -0800)]
Mark non-captured constexpr variable as static
Summary:
GCC & Clang allow the use of a non-captured constexpr local within a lambda, MSVC does not.
All 3 compilers allow this when the local has static storage.
Reviewed By: yfeldblum
Differential Revision:
D4675147
fbshipit-source-id:
3e07eb77731cbd3ebda6aee4b0b57ac19ac34de5
Christopher Dykes [Wed, 8 Mar 2017 18:48:01 +0000 (10:48 -0800)]
Don't define MALLOCX_* if building with JEMalloc
Summary:
With the way it is currently, if `jemalloc.h` is included after `folly/Malloc.h`, `jemalloc.h` ends up redefining these.
This changes it to just include `jemalloc.h` if we know we're compiling with JEMalloc.
Reviewed By: yfeldblum
Differential Revision:
D4660285
fbshipit-source-id:
814e36432676e89cf7ba2bc5247b7dde2bfdc14a
Anirudh Ramachandran [Wed, 8 Mar 2017 18:10:42 +0000 (10:10 -0800)]
Fix mcrouter-oss build
Summary:
D4624754 broke mcrouter-oss because that uses older OpenSSL (1.0.1).
Reviewed By: yfeldblum, jmswen
Differential Revision:
D4670767
fbshipit-source-id:
f297c8d3e013525bb36bd059eb40c70f0c4c2dcc
Jon Maltiel Swenson [Wed, 8 Mar 2017 17:41:26 +0000 (09:41 -0800)]
std::make_unique -> folly::make_unique for older platforms
Summary: Title.
Reviewed By: yfeldblum
Differential Revision:
D4674125
fbshipit-source-id:
71ad38d7a52ab1c27fcc7ff14d130978b0ece382
Andrii Grynenko [Wed, 8 Mar 2017 00:54:44 +0000 (16:54 -0800)]
Default VirtualEventBase
Summary:
Make each EventBase have a defuault VirtualEventBase which is attached to it and is joined on destruction. Default VirtualEventBase is lazily created on first request.
This makes it trivial to use code switched to VirtualEventBase both with VirtualEventBase and EventBase.
Reviewed By: yfeldblum
Differential Revision:
D4644639
fbshipit-source-id:
cf28a3632463a1c61404c225ce1186f5a4a062a3
Alexander Blom [Tue, 7 Mar 2017 11:27:21 +0000 (03:27 -0800)]
Dial EventBase loop time logging up to 11
Summary:
There is no need for EventBase to log every loop iteration on a relatively low VLOG level.
Just move it up to 11 like the other verbose logging in EventBase.cpp
Reviewed By: yfeldblum
Differential Revision:
D4642379
fbshipit-source-id:
351636afb186ba94b2447b206d7d1389cbdba110
Anirudh Ramachandran [Tue, 7 Mar 2017 08:26:12 +0000 (00:26 -0800)]
Add a few more methods to OpenSSLCertUtils
Summary:
Add a few more getters (subject, issuer, notbefore, notafter) to
OpenSSLCertUtils.
Also add an additional API to AsyncSSLSocket to add application-generated
alert strings during the handshake, for e.g., during certificate verification
Reviewed By: knekritz
Differential Revision:
D4624754
fbshipit-source-id:
f01998b9e0e58b88ece8c6dc51ab590988bf0a8f
Johannes Kopf [Sun, 5 Mar 2017 23:58:16 +0000 (15:58 -0800)]
fixing a compile error on windows
Summary:
This file only compiles with MSVC after I made the change in this diff.
The code was difficult to follow, so I am not sure if the template is needed here?
Reviewed By: yfeldblum
Differential Revision:
D4656575
fbshipit-source-id:
19415623bdb1757b573f12cdc9d8544d716ce6f2
Jim Meyering [Sun, 5 Mar 2017 18:32:27 +0000 (10:32 -0800)]
folly/Foreach.h: avoid shadowing warnings
Summary:
Fix warnings exposed by gcc's -Wshadow-compatible-local.
Don't use a hard-coded names that would cause shadowing with each nested use of this macro.
This avoids errors like the following:
folly/Foreach.h:94:18: error: declaration of 'FOR_EACH_privateCount' shadows a previous local [-Werror=shadow-compatible-local]
folly/Foreach.h:91:12: error: shadowed declaration is here [-Werror=shadow-compatible-local]
Reviewed By: yfeldblum
Differential Revision:
D4656783
fbshipit-source-id:
d7cd820fb04ccd78242f7487e2b219dc300709b6
Subodh Iyengar [Sun, 5 Mar 2017 01:46:28 +0000 (17:46 -0800)]
Add getTotalConnectTimeout method
Summary:
AsyncSSLSocket can be connected using connect with
total timeouts.
This adds a method to get the total timeout that
was set.
Reviewed By: ngoyal, yfeldblum
Differential Revision:
D4656331
fbshipit-source-id:
a55ad9f081449d358b8133e9598a2063f625a2e6
Marc Celani [Sat, 4 Mar 2017 06:27:50 +0000 (22:27 -0800)]
Remove a RequestContext deadlock
Summary:
It is not unusual to write a RequestData that will send a request to a backend service upon destruction (for example, to log the request data). This typically involves calling EventBase::runInEventBaseThread() to do the logging. Normally, if you wait until the RequestContext is destructing for this to happen, everything works fine. However, if you explicitly call clearContextData(), then this can cause a deadlock. clearContextData() holds the write lock on the data_. Imagine the NotificationQueue thread tries to set the context (for some other reason), and it is waiting on the read lock on the data_. It does so while holding a lock on its own queue. Now, the clearContextData() calls the destructor while holding the write lock on data_, and the destructor calls runInEventBaseThread, which grabs the queue's lock. Deadlock.
This can either be fixed in NotificationQueue or RequestContext. I decided to fix it in RequestContext because there may be other deadlocks that don't involve NotificationQueue (see the test plan).
There are other deadlocks in RequestContext if you call write methods in RequestData::onSet or onUnset. But fixing this would require a massive perf regression (I imagine using shared_ptr instead of unique_ptr, and copying the ptrs under readlock and calling the callbacks after releasing the lock - yuck!) So instead, warn people against doing that.
Reviewed By: yfeldblum
Differential Revision:
D4655400
fbshipit-source-id:
cfebe696953a19dc4dba49976bbcd0ec1363bc42
Yedidya Feldblum [Fri, 3 Mar 2017 05:32:09 +0000 (21:32 -0800)]
Tweak size handling in Endian
Summary:
[Folly] Tweak size handling in `Endian`.
Either multiply by 8 in one place, or divide by 8 in another place. Go with the latter, because `sizeof` in C++ emits byte sizes, not bit sizes.
Reviewed By: simpkins
Differential Revision:
D4645020
fbshipit-source-id:
cb78600ba4c20bebc66aed506d4b5d6c378fc998
Christopher Dykes [Thu, 2 Mar 2017 21:44:59 +0000 (13:44 -0800)]
Revert
D4618623: Give observer manager threads a name
Summary: This reverts commit
21b86944f513da0700039a3e3736937fd72e8887
Differential Revision:
D4618623
fbshipit-source-id:
6ab6498a2ce22895d7052e258d1af216d46ca178
Subodh Iyengar [Thu, 2 Mar 2017 17:00:14 +0000 (09:00 -0800)]
Add a method to AsyncSSLSocket to supply connect timeouts
Summary:
The current method to supply connect timeouts to AsyncSSLSocket
is to supply only the max connect + ssl connect time.
However in some cases when connect time is known, it is desirable
to supply it so that if connect does not succeed in connect time
we can error out quicker and retry.
This adds a new method for connect time in addition to the total
Connect time.
An alternative to this would be to create a AsyncSocket, connect it
and then pass it's fd to AsyncSSLSocket, however that approach does
not work well when TFO is being used, because TFO State is a part of
the AsyncSocket's state and that is not encapsulated with the fd transfer.
We could move the state around, but that is error prone, and this is much
simpler and isolated to AsyncSSLSocket.
Reviewed By: knekritz
Differential Revision:
D4626924
fbshipit-source-id:
d802d035efbced68873ab59314d9f0e661e5509b
Yedidya Feldblum [Thu, 2 Mar 2017 05:20:44 +0000 (21:20 -0800)]
Refactor Endian
Summary:
[Folly] Refactor `Endian`.
Define `swap` for all types, instead of only declaring it for all types, but have its implementation call a function that only has a given set of non-template overloads for a given set of supported types.
The effective change is that now `Endian::swap<std::string>` will fail to compile, rather than compile but fail to link.
And support floating-point types.
Reviewed By: nbronson
Differential Revision:
D4615706
fbshipit-source-id:
5034e1e4466b8118a258d917ce8f4094460ca01a
Andrii Grynenko [Wed, 1 Mar 2017 18:37:55 +0000 (10:37 -0800)]
Fix ASAN integration with detect_stack_use_after_return turned on
Summary: detect_stack_use_after_return enables fake stack logic. Previous implementation was relying on fiber releasing its fake stack before switch, which is not safe, because that fake stack may actually be in use. This diff implements a hacky workaround by building a freeFakeStack function, which can release fake stack outside of the fiber. Ideally this function should be provided by ASAN itself.
Reviewed By: yfeldblum
Differential Revision:
D4631962
fbshipit-source-id:
6213e2a6b3cbc35fae3793fcf86b0614dd8ff825
Andrii Grynenko [Wed, 1 Mar 2017 18:35:36 +0000 (10:35 -0800)]
Disable MemoryIdler::unmapUnusedStack with ASAN
Summary: It doesn't work nicely with fake stacks (which are used with detect_stack_use_after_return).
Reviewed By: yfeldblum
Differential Revision:
D4631995
fbshipit-source-id:
f139041314f8f64c0cf0a15874d6a4710fb2a5b6
Nathan Bronson [Wed, 1 Mar 2017 17:53:28 +0000 (09:53 -0800)]
rename Range template arg for increased readability
Summary:
Parameterizing Range by the template arg T is potentially
confusing because it violates the typical container pattern of T being
the value type. This diff uses Range<Iter> consistently in Range.h when
the template arg refers to a fully general iterator.
Reviewed By: yfeldblum
Differential Revision:
D4635270
fbshipit-source-id:
f70bb2e3e23ab9875fba3dbf7b11492613a037b8
Philipp Unterbrunner [Wed, 1 Mar 2017 06:14:32 +0000 (22:14 -0800)]
New C++17 backport: folly::enable_shared_from_this
Summary:
C++14 has no direct means of creating a std::weak_ptr, one must always create a (temporary) std::shared_ptr first. C++17 adds weak_from_this() to std::enable_shared_from_this to avoid that overhead.
Alas code that is meant to compile under different language versions cannot rely on std::enable_shared_from_this::weak_from_this().
This new utility class uses SFINAE to call std::enable_shared_from_this<T>::weak_from_this() if available. Falls back to std::enable_shared_from_this<T>::shared_from_this() otherwise.
Use as a drop-in replacement for std::enable_shared_from_this where weak_from_this() is desired.
Reviewed By: yfeldblum
Differential Revision:
D4616394
fbshipit-source-id:
73bf6cd8852d4a33478a9280cc69c81e7ea73423
Haijun Zhu [Tue, 28 Feb 2017 06:45:34 +0000 (22:45 -0800)]
Give observer manager threads a name
Summary: As title, convenient for debugging. Asked for from
D4542856
Reviewed By: nkg-
Differential Revision:
D4618623
fbshipit-source-id:
21b86944f513da0700039a3e3736937fd72e8887
Ted Percival [Mon, 27 Feb 2017 23:01:14 +0000 (15:01 -0800)]
Update googletest to 1.8.0
Summary:
`make check` was failing because <gmock.h> is included but not supplied. Updating to googletest 1.8.0 includes both googletest & googlemock, so `make check` now runs (and passes).
Closes https://github.com/facebook/folly/pull/547
Reviewed By: igorsugak
Differential Revision:
D4593403
Pulled By: Orvid
fbshipit-source-id:
02f80e7b67e17562ff981e9c80a37f985eb685be
Kyle Nekritz [Mon, 27 Feb 2017 23:00:11 +0000 (15:00 -0800)]
Move some tests out of FOLLY_ALLOW_TFO ifdef.
Summary: I think this ended up encompassing more than intended.
Reviewed By: yfeldblum, maxgeorg
Differential Revision:
D4622645
fbshipit-source-id:
26597098a479b85d6ecc64abef2ecc53637ee759
Kyle Nekritz [Mon, 27 Feb 2017 18:48:39 +0000 (10:48 -0800)]
Don't call memcpy with empty buffer in IOBuf::copyBuffer().
Summary: Fixes "undefined behavior" in ubsan builds when using an empty ByteRange.
Reviewed By: siyengar
Differential Revision:
D4613663
fbshipit-source-id:
4b53ba764609acc986340f10613f84585fa697cf
Christopher Dykes [Mon, 27 Feb 2017 03:20:16 +0000 (19:20 -0800)]
Kill checks in configure.ac that aren't used
Summary: They are checks that aren't actually used anywhere to guard anything, so kill them. Many are for things that have long since been standard, or aren't even used.
Reviewed By: yfeldblum
Differential Revision:
D4615947
fbshipit-source-id:
2179caff4ef8583c89efedbff3136ae5fc552424
Christopher Dykes [Mon, 27 Feb 2017 03:19:28 +0000 (19:19 -0800)]
Use cstdint instead of inttypes.h
Summary: This is the only place `inttypes.h` is used in Folly and it's used in a context where `cstdint` would have sufficed.
Reviewed By: yfeldblum
Differential Revision:
D4619248
fbshipit-source-id:
e67dccb7d8bf1ad5f7539d4b039590253e8d8c79
Christopher Dykes [Mon, 27 Feb 2017 00:18:08 +0000 (16:18 -0800)]
Kill unused include of sched.h
Summary: These are the only includes of `sched.h` in Folly, and they really are unused:
Reviewed By: yfeldblum
Differential Revision:
D4615501
fbshipit-source-id:
6a3a1aad7a91a92a322fd93d18e1284aa3f86b89
Philip Pronin [Sun, 26 Feb 2017 23:30:35 +0000 (15:30 -0800)]
reduce consumed stack size in symbolizer
Summary:
It currently takes ~32kB of stack trace to run symbolizer, which is
very close to ASan alt stack size (32 kB).
If we exclude `demangle` (which can use unbound stack size in extreme cases),
the heaviest path in symbolizer includes `FrameArray<100>` and three arrays of
`PATH_MAX` (4 kB) size. This diff removes the former and one of the latters,
reducing this code path from 32 kB to ~10 kB.
Reviewed By: ot, yfeldblum
Differential Revision:
D4618467
fbshipit-source-id:
e6a53b61b3d5f6e8b892216d2e9b839ed8430d0e
Christopher Dykes [Sun, 26 Feb 2017 19:13:26 +0000 (11:13 -0800)]
Drop FOLLY_HAVE_STD_THIS_THREAD_SLEEP_FOR
Summary: It was only needed for GCC 4.7 support. GCC 4.8 and above support it.
Reviewed By: yfeldblum
Differential Revision:
D4616044
fbshipit-source-id:
177d7b3b7090134f9d8084a3ba7a984446c87d5e
Michael Lee [Sat, 25 Feb 2017 02:08:13 +0000 (18:08 -0800)]
Fix -Wshadow warning in sorted_vector_types
Summary: `last` was already passed in as a variable, so switch this so there isn't a local variable at all.
Reviewed By: mlogan, yfeldblum
Differential Revision:
D4615206
fbshipit-source-id:
dd8e3157e54dc2abe3dfd97837ce327371f4f7b2
Yedidya Feldblum [Fri, 24 Feb 2017 22:33:37 +0000 (14:33 -0800)]
Drop support for gcc 4.7 with byteswap shim
Summary: [Folly] Drop support for gcc 4.7 with byteswap shim
Reviewed By: igorsugak, Orvid
Differential Revision:
D4610746
fbshipit-source-id:
092cd432c7bda9ca5507d0230b6fcaa43b96c500
Giuseppe Ottaviano [Fri, 24 Feb 2017 01:51:16 +0000 (17:51 -0800)]
Fix a corner case in EliasFanoReader::previousValue
Summary:
`previousValue` makes the incorrect assumption that `outer_`
is a multiple of the word size. This is incorrect because `skipToNext`
can reposition at an arbitrary point.
The bug is very rare because it can only happen if there is a gap
larger than the skip quantum after the first element in the upper
bits.
Reviewed By: philippv
Differential Revision:
D4607270
fbshipit-source-id:
ff016f09f3f1f87314b68370e3dc137b82694f45
Mark Logan [Thu, 23 Feb 2017 20:21:31 +0000 (12:21 -0800)]
Remove duplicates during bulk insertion.
Summary:
antonl noticed that bulk_insert doesn't remove duplicates.
We now run a std::unique() pass after merging.
Reviewed By: yfeldblum
Differential Revision:
D4595304
fbshipit-source-id:
538364150aeea64b95488da158c09e07a6597e7c
Michael Lee [Tue, 21 Feb 2017 18:24:08 +0000 (10:24 -0800)]
Add getCommonName and getSubjectAltName Cert utility helpers
Summary: `getCommonName` and `getSubjectAltName` are useful shared utility functions.
Reviewed By: anirudhvr
Differential Revision:
D4546866
fbshipit-source-id:
bcefc1ff3a02df93fbf0cd2d4f24569928bd1753
Mark Williams [Mon, 20 Feb 2017 22:53:22 +0000 (14:53 -0800)]
Prevent a crash in folly::Symbolizer
Summary:
dbg and dbgo builds of hhvm with gcc-5 crash when generating
backtraces using folly::Symbolizer, because the .debug_aranges for
libc-2.23.so are SHF_COMPRESSED, and folly::Symbolizer doesn't
recognize that.
Just pretend that the section doesn't exist if it has SHF_COMPRESSED
set.
We might eventually want to support decompressing such sections under
an option - but folly::Symbolizer's goal is to just mmap and walk the
debug info without allocating memory (so that it can run while
handling signals etc).
Reviewed By: pixelb
Differential Revision:
D4586762
fbshipit-source-id:
bef61ed670d1a80caa4f7aac1f80fd2a92cc4ba9
Maged Michael [Fri, 17 Feb 2017 13:13:28 +0000 (05:13 -0800)]
Add Baton variants with multiple posters and with a non-blocking waiter
Summary:
Added two variants of Baton by adding two Boolean template parameters with defaults that correspond to the original single poster blocking waiter version:
- SinglePoster (single poster vs multiple posters). Default true.
- Blocking (vs spinning). Default true.
The multi-poster baton (SinglePoster = false) can be handed over by multiple concurrent posters, where redundant post()-s are idempotent but if a post() arrives after the baton is reset() then it unblocks the waiter.
The nonblocking Baton (Blocking = false) has faster common case post(), by avoiding CAS in the critical path. It does so by disallowing waiter blocking and timed_wait().
Reviewed By: nbronson
Differential Revision:
D4506728
fbshipit-source-id:
e5b65ad93e443fbba22164319c985ebc8424554a
Yedidya Feldblum [Fri, 17 Feb 2017 05:07:49 +0000 (21:07 -0800)]
Fix exception_wrapper::throwException when called before main
Summary:
[Folly] Fix `exception_wrapper::throwException` when called before `main`.
When the `exception_wrapper` is empty, then `throwException` emits a message to `std::cerr` and terminates. If called before `main` begins or after `main` ends, then `std::cerr` might not have been constructed yet or might have already been destructed. Bad. Segfault, etc. So we need to ensure that `std::cerr` is alive by holding an instance of `std::ios_base::Init`.
Reviewed By: Orvid
Differential Revision:
D4576190
fbshipit-source-id:
dd84b5e82eb6bd817d405baf530714e0f4c314c5
Yedidya Feldblum [Thu, 16 Feb 2017 22:45:30 +0000 (14:45 -0800)]
Drop support for Clang < 3.9
Summary: [Folly] Drop support for Clang < 3.9.
Reviewed By: igorsugak
Differential Revision:
D4567233
fbshipit-source-id:
cd94c711f0390d249b6736ab292721a477022b02
Christopher Dykes [Thu, 16 Feb 2017 22:02:54 +0000 (14:02 -0800)]
Workaround MSVC 2015 limitations in Traits.h
Summary: MSVC 2015 has issues with templated `using` declarations using `decltype`, so adjust the definition to use constexpr evaluation to fill a template parameter of a base type instead.
Reviewed By: yfeldblum
Differential Revision:
D4510155
fbshipit-source-id:
cc2e33625b515085dff4e682971299810905fef0
Christopher Dykes [Thu, 16 Feb 2017 21:10:26 +0000 (13:10 -0800)]
Adjust a few things to avoid triggering warnings under MSVC
Summary: This includes both unused parameters (W4100) and conditional expression is constant (W4127).
Reviewed By: yfeldblum
Differential Revision:
D4525057
fbshipit-source-id:
7c057dbe239d02fa2e3ce96373d53814591994ec
Christopher Dykes [Thu, 16 Feb 2017 21:08:47 +0000 (13:08 -0800)]
Use std::this_thread::yield rather than sched_yield
Summary: They do the same thing, and the first is portable.
Reviewed By: yfeldblum
Differential Revision:
D4569649
fbshipit-source-id:
db0434766f674a7789d6e59335e122b4d2131e06
Maged Michael [Thu, 16 Feb 2017 20:19:29 +0000 (12:19 -0800)]
Fix data race in Futex<EmulatedFutexAtomic>
Summary: Fixed a data race between an atomic store by the waker and a nonatomic memcpy by the waiter.
Reviewed By: nbronson
Differential Revision:
D4572410
fbshipit-source-id:
3982ca433e0f628636916516e35aeb7738ae030f
Lovro Puzar [Thu, 16 Feb 2017 11:33:51 +0000 (03:33 -0800)]
Add AtomicIntrusiveLinkedList::reverseSweep()
Summary: In
D4558451 I want to pull elements off an atomic list onto a thread-local (single-consumer) vector and pop to get elements in insertion order. A sweep that provides elements in LIFO order will avoid a redundant pair of list reversals.
Reviewed By: nbronson
Differential Revision:
D4564816
fbshipit-source-id:
38cf50418e6afe0be3eec96ce85d571c65f06d7e
Philip Pronin [Wed, 15 Feb 2017 20:10:01 +0000 (12:10 -0800)]
optimize EliasFanoEncoder::defaultNumLowerBits
Summary:
`defaultNumLowerBits` is heavily used during PL encoding with
optimally-partitioned EF. This diff improves its performance by 3.5x by
avoiding expensive 64-bit division.
Reviewed By: ot, luciang
Differential Revision:
D4564615
fbshipit-source-id:
4521d3c05f19573cd2c84f702fcfeaace5f98e77
Phil Willoughby [Wed, 15 Feb 2017 11:37:16 +0000 (03:37 -0800)]
Replace the future-splitting system
Summary:
The previous mechanism in SharedPromise doesn't work if the lifetime of the
SharedPromise object ends before the Future which it was splitting is
completed.
This variation on the same theme doesn't have that problem.
Reviewed By: spacedentist
Differential Revision:
D4339670
fbshipit-source-id:
f619762bff1390481715575b3e638ec26b5c4edd
Anton Likhtarov [Wed, 15 Feb 2017 01:35:35 +0000 (17:35 -0800)]
Fix undefined behaviour
Summary: memcpy's src cannot be nullptr even if the size is 0.
Reviewed By: djwatson
Differential Revision:
D4560100
fbshipit-source-id:
37cd3ed73f902a136f711a5c1a918258f94d1063
Alex Malyshev [Tue, 14 Feb 2017 19:09:42 +0000 (11:09 -0800)]
Add overloads of Range::{start,end}sWith with custom comparator
Summary: Intended to be used for case-insensitive prefix/suffix matching.
Reviewed By: yfeldblum
Differential Revision:
D4552336
fbshipit-source-id:
0030b883426dd67bea27c3f878279359d51e1d33
Maxim Georgiev [Tue, 14 Feb 2017 01:32:45 +0000 (17:32 -0800)]
Timestamping callback interface in folly::AsyncSocket
Summary: Adding an interface to folly::AsyncSocket allowing to receive timestamp notifications collected using recvmsg(fd, MSG_ERRQUEUE, ...).
Reviewed By: djwatson
Differential Revision:
D4329066
fbshipit-source-id:
154f5c0d04e5c0e410081d48c937af4069479fc2
Adam Simpkins [Sat, 11 Feb 2017 01:11:44 +0000 (17:11 -0800)]
add Range constructors from std::array
Summary:
Add explicit constructors to create Range objects referring to the contents of
a std::array.
D4165608 previously added a folly::range() factory function to create Ranges
around const arrays. However, it did not support non-const arrays. However,
providing this as a constructor seems better. This new constructor does not
appear ambiguous with any existing constructors, and a constructor allows for
more natural support of non-const arrays: the caller can explicitly indicate
if they want to construct a Range to const or non-const data in this case.
Reviewed By: yfeldblum
Differential Revision:
D4523515
fbshipit-source-id:
c1a262f9e8f76907d87d80b03f252576506e70ab
Andrii Grynenko [Fri, 10 Feb 2017 20:56:56 +0000 (12:56 -0800)]
Minor GDB script fix
Reviewed By: lbrandy
Differential Revision:
D4544705
fbshipit-source-id:
d60f2026d31c94e020df51f8c887b995986ddcd7
Jack Montgomery [Fri, 10 Feb 2017 20:39:08 +0000 (12:39 -0800)]
changed Synchronized.md to reflect SharedMutex as default
Summary: folly/docs/Synchronized.md now reflects the fact that SharedMutex is default mutex for Synchronized
Reviewed By: yfeldblum
Differential Revision:
D4529851
fbshipit-source-id:
b3b8eafe908ba92e3629392fbc4b856b5a99b658
Andrew Krieger [Fri, 10 Feb 2017 00:54:55 +0000 (16:54 -0800)]
Detect identity conversion in toDynamic
Summary:
D4499520 added typedefs to `dynamic` which made it start matching
tests for ranges/containers. However, the typedefs are unconditional on the
actual contents of the `dynamic`. This made toDynamic(dynamic) select the
range-based conversion operator, always, which immediately asserts when
trying to do range-based iteration over an Object or a primitive. Add tests
to the converters that enable/disable depending on whether the object is
already a `dynamic` and early-out in that case.
Reviewed By: mzlee
Differential Revision:
D4538617
fbshipit-source-id:
f3a5aafab07946a221dcead782fc27de51afa0a6
Den Raskovalov [Thu, 9 Feb 2017 20:00:33 +0000 (12:00 -0800)]
add folly:hasher<bool>
Summary:
hasher<bool> is a trivial thing, but it is useful, if we implement a hash function for a class by writing something like:
return folly::Hash()(boolField1_, boolField2_, intField3_, boolField4_, someField5_)
Reviewed By: ot
Differential Revision:
D4535563
fbshipit-source-id:
5e6672c2eeaebbbac80a8a066a6a0ec4838810f4
Andrii Grynenko [Thu, 9 Feb 2017 18:58:07 +0000 (10:58 -0800)]
Add keepAlive() mechanism
Summary:
EventBase and VirtualEventBase already had a loopKeepAlive() mechanism, which enabled libraries to prevent EventBase/VirtualEventBase from being destroyed until all keep-alive tokens were released.
This change adds generic keepAlive() support into folly::Executor. folly::Executors which don't support keep-alive mechanism yet, will just return a no-op KeepAlive token.
Reviewed By: yfeldblum
Differential Revision:
D4516649
fbshipit-source-id:
869779621c746cb14d985aa73bc4536859914c03
Phil Willoughby [Thu, 9 Feb 2017 12:35:54 +0000 (04:35 -0800)]
Benchmark string copying via the formatter
Summary:
Using the formatter is always much slower than using the copy constructor (News at 11).
Comparing the two idioms for formatting out a single string input:
* the unsafe method (`format(theString)`) is (annoyingly) fastest for small strings; probably because cache-hits dominate the need to inspect every character to see if it is `{` or `}`
* the safe method (`format("{}",theString)`) is fastest on large strings (crossover at roughly 256 bytes)
* there isn't a lot in it between 64 and 512 bytes.
Reviewed By: yfeldblum
Differential Revision:
D4423088
fbshipit-source-id:
7f8590653ab33fe62887a506ea79a43989fbfb29