folly.git
7 years agoRefactor stats to use the same type for indexes
Christopher Dykes [Fri, 16 Dec 2016 03:59:27 +0000 (19:59 -0800)]
Refactor stats to use the same type for indexes

Summary:
This refactors folly/stats/* to use a single type for indexes rather than `size_t`, `int`, `unsigned int`, `uint64_t` and `int64_t` depending on where you looked.
This also has the result of getting MSVC to not complain about implicit sign conversions and implicit truncations.

Reviewed By: simpkins

Differential Revision: D4282174

fbshipit-source-id: 8529be34dce8ad18bc64395330bbdf2cd7305be4

7 years agoInclude <cassert> when using assert
Christopher Dykes [Fri, 16 Dec 2016 01:31:48 +0000 (17:31 -0800)]
Include <cassert> when using assert

Summary:
We were using `assert` without including anything that defines it.

Closes https://github.com/facebook/folly/issues/530

Reviewed By: yfeldblum

Differential Revision: D4337047

fbshipit-source-id: 327d19a685e7a4cc1e1eb6e471a6457fe9dee6c7

7 years agoCheck the baton waits in the ScopedEventBaseThread tests
Yedidya Feldblum [Thu, 15 Dec 2016 09:37:21 +0000 (01:37 -0800)]
Check the baton waits in the ScopedEventBaseThread tests

Summary:
[Folly] Check the baton waits in the `ScopedEventBaseThread` tests.

Also:
* `Baton<T>::timed_wait` can take a `duration`, not just a `time_point`.
* Allow a bit more time for waiting, just in case the machine running the tests is under load.

Reviewed By: andriigrynenko

Differential Revision: D4330126

fbshipit-source-id: 55878577b1deeb260686647e5f22a81d6fb9e06d

7 years agoRequire runBeforeLoop callbacks to be canceled prior to EventBase destruction
Andrii Grynenko [Thu, 15 Dec 2016 04:06:38 +0000 (20:06 -0800)]
Require runBeforeLoop callbacks to be canceled prior to EventBase destruction

Summary: This makes it similar to other other events registered with EventBase.

Reviewed By: yfeldblum

Differential Revision: D4331277

fbshipit-source-id: 5d728d4ae5faff1a72ed724b4e2a6c0dd6c3b02d

7 years agoadd folly::init to libfolly for OSS build
Wez Furlong [Thu, 15 Dec 2016 04:03:32 +0000 (20:03 -0800)]
add folly::init to libfolly for OSS build

Summary:
We use this in eden and this avoids needing to patch the homebrew recipe.

I've also made the use of the folly symbolizer specific to the facebook
internal build of folly, because it fails to compile in the Linux OSS build
too.

Reviewed By: yfeldblum

Differential Revision: D4292166

fbshipit-source-id: b69153be8ab9cc461bc7f456248e73972ba7f461

7 years agoMake FunctionLoopCallback available outside of EventBase.cpp
Andrii Grynenko [Thu, 15 Dec 2016 04:03:18 +0000 (20:03 -0800)]
Make FunctionLoopCallback available outside of EventBase.cpp

Reviewed By: yfeldblum

Differential Revision: D4331194

fbshipit-source-id: 1e1579e3b775b1b4e329aa28aae11a2b54294697

7 years agoMake SingletonVault state use ReadPriority mutex
Andrii Grynenko [Thu, 15 Dec 2016 04:02:46 +0000 (20:02 -0800)]
Make SingletonVault state use ReadPriority mutex

Summary: This fixes a deadlock possible when singleton chain is created concurrently with destroyInstances().

Reviewed By: lbrandy, yfeldblum

Differential Revision: D4329028

fbshipit-source-id: a11b3ff42d164ead2f8e3e77e0e17be43a8ad306

7 years agowork around GCC#61971 (spurious -Warray-bounds warnings) in folly::FixedString
Eric Niebler [Wed, 14 Dec 2016 20:21:25 +0000 (12:21 -0800)]
work around GCC#61971 (spurious -Warray-bounds warnings) in folly::FixedString

Summary:
GCC has the temerity to insinuate that my code has out-of-array-bounds access. After cross-checking with clang and ubsan, reviewing the code, and running constexpr tests (for which out-of-range errors are caught at compile time), I can say with pretty high confidence that this is an instance of GCC#61971 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61971). Basically, the gcc-4 series is known to issue spurious -Warray-bounds warnings. The "fix" is to route internal accesses to some helper functions, for which -Warray-bounds has been suppressed.

User code that accesses elements with operator[] will still warn on out-of-bounds access. If this is a problem in practice, we can suppress the warning there, too. Trying this for now since it is less likely to hide real problems.

Reviewed By: yfeldblum

Differential Revision: D4317305

fbshipit-source-id: 7bf92f993ac1a29631463c582c1b64d76f755181

7 years agofix ExceptionTracerTest build
Nathan Bronson [Wed, 14 Dec 2016 17:03:02 +0000 (09:03 -0800)]
fix ExceptionTracerTest build

Summary:
A recent diff added [[noreturn]] annotations that cause buck
build to fail for ExceptionTracerTest.cpp, due to our use of -Werror
and -Wunreachable-code-return.  This diff removes the unreachable return
statement.

Differential Revision: D4326888

fbshipit-source-id: 7863c163eedcf2a7e19730c1de194f05c544a2c0

7 years agoAllow building with -Wmissing-noreturn
Christopher Dykes [Wed, 14 Dec 2016 06:05:21 +0000 (22:05 -0800)]
Allow building with -Wmissing-noreturn

Summary: If your function doesn't return you should be explicit about it.

Reviewed By: meyering

Differential Revision: D4309893

fbshipit-source-id: ce275ec8f42e2cb3253a1e40e263934649f09d9e

7 years agoUpdate fibers GDB docs
Andrii Grynenko [Wed, 14 Dec 2016 01:50:27 +0000 (17:50 -0800)]
Update fibers GDB docs

Reviewed By: yfeldblum

Differential Revision: D4323918

fbshipit-source-id: 8dcd4ef3629fff061a9f149093ef1fe087f1c7e2

7 years agoFind and remove unused headers
Michael Lee [Tue, 13 Dec 2016 22:02:10 +0000 (14:02 -0800)]
Find and remove unused headers

Summary: Find and remove a couple of unnecessary includes

Reviewed By: matbd

Differential Revision: D4322316

fbshipit-source-id: 7b55119bd7566fd62762ace5e35aa536489fafad

7 years agoMove GDB scripts for fibers into folly
Andrii Grynenko [Tue, 13 Dec 2016 21:57:32 +0000 (13:57 -0800)]
Move GDB scripts for fibers into folly

Reviewed By: igorsugak

Differential Revision: D4320762

fbshipit-source-id: 2028de6ccc6fb129381b03d694b88677a5aa50d6

7 years agoAdd evb change callback to SSL Socket
Neel Goyal [Tue, 13 Dec 2016 18:25:19 +0000 (10:25 -0800)]
Add evb change callback to SSL Socket

Summary: Allow observers to be notified when AsyncSocket attaches and detaches from EVB

Reviewed By: siyengar

Differential Revision: D4256175

fbshipit-source-id: a3ff96811f885e508f20cf11ce52e0f00e5ee461

7 years agoEnable -Wunreachable-code-return
Christopher Dykes [Tue, 13 Dec 2016 18:01:00 +0000 (10:01 -0800)]
Enable -Wunreachable-code-return

Summary: The most common place this happened was in tests where it was being used to force the return type of a lambda, but there were a couple of places in the main code that triggered this as well.

Reviewed By: yfeldblum

Differential Revision: D4310187

fbshipit-source-id: e3701cff9827eacaf3be8d28296441466eb2fa11

7 years agomove JemallocNodumpAllocator to folly/experimental
Philip Pronin [Tue, 13 Dec 2016 09:53:43 +0000 (01:53 -0800)]
move JemallocNodumpAllocator to folly/experimental

Summary:
Moving russoue's `JemallocNodumpAllocator` (D3147173) from
`mcrouter` codebase to `folly`, so we can use it in a few other services
that suffer from a huge core dump problem.

Reviewed By: russoue, jmswen, luciang

Differential Revision: D4311394

fbshipit-source-id: 6a13c478b939bd411e0fd37e655125f62434c366

7 years agoallow run-once callbacks
Igor Zinkovsky [Tue, 13 Dec 2016 07:21:55 +0000 (23:21 -0800)]
allow run-once callbacks

Summary: Adding new `addFunctionOnce` method that executes provided callback only once.

Reviewed By: yfeldblum

Differential Revision: D4315635

fbshipit-source-id: 4819ec30b4f2e4ab3185a37158404e1c7a96758a

7 years agoAllow building with -Wshift-sign-overflow
Christopher Dykes [Mon, 12 Dec 2016 23:15:27 +0000 (15:15 -0800)]
Allow building with -Wshift-sign-overflow

Summary: Prior to C++14 these shifts are undefined behavior, but the unsigned version is not, so do the shifts on unsigned values before converting to the final type.

Reviewed By: yfeldblum

Differential Revision: D4309311

fbshipit-source-id: 914b207bac2f77a96c07a8a5df81980c672aa677

7 years agoAllow building with -Wgnu-conditional-omitted-operand
Christopher Dykes [Mon, 12 Dec 2016 19:46:03 +0000 (11:46 -0800)]
Allow building with -Wgnu-conditional-omitted-operand

Summary: Which warns about the use of a ternary statement with the first operand omitted. This is a GCC extension and MSVC does not support it, so eliminate the last use of it.

Reviewed By: yfeldblum

Differential Revision: D4309989

fbshipit-source-id: 04c968708e47f8cb707fd0892e8780bc676df0de

7 years agoDon't declare a variable for exceptions we discard
Christopher Dykes [Mon, 12 Dec 2016 19:39:32 +0000 (11:39 -0800)]
Don't declare a variable for exceptions we discard

Summary: They aren't needed and they count as initialized but unused variables.

Reviewed By: yfeldblum

Differential Revision: D4308844

fbshipit-source-id: a6833dbf434ebdefff0b375729a4e62495463ac0

7 years agoFix some implicit truncation and sign coersion in the networking APIs
Christopher Dykes [Mon, 12 Dec 2016 19:34:23 +0000 (11:34 -0800)]
Fix some implicit truncation and sign coersion in the networking APIs

Summary: Split out of an earlier pair of diffs, this focuses exclusively on Folly's networking APIs and works to eliminate places where values were being implicitly truncated.

Reviewed By: yfeldblum

Differential Revision: D4288042

fbshipit-source-id: dd6e19acd319296a45c29c8050dc62f06571e1e6

7 years agoEnable -Wunreachable-code-break v2016.12.12.00
Christopher Dykes [Sat, 10 Dec 2016 02:26:52 +0000 (18:26 -0800)]
Enable -Wunreachable-code-break

Summary: Because the `break;` can be dead, and sometimes is indicitive of a different type of error.

Reviewed By: meyering

Differential Revision: D4310056

fbshipit-source-id: ad215eb9b2e5bb4d5c703582203efce893b26a76

7 years agoLog supported versions extension in AsyncSSLSocket.
Kyle Nekritz [Sat, 10 Dec 2016 00:09:42 +0000 (16:09 -0800)]
Log supported versions extension in AsyncSSLSocket.

Summary: To monitor client support of TLS 1.3.

Reviewed By: ngoyal

Differential Revision: D4308473

fbshipit-source-id: cb6fb444c8b7ced39e6655a0f63b18523c2fb9c5

7 years agofolly/io/async/tests: always detach event base in tests, fixes UBSAN tests
Nathan Bronson [Fri, 9 Dec 2016 20:42:28 +0000 (12:42 -0800)]
folly/io/async/tests: always detach event base in tests, fixes UBSAN tests

Summary:
In AsyncSSLSocket tests the shared_ptr structure means that the
AsyncSSLSocket-s outlive the stack-allocated EventBase on which they were
created.  Previously there were scattered calls to detachEventBase on the
last interesting callback, but several calls were missing.  This diff
switches to a model where the SSLServerAcceptCallbackBase is responsible
for detaching the sockets.

This diff also fixes a low-firing race between shutdown
of the TestSSLAsyncCacheServer Main thread and a call to
EmptyReadCallback::readEOF.  Most uses of EmptyReadCallback don't attach
the TCP socket, so they can't actually tolerate a call to readError
or readEOF.

These use-after-destruction problems were discovered by UBSAN.

Reviewed By: djwatson

Differential Revision: D4301416

fbshipit-source-id: 127fb5e506d0694c5ca81d7a38c704d69f4ab3eb

7 years agoEnable -Wextra-semi
Christopher Dykes [Fri, 9 Dec 2016 19:04:19 +0000 (11:04 -0800)]
Enable -Wextra-semi

Summary:
Because the extra semicolons are useless and all typos...
GCC doesn't have this warning. Neither does MSVC, but that won't stop me.

Reviewed By: igorsugak

Differential Revision: D4304218

fbshipit-source-id: a06586edc6b9bafd5dd074e9fd4e0ed152181abc

7 years agoDon't shadow locals, parameters or fields
Christopher Dykes [Fri, 9 Dec 2016 01:37:20 +0000 (17:37 -0800)]
Don't shadow locals, parameters or fields

Summary:
This accounts for the places that were triggering warnings 4456, 4457, and 4458, which are all related to shadowing names, be they locals, parameters, or even types.
This doesn't deal with 4459, which is specifically for shadowing global variables, because folly/gen defines globals by the name of `count`, `min`, `max` and a few other similar names.

Reviewed By: meyering

Differential Revision: D4296781

fbshipit-source-id: a2e625095e2c65a53a9226b000aaf0ca95a3a393

7 years agoFix SimpleBarrier
David Goldblatt [Fri, 9 Dec 2016 01:20:46 +0000 (17:20 -0800)]
Fix SimpleBarrier

Summary:
Do the barrier completion test in a loop. (std::condition_variable has pthreads-style spurious wakeups).

(Sorry for missing this in review).

Reviewed By: djwatson

Differential Revision: D4302035

fbshipit-source-id: 3322d6a0ffba8c47c46bafb1d88034e1a0a9c652

7 years agoupdate small locks benchmark
Dave Watson [Thu, 8 Dec 2016 18:28:21 +0000 (10:28 -0800)]
update small locks benchmark

Summary: Add fairness benchmark, contended benchmark

Reviewed By: davidtgoldblatt

Differential Revision: D3706680

fbshipit-source-id: 01814fcd6b0cc3dd12815a2b2c248abc6a3771ec

7 years agoFix sorted_vector_set::erase
Qinfan Wu [Thu, 8 Dec 2016 16:38:14 +0000 (08:38 -0800)]
Fix sorted_vector_set::erase

Summary: It deletes things even when input isn't in the container.

Reviewed By: luciang

Differential Revision: D4298340

fbshipit-source-id: 3e8fc04c2c21eb231dcaf82239ac5f6d25e49e2c

7 years agoFix Synchronized.md documentation to use correct condition_variable::wait call
David Lam [Wed, 7 Dec 2016 23:32:30 +0000 (15:32 -0800)]
Fix Synchronized.md documentation to use correct condition_variable::wait call

Summary:
`condition_variable::wait_for` takes as second param `std::chrono::duration`
and not a predicate; what we want is `condition_variable::wait`.

Reviewed By: simpkins

Differential Revision: D4295305

fbshipit-source-id: 05f735fe6e7ecb9d8f42cb38a2985b9ce9dad984

7 years agoFix some implicit truncations in the interaction with OpenSSL APIs
Christopher Dykes [Wed, 7 Dec 2016 22:16:59 +0000 (14:16 -0800)]
Fix some implicit truncations in the interaction with OpenSSL APIs

Summary: MSVC has the ability to warn about implicit truncations and places where implicit sign coercions are occuring, so do some cleanup to make it possible to compile with the warnings enabled.

Reviewed By: yfeldblum

Differential Revision: D4288028

fbshipit-source-id: f8330c62b2dcb76f696dfc47888f0e3e1eefc21a

7 years agoCut some includes from Executor.h
Yedidya Feldblum [Wed, 7 Dec 2016 22:14:47 +0000 (14:14 -0800)]
Cut some includes from Executor.h

Summary: [Folly] Cut some includes from `Executor.h`.

Reviewed By: mzlee

Differential Revision: D4256618

fbshipit-source-id: 1728f48b3c0ec4e0c4c84c44bd8afb583d438129

7 years agoUSE_JEMALLOC in the OSS build if we have jemalloc
Wez Furlong [Wed, 7 Dec 2016 20:53:52 +0000 (12:53 -0800)]
USE_JEMALLOC in the OSS build if we have jemalloc

Summary:
Nothing defines USE_JEMALLOC in the OSS build today and that causes
some portability problems.

Specifically, the homebrew recipe will make libjemalloc available and our
configure script will detect it and add it to the library flags.

Our subsequent check for `malloc_usable_size` then finds this function in
libjemalloc.

When later attempting to build wangle against the homebrew folly we get
compilation failures because the prototype for `malloc_usable_size` is only
available in the jemalloc headers and nothing in the saved configuration for
folly is set up for this to be pulled in as it it guarded by `USE_JEMALLOC`.

This attempts to resolve the situation by forcing on `USE_JEMALLOC` when
we detect the library in configure.

This is made a little more complicated because we cannot set `USE_JEMALLOC`
in the OSS build; it gets rewritten to have a `FOLLY_` prefix.  Since we
have code outside of folly that requires that this symbol be `USE_JEMALLOC`,
I've changed the conditional to check for both flavors of the symbol, with
and without the prefix.

Reviewed By: yfeldblum

Differential Revision: D4289176

fbshipit-source-id: 756bc815c3ef1fac454e603feb72155d98c5aadd

7 years agoadd folly::FixedString, a constexpr-usable string with a fixed-size internal buffer
Eric Niebler [Wed, 7 Dec 2016 20:43:21 +0000 (12:43 -0800)]
add folly::FixedString, a constexpr-usable string with a fixed-size internal buffer

Summary: Inspired by http://wg21.link/p0259, folly::BasicFixedString is a std::string replacement that is usable in constexpr contexts. It uses an internal fixed-size buffer to store up to N characters, where N is a template parameter.

Reviewed By: luciang

Differential Revision: D4249529

fbshipit-source-id: 10f12ea2510a8d21ec60a07a8f15ecc3e35c5431

7 years agoRename stdin, etc. in Subprocess to work with MSVC
Christopher Dykes [Wed, 7 Dec 2016 19:42:17 +0000 (11:42 -0800)]
Rename stdin, etc. in Subprocess to work with MSVC

Summary:
`stdin`, `stdout` and `stderr` are macros that expand to function calls with the MSVC CRT implementation. This is also the case for musl-libc. This means that Subprocess simply cannot be compiled on those platforms without changing the API.
To solve that, we change the API and deprecate the old API.

For more fun, `stdin`, `stdout` and `stderr` are also macros in glibc, they just expand to other identifiers rather than a function call.

Reviewed By: yfeldblum

Differential Revision: D4229544

fbshipit-source-id: 97f1a3b228b83cfdcaffee56d729063ea235e608

7 years agofix FutureTest/RequestContext
Nathan Bronson [Wed, 7 Dec 2016 19:39:00 +0000 (11:39 -0800)]
fix FutureTest/RequestContext

Summary: Fix use-after-destroy of NewThreadExecutor.  Detected by opt-ubsan tests.

Reviewed By: yfeldblum

Differential Revision: D4291900

fbshipit-source-id: 206f1d7b80fa04e1570e4b7a20e50b9a8ceb7bcb

7 years agoincrease writeLen for tests that want to trigger buffering
Nathan Bronson [Wed, 7 Dec 2016 19:20:21 +0000 (11:20 -0800)]
increase writeLen for tests that want to trigger buffering

Summary:
Freshly opened TCP sockets can have a send buffer size bigger
than wmem_default, because connection parameters are cached in the
route cache.  Some of the async socket tests assumed that writing 8M of
data was enough to guarantee blocking behavior, but since wmem_max is
20M on our systems the resulting tests are flaky.

Reviewed By: marcinpe

Differential Revision: D4292201

fbshipit-source-id: ba5d606d080330e455eee2b17bcae6cf546bf981

7 years agoAdd EvictingCacheMap MoveConstructor
Dan Schatzberg [Wed, 7 Dec 2016 16:08:34 +0000 (08:08 -0800)]
Add EvictingCacheMap MoveConstructor

Summary:
Add the default move constructor and move operator
to EvictingCacheMap so it can be moved.

Reviewed By: markisaa, luciang

Differential Revision: D4287472

fbshipit-source-id: 130e9d5467d6da14ba95a9e769cf8e8d541a704c

7 years agoIncrease fiber stack size if UBSAN is enabled
Andrii Grynenko [Tue, 6 Dec 2016 23:11:57 +0000 (15:11 -0800)]
Increase fiber stack size if UBSAN is enabled

Summary: UBSAN instrumentation results in more stack being used. Applying the same logic we already have for ASAN there.

Reviewed By: igorsugak

Differential Revision: D4287455

fbshipit-source-id: 1a224cb5a3654c23b15fa298bf80476234a1418c

7 years agoRemove unecessary iostream include
Michael Lee [Tue, 6 Dec 2016 21:58:20 +0000 (13:58 -0800)]
Remove unecessary iostream include

Summary: MacAddress only needs to include ostream and the test header does not need iostream.

Differential Revision: D4286405

fbshipit-source-id: e64fdd4e8428c62279ed7c185188f3dfc14096d3

7 years agoMore iostream removal.
Michael Lee [Tue, 6 Dec 2016 20:08:49 +0000 (12:08 -0800)]
More iostream removal.

Summary:
We do not need it and it adds a static initialization

This is the last extra one in liger. The other places actually need iostream to print things

Reviewed By: yfeldblum

Differential Revision: D4286095

fbshipit-source-id: 44a827e48e9fb9106626e784592eb194dff83bf6

7 years agoMake bm_min_iters a 32-bit flag
Christopher Dykes [Tue, 6 Dec 2016 18:51:35 +0000 (10:51 -0800)]
Make bm_min_iters a 32-bit flag

Summary:
The benchmark API only supports `unsigned int` as the iteration number, so this being 64-bit means it has to be truncated for no reason.
This change gets us closer to being able to enable MSVC's implicit truncation warnings.

Reviewed By: yfeldblum

Differential Revision: D4281264

fbshipit-source-id: 27397e3f23bace20f3cc457665ea6f21bf994da5

7 years agofix gbd debugging script
Misha Shneerson [Tue, 6 Dec 2016 04:33:09 +0000 (20:33 -0800)]
fix gbd debugging script

Summary:
I was getting an error when running commands in
https://our.intern.facebook.com/intern/dex/fibers/gdb/

Reviewed By: andriigrynenko

Differential Revision: D4283229

fbshipit-source-id: fe45847d0ec6cadfbce6fe9818066cce3e275a46

7 years agoconstexpr_strlen works for types other than char. Remove bogus check for nullptr.
Eric Niebler [Mon, 5 Dec 2016 21:06:16 +0000 (13:06 -0800)]
constexpr_strlen works for types other than char. Remove bogus check for nullptr.

Summary: overload constexpr_strlen to work with other character types

Reviewed By: yfeldblum, luciang, Orvid, ot

Differential Revision: D4269654

fbshipit-source-id: 2fcd666669efb51d77e847ff31bda3a301e763da

7 years agoReformulate constexpr_min and constexpr_max to achieve stability in sorting as descri...
Eric Niebler [Mon, 5 Dec 2016 20:51:19 +0000 (12:51 -0800)]
Reformulate constexpr_min and constexpr_max to achieve stability in sorting as described in stepanovpapers.com/notes.pdf

Summary: There is a famous long-standing "bug" in the standard library regarding the semantics of min and max wrt values that are equivalent wrt op< but not equal. Let's not make the same mistake with constexpr_min and constexpr_max.

Reviewed By: yfeldblum, luciang, Orvid, ot

Differential Revision: D4269635

fbshipit-source-id: 19b464c949dc0cf07afb08eaf657ae8b242ca42d

7 years agoFix potential double close() on exception v2016.12.05.00
Amir Shalem [Sun, 4 Dec 2016 19:15:34 +0000 (11:15 -0800)]
Fix potential double close() on exception

Summary:
Fix potential double close() on exception when SO_REUSEPORT fails.
The fd will be closed twice, once by close() and second by the scope guard above.

Reviewed By: yfeldblum

Differential Revision: D4272300

fbshipit-source-id: a163be822d7522cadb9dc3c3eddca10df453de14

7 years agoGet ConcurrentSkipList functional
Christopher Dykes [Sat, 3 Dec 2016 00:45:01 +0000 (16:45 -0800)]
Get ConcurrentSkipList functional

Summary:
MSVC was getting thoroughly confused while trying to eval the constexpr function, so switch it to a template instead.
MSVC was also failing to wrap it's head around what a NodeRecycler is, so delay its resolution via typename.

Reviewed By: yfeldblum

Differential Revision: D3478755

fbshipit-source-id: f687f4538fb12ef8eee525557f4cc988a09e714d

7 years agoBegin making folly compile cleanly with a few of MSVC's sign mismatch warnings enabled
Christopher Dykes [Fri, 2 Dec 2016 22:23:36 +0000 (14:23 -0800)]
Begin making folly compile cleanly with a few of MSVC's sign mismatch warnings enabled

Summary:
This makes the changes required to allow folly to compile cleanly with the sign/unsigned mismatch warnings 4388 and 4389, as well as with warnings 4804 and 4805, which are about comparisons between scalars and bool.
Most of the changes in this are to `DCHECK_*` calls which are translated to a templated call which does the comparison internally based on the inferred type of the argument, which for a literal `0` is `int`, causing the warnings to get generated when the comparison is done.

Reviewed By: yfeldblum

Differential Revision: D4253427

fbshipit-source-id: cd17973a78e948a62c886a2959f9abf40a69f9f5

7 years agosupport getting timer from eventbase
Scott Michelson [Fri, 2 Dec 2016 19:48:48 +0000 (11:48 -0800)]
support getting timer from eventbase

Summary: This brings the EventBase functionality of getting a timer for the eventbase into the virtual interface

Differential Revision: D4264135

fbshipit-source-id: e5526610eca808e1d7b549a7cd6cd7b2c65d3ce1

7 years agoadd a new writeFileAtomic() function
Adam Simpkins [Thu, 1 Dec 2016 23:45:22 +0000 (15:45 -0800)]
add a new writeFileAtomic() function

Summary:
Add a utility function to more safely set a file's contents by writing to a
temporary file first, then renaming the temporary file into place.  On Linux
systems where renames are atomic, this ensures that the operation either
succeeds or that the old file state is left unchanged on failure.

Note that unlike most of the other APIs in FileUtil.h, I intentionally made
writeFileAtomic() throw an exception on failure.  This is implemented using a
lower-level writeFileAtomicNoThrow() version.  Callers who care about the
exception overhead can use the lower level version instead.  (Exception
overhead should be relatively low compared to the file I/O operations, though,
so I suspect most users will prefer the throwing APIs.)

Reviewed By: yfeldblum

Differential Revision: D4253964

fbshipit-source-id: 5301e2791b82c6f90b63bb509b0411841c266705

7 years agoFuture<typename>::getTryVia
Yedidya Feldblum [Thu, 1 Dec 2016 20:43:06 +0000 (12:43 -0800)]
Future<typename>::getTryVia

Summary:
[Folly] `Future<typename>::getTryVia`.

We have `waitVia` and `getVia` and `getTry`, but `getTryVia` was missing.

Reviewed By: fugalh

Differential Revision: D4254972

fbshipit-source-id: 403e1a3496ad5dfc93c4c55ab75a83bcc89e6c64

7 years agoFix assertion in unit test
Subodh Iyengar [Thu, 1 Dec 2016 14:39:24 +0000 (06:39 -0800)]
Fix assertion in unit test

Summary:
Fix test for AsyncSSLSocket. When a timeout
occurs during a handshake it's possible that
invokeConnectError is called with sslState_ ==
CONNECTING. This just removes the assertion in
this case. This doesnt affect prod code, only
tests

Reviewed By: yfeldblum

Differential Revision: D4252677

fbshipit-source-id: 4db3a94ae28aa140546554c087bedcee7f06d201

7 years agoUse singleton EventBasePool in ServiceRouter
Andrii Grynenko [Thu, 1 Dec 2016 01:59:58 +0000 (17:59 -0800)]
Use singleton EventBasePool in ServiceRouter

Summary:
Switching ServiceRouter code to use VirtualEventBase instead of EventBase allows us to have same thread-pool shared between multiple ServiceRouter instances.

In future this allows us to replace EventBasePoolImpl with some generic thread-pool implementation (e.g. IOThreadPoolExecutor). It also makes it trivial to have ServiceRouter run on a any existing thread-pool if necessary.

Reviewed By: smichelson

Differential Revision: D3935283

fbshipit-source-id: 3275bbace15a0df8b06d12c970ccc098a631658d

7 years agoUse SingletonThreadLocal in folly::Random
Andrii Grynenko [Thu, 1 Dec 2016 00:50:04 +0000 (16:50 -0800)]
Use SingletonThreadLocal in folly::Random

Summary: folly::SingletonThreadLocal should be used for all thread-local singletons to avoid SDOF.

Reviewed By: yfeldblum

Differential Revision: D4253009

fbshipit-source-id: 5b4ca57a7a77b7b54c94630a2a29d13b84a3af27

7 years agoStart fixing implicit truncations
Christopher Dykes [Wed, 30 Nov 2016 19:17:39 +0000 (11:17 -0800)]
Start fixing implicit truncations

Summary:
Truncations should be explicit, but for some reason, MSVC seems to be the only compiler that will warn you when you implicitly truncate integer or float values.
This allows Folly to be compiled with warnings 4018, 4242, 4244 and 4305 enabled.
Technically 4018 is a sign mismatch warning, but there was only one place it was being triggered so I included it anyways. The other 3 are warnings for implicit truncation.

There is one other implicit truncation warning that currently triggers in Folly, 4267, but there are a lot more places where that triggers so I'll do that in a separate diff.

Reviewed By: yfeldblum

Differential Revision: D4249471

fbshipit-source-id: e18a93d85856c998576934a6229c9edd1638a54e

7 years agoAdd optional Tracepoint for RequestContext switch
Teng Qin [Wed, 30 Nov 2016 19:07:23 +0000 (11:07 -0800)]
Add optional Tracepoint for RequestContext switch

Summary: Using newly added `StaticTracepoint.h`, add a Tracepoint for `RequestContext` switch that could be enabled by compiler flag.

Reviewed By: drarmstr

Differential Revision: D4238658

fbshipit-source-id: 043a035ba8251b48d7b29d63a2219ad2edda164f

7 years agoAdd constexpr to the simple folly::Range accessors (begin, end, data, empty, etc)
Eric Niebler [Wed, 30 Nov 2016 03:42:04 +0000 (19:42 -0800)]
Add constexpr to the simple folly::Range accessors (begin, end, data, empty, etc)

Summary: More constexpr is better!

Reviewed By: yfeldblum, luciang, ot

Differential Revision: D4244996

fbshipit-source-id: 30a9b726c115a92bb18538d7f18e50eccb0a1ef6

7 years agoFix incorrect bytesWritten computation in AsyncSocket
Tiho Tarnavski [Tue, 29 Nov 2016 23:41:06 +0000 (15:41 -0800)]
Fix incorrect bytesWritten computation in AsyncSocket

Summary: If a write request is buffered after a partial write, then bytes written is not updated after subsequent write operations (`performWrite`) for the buffered write request (`BytesWriteRequest`). This results in a wrong value for totalBytesWritten_, which is reported in the error callback in case the write request fails.

Reviewed By: yfeldblum

Differential Revision: D4205743

fbshipit-source-id: f77ca55ccfdceda1008c45e72ec093b00bf250e4

7 years agoDisallow folly::Singletons before main()
Andrii Grynenko [Tue, 29 Nov 2016 23:34:43 +0000 (15:34 -0800)]
Disallow folly::Singletons before main()

Summary:
Make folly::Singleton fail if singleton is requested before registrationComplete. By doing this we disallow any folly::Singleton to be created before main().

Strict mode is still disabled for Python and Hs.

Reviewed By: yfeldblum

Differential Revision: D4121322

fbshipit-source-id: b66c23e24f6a7324cd12ddb77cad960e0950a1aa

7 years agoEscape backticks in shell script
Guo Xiao [Tue, 29 Nov 2016 20:30:16 +0000 (12:30 -0800)]
Escape backticks in shell script

Summary: Closes https://github.com/facebook/folly/pull/520

Reviewed By: pixelb

Differential Revision: D4243347

Pulled By: yfeldblum

fbshipit-source-id: cae0b36abdc7807afc188220f7f421f2a3bbc973

7 years agoSupport old LZ4 versions
Nick Terrell [Tue, 29 Nov 2016 19:37:10 +0000 (11:37 -0800)]
Support old LZ4 versions

Summary: D4194834 broke the OSS build.  Ubuntu 14.4 has r114 in its repo, so support it.

Reviewed By: yfeldblum

Differential Revision: D4224129

fbshipit-source-id: c85e95716ee1a08b33455bfe6fc9f7712d226edf

7 years agoUse std::terminate rather than throwing in a noexcept function
Christopher Dykes [Tue, 29 Nov 2016 05:23:33 +0000 (21:23 -0800)]
Use std::terminate rather than throwing in a noexcept function

Summary: Because MSVC isn't happy about it and generates a warning with a lot of context.

Reviewed By: yfeldblum

Differential Revision: D4242688

fbshipit-source-id: b1e26c9e3b58e7bac0e00ab8959358010fa610e8

7 years agofix bootstrap on osx
r8k [Mon, 28 Nov 2016 19:26:46 +0000 (11:26 -0800)]
fix bootstrap on osx

Summary:
* include all dependencies
 * update `autoconf` & `configure` with correct params
 * include `make` & `make install` in the bootstrap for a better user experience
 * fixes #332
Closes https://github.com/facebook/folly/pull/513

Reviewed By: yfeldblum

Differential Revision: D4177362

Pulled By: Orvid

fbshipit-source-id: c62d6633c382fca57bb06db08724a7355b71bdb3

7 years agoCanonicalize some aspects of the folly/experimental/hazptr test v2016.11.28.00
Yedidya Feldblum [Mon, 28 Nov 2016 06:02:48 +0000 (22:02 -0800)]
Canonicalize some aspects of the folly/experimental/hazptr test

Summary:
[Folly] Canonicalize some aspects of the `folly/experimental/hazptr` test.

* Remove the custom `main()` and use the provided weak symbol, either from `folly/test/common/TestMain.cpp` or from `gtest` depending on the build.
* Extract some common setup/teardown (just debug logging in this case) to a test fixture.

Reviewed By: Orvid

Differential Revision: D4234154

fbshipit-source-id: 25613cba0ad6c9147714d98150e013fba1a64d46

7 years agoFix termination output on GCC
Phil Willoughby [Sun, 27 Nov 2016 17:41:10 +0000 (09:41 -0800)]
Fix termination output on GCC

Summary:
Thanks nbronson for suggesting this fix. I don't see why this should make any
difference (and nor does clang) but the important thing is that it works now.

Reviewed By: nbronson

Differential Revision: D4212670

fbshipit-source-id: 08b4313d736f237039a807fbc458d4d581a2ef35

7 years agoAllow the use of an emulated futex for EventCount
Christopher Dykes [Fri, 25 Nov 2016 23:04:03 +0000 (15:04 -0800)]
Allow the use of an emulated futex for EventCount

Summary:
Otherwise it won't work under MSVC where we don't have Futexes.
This is achieved by using the Futex API already used elsewhere in Folly.

Reviewed By: yfeldblum

Differential Revision: D4233517

fbshipit-source-id: d6ae6a34b2287cf485f8e4a316445a2ba746d1a7

7 years agoRevert D4214296: [Folly] Include init/Init.cpp
Christopher Dykes [Fri, 25 Nov 2016 19:29:21 +0000 (11:29 -0800)]
Revert D4214296: [Folly] Include init/Init.cpp

Summary: This reverts commit 636ed5ae8ad36a323054efaad96d3756f1b7b9d0

Differential Revision: D4214296

fbshipit-source-id: 41fe55a8fcbf41cce44fee7ba65eda5aadbf97b3

7 years agoFix TFO refused case
Subodh Iyengar [Fri, 25 Nov 2016 05:18:22 +0000 (21:18 -0800)]
Fix TFO refused case

Summary:
When TFO falls back, it's possible that
the fallback can also error out.

We handle this correctly in AsyncSocket,
however because AsyncSSLSocket is so
inter-twined with AsyncSocket, we missed
the case of error as well.

This changes it so that a connect error on
fallback will cause a handshake error

Differential Revision: D4226477

fbshipit-source-id: c6e845e4a907bfef1e6ad1b4118db47184d047e0

7 years agoSuppress deprecation warnings in related tests
Yedidya Feldblum [Thu, 24 Nov 2016 22:56:49 +0000 (14:56 -0800)]
Suppress deprecation warnings in related tests

Summary:
[Folly] Suppress deprecation warnings in related tests.

When a test specifically exercises a marked-deprecated library or a marked-deprecated part of a library, we do not need to see the deprecation warnings - they are noise.

Specifically, `Singleton` and `Subprocess` have tested but marked-deprecated APIs, so we suppress deprecation warnings in those specific test suites.

Reviewed By: andrewjcg

Differential Revision: D4230826

fbshipit-source-id: 937b078029cde492906088caa3a9e5eee449bc12

7 years agoDon't expect .native() to return a string
Christopher Dykes [Wed, 23 Nov 2016 23:19:57 +0000 (15:19 -0800)]
Don't expect .native() to return a string

Summary: It's called `.native()` for a reason, and returns a `wstring` on windows, so call `string()` instead.

Reviewed By: yfeldblum

Differential Revision: D4229254

fbshipit-source-id: d5f9658b41f45fd719ca3e878a2e61c9dce24f10

7 years agoAdd USDT header file to folly
Teng Qin [Wed, 23 Nov 2016 22:05:39 +0000 (14:05 -0800)]
Add USDT header file to folly

Summary:
Derived from `sdt.h` in [[ https://sourceware.org/systemtap/ | SystemTap ]]
Performed changes and clean-ups including:
- Get rid of the `sdt-config.h`.
- Get rid of "Running in Assembler" code.
- Replace the `DTRACE_PROBE_1, ... DTRACE_PROBE_N` Macro family with a single Macro using the "count Macro arguments" trick
- Get rid of argument signed-ness calculation. A **lot** of painful code were there only for this, and it has no real usage except for displaying purposes.
- Re-structure the helper methods (Macros) so that the logic of the code is a bit more readable.
- Add some comments so that it would be easier for users and future developers to understand what this header file is actually doing.
- Update license banner.

Reviewed By: meyering

Differential Revision: D3792966

fbshipit-source-id: 564a1011f7946d30be78191f334e072d94fa264e

7 years agoClose sockets properly in the portability headers
Christopher Dykes [Wed, 23 Nov 2016 19:07:11 +0000 (11:07 -0800)]
Close sockets properly in the portability headers

Summary:
Even when linked against the dynamic runtime.
In truth, the old way was far cleaner, but we do need to be able to close the file descriptors as there is a hard global limit set by the CRT when it's compiled of 8k file descriptors.
This closes it by applying a flag that prevents calls to `CloseHandle` from actually closing the handle, then we call `_close` to get the file descriptor itself closed, then we can call `_closesocket` to close the socket and handle.
This is complicated by the fact that attempting to close a handle that you've marked as being prevented from being closed will trigger an SEH exception, but only if you have a debugger attached. That means that, for anything closing sockets to be debuggable, we have to handle that exception (as a no-op) and then get to have fun trying to get `STATUS_HANDLE_NOT_CLOSABLE`, which for some absurd reason, is only defined as part of the driver developer kit's headers. Some fun ensued where VS was nice enough to point out that the bcrypt headers also defines `NTSTATUS`, and doesn't require building as a driver to use it. For that reason we borrow its definition of `NTSTATUS` rather than declaring it ourselves.
We also have to prevent the main windows headers from defining the base SEH exceptions, because those will be redefined by `ntstatus.h` otherwise :(

Reviewed By: yfeldblum

Differential Revision: D4222625

fbshipit-source-id: 6ed7e91b7a735b5506eb189e452983cd8cace34b

7 years agoSuppress some aborts in debug mode when using already closed file descriptors
Christopher Dykes [Wed, 23 Nov 2016 18:43:24 +0000 (10:43 -0800)]
Suppress some aborts in debug mode when using already closed file descriptors

Summary: The helper exists because MSVC is a pain in this regard, so use it.

Reviewed By: yfeldblum

Differential Revision: D4224037

fbshipit-source-id: 6c6415877785f13ea91618a3042f2470dccd08c1

7 years agoFix fibers gdb utils script
Stepan Palamarchuk [Tue, 22 Nov 2016 22:39:34 +0000 (14:39 -0800)]
Fix fibers gdb utils script

Summary:
There was a recent change in boost compatibility that changed fibers internals and thus broke this script.
This diff fixes gdb script to properly print stack trace for fibers.

Reviewed By: yfeldblum

Differential Revision: D4214575

fbshipit-source-id: 4bf69e9b297c7539a2b2b71093998c30d6a2d81c

7 years agoTweak zstd autoconf check so the build works with older zstd
Lovro Puzar [Tue, 22 Nov 2016 18:45:34 +0000 (10:45 -0800)]
Tweak zstd autoconf check so the build works with older zstd

Summary: Ubuntu 16.10 has a package for zstd 0.5.1 which is too old to be used by folly.  With this change autoconf will check that one of the newer functions is present, disable zstd if not.

Reviewed By: Orvid, philippv

Differential Revision: D4219964

fbshipit-source-id: 1e64dfb62f81f7e61b097cb7d4fd3810da476625

7 years agoCorrectly bind to the wildcard address in AsyncServerSocket::bind
Christopher Dykes [Tue, 22 Nov 2016 17:48:18 +0000 (09:48 -0800)]
Correctly bind to the wildcard address in AsyncServerSocket::bind

Summary: Because Windows disagrees with everything else about how to specify that you want the wildcard address. It's done with an empty string on Windows, but `nullptr` everywhere else.

Reviewed By: yfeldblum

Differential Revision: D4216970

fbshipit-source-id: b5dc136946d9677a96be3252e44d383a6abca800

7 years agoWork around an MSVC expression SFINAE bug in DynamicParser
Christopher Dykes [Mon, 21 Nov 2016 23:40:54 +0000 (15:40 -0800)]
Work around an MSVC expression SFINAE bug in DynamicParser

Summary: The good news is that it's cleaner than it was to start with.

Reviewed By: yfeldblum

Differential Revision: D4215323

fbshipit-source-id: 6758092f1e76f60b360753026bb7716737a51304

7 years agoDisable the DoubleRegistrationLogging singleton test under MSVC
Christopher Dykes [Mon, 21 Nov 2016 23:39:27 +0000 (15:39 -0800)]
Disable the DoubleRegistrationLogging singleton test under MSVC

Summary: It's the only test in the file that is dependent on Subprocess, which is currently unsupported under MSVC.

Reviewed By: yfeldblum

Differential Revision: D4214812

fbshipit-source-id: 9dcd9763b51d037e0c452f79f134df286a11e718

7 years agoInclude init/Init.cpp
Zach Amsden [Mon, 21 Nov 2016 22:42:11 +0000 (14:42 -0800)]
Include init/Init.cpp

Summary: Anything calling folly::init() will not link with open source build

Reviewed By: yfeldblum

Differential Revision: D4214296

fbshipit-source-id: 636ed5ae8ad36a323054efaad96d3756f1b7b9d0

7 years agoWorkaround a bug resolving decltype'd locals in lambdas v2016.11.21.00
Christopher Dykes [Sat, 19 Nov 2016 05:34:19 +0000 (21:34 -0800)]
Workaround a bug resolving decltype'd locals in lambdas

Summary:
Then it's time to get food.
The bug report linked in the comment has more details.

Reviewed By: yfeldblum

Differential Revision: D4209389

fbshipit-source-id: 87e72691555992bdf964b0ded1173daadcedffa4

7 years agoDon't explicitly alias dynamic after using the entire folly namespace
Christopher Dykes [Sat, 19 Nov 2016 04:56:29 +0000 (20:56 -0800)]
Don't explicitly alias dynamic after using the entire folly namespace

Summary: Because, to the best of my knowledge, MSVC is quite right to claim it doesn't know which `dynamic` everyone keeps referring to. Is it `folly::dynamic` or `::dynamic`?

Reviewed By: yfeldblum

Differential Revision: D4209535

fbshipit-source-id: 63322a8f960954e1a63fe5c9a4a5d9395c7827d9

7 years agoUse the GTest portability header in shell_test
Christopher Dykes [Sat, 19 Nov 2016 02:35:02 +0000 (18:35 -0800)]
Use the GTest portability header in shell_test

Summary: It was including gtest directly, making MSVC unhappy.

Reviewed By: yfeldblum

Differential Revision: D4208744

fbshipit-source-id: 7100058f3c9fde38744888c99e927c610f11d013

7 years agoDon't attempt to separately close the underlying file descriptor in the format other...
Christopher Dykes [Sat, 19 Nov 2016 01:54:36 +0000 (17:54 -0800)]
Don't attempt to separately close the underlying file descriptor in the format other test

Summary: Windows automatically closes the underlying file descriptor when you call fclose, however fclose is not a function that can be easily overriden in the portability layer, so choose to just not call `close` on Windows instead.

Reviewed By: yfeldblum

Differential Revision: D4190524

fbshipit-source-id: a68edccd04e63f89c178ade584fa7192845773f8

7 years agoUse structs rather than type aliases for Unit::Lift and Unit::Drop
Christopher Dykes [Sat, 19 Nov 2016 01:53:37 +0000 (17:53 -0800)]
Use structs rather than type aliases for Unit::Lift and Unit::Drop

Summary:
VS 2017 RC brings with it fixes for some things and unfortunately, a few known regressions in expression SFINAE. In this case, alias templates with dependent `decltype()` calls are broken, so switch to a templated struct instead.
It's the very last issue mentioned in: https://blogs.msdn.microsoft.com/vcblog/2016/06/07/expression-sfinae-improvements-in-vs-2015-update-3/

Reviewed By: yfeldblum

Differential Revision: D4199676

fbshipit-source-id: 9ce157cc891182509a30b000de1b509063387244

7 years agoSynchronized: disable operator= when the type isn't copy assignable
Maxime Boucher [Sat, 19 Nov 2016 00:53:50 +0000 (16:53 -0800)]
Synchronized: disable operator= when the type isn't copy assignable

Summary: The value of std::is_copy_assignable<folly::Synchronized<T>>::value is incorrect when T isn't copy assignable. As a result, it isn't possible to use SFINAE to properly select a function when the base type is a folly::Synchronized. This diff selectively deletes the copy constructor and copy assignment operator when the underlying type T isn't copyable. This is most useful in the case of folly::Synchronized<std::unique_ptr<...>>

Reviewed By: yfeldblum

Differential Revision: D4203081

fbshipit-source-id: 1e811f9e52db26c23b1c6f1907bac9e2854ddb9d

7 years agoDisable a range test under MSVC
Christopher Dykes [Fri, 18 Nov 2016 23:07:58 +0000 (15:07 -0800)]
Disable a range test under MSVC

Summary: Because, as the comment says, MSVC fails miserably at this, producing errors at compile time.

Reviewed By: yfeldblum

Differential Revision: D4207544

fbshipit-source-id: d9a11b72877d22d3d3fe2e2c862d99601ab21431

7 years agoExpose folly::symbolizer::dumpStackTrace().
Martin Martin [Fri, 18 Nov 2016 17:59:37 +0000 (09:59 -0800)]
Expose folly::symbolizer::dumpStackTrace().

Summary:
Expose folly::symbolizer::dumpStackTrace() for use with
custom signal handlers.

Reviewed By: luciang

Differential Revision: D4174004

fbshipit-source-id: 510b77edef652f3e9d10f0acfb4998b64a15fad5

7 years agoExplain crash when exception is thrown from Scope Guard
Phil Willoughby [Fri, 18 Nov 2016 16:08:19 +0000 (08:08 -0800)]
Explain crash when exception is thrown from Scope Guard

Summary:
Print a message to `std::cerr` when the current program is about to call `std::terminate` because a `folly::ScopeGuard` callback threw an exception. This goes to `std::terminate` in the (common) cases when the `ScopeGuard` destructor is `noexcept`

This gives the user a small clue as to what just happened, since the default diagnostics for this on some platforms do not help at all.

Reviewed By: nbronson

Differential Revision: D4061096

fbshipit-source-id: c3b534d4a36b095e08e46f375251b6fd416ccd68

7 years agoforce read for doNotOptimizeAway(*ptr_to_small_trivial)
Nathan Bronson [Fri, 18 Nov 2016 16:07:09 +0000 (08:07 -0800)]
force read for doNotOptimizeAway(*ptr_to_small_trivial)

Summary:
doNotOptimizeAway's "X" input operand constraint is interpreted
more loosely by gcc than by clang, resulting in surprising behavior
for doNotOptimizeAway(*ptr) and a difference in behavior between gcc
and clang benchmarks.  clang also is more aggressive about placing an
input operand into a register even when the constraint would allow it to
be in memory, so an "r,m" constraint has a similar problem.  This diff
changes the input constraint so that register-sized values must actually
be copied into a register, which makes the behavior more intuitive and
more consistent across platforms.

Reviewed By: davidtgoldblatt

Differential Revision: D4199767

fbshipit-source-id: aa56a7b11cb3229b95da87295f0dfc38476959d2

7 years agoFix Build: folly with -Wmissing-braces
Yedidya Feldblum [Fri, 18 Nov 2016 07:01:42 +0000 (23:01 -0800)]
Fix Build: folly with -Wmissing-braces

Summary:
[Folly] Fix Build: `folly` with `-Wmissing-braces`.

Construction of `std::array` with list-initialization for the contained C array requires double braces, per the standard.

Compilers accept it with single braces, but will reject it when `-Wmissing-braces` is passed.

Reviewed By: igorsugak, meyering

Differential Revision: D4202629

fbshipit-source-id: e5b87a655e7f25e6cddb931dda28b172c768f227

7 years agofolly/portability: move some macro definitions to `CPortability.h`
Andrew Gallagher [Fri, 18 Nov 2016 05:16:07 +0000 (21:16 -0800)]
folly/portability: move some macro definitions to `CPortability.h`

Summary: These macros apply to both C and C++.

Reviewed By: yfeldblum

Differential Revision: D4199905

fbshipit-source-id: 8dc22959d0a6349c6c76415d1a38eda52cab83a5

7 years agoFaster unhexlify
Tom Jackson [Fri, 18 Nov 2016 02:14:14 +0000 (18:14 -0800)]
Faster unhexlify

Summary:
Using already-available lookup table instead of a bunch of branching, this improves read throughput from ~750MB/s to 2.1GB/s in benchmarks.

```
before:        (time)   (rate)
BM_unhexlify   1.39ns  719.26M
after:
BM_unhexlify 470.59ps    2.13G
```

Reviewed By: philippv

Differential Revision: D4201352

fbshipit-source-id: 8393e066c45c402ccb8b537fdb25417e8e6a9511

7 years agoDon't rely on implicit lookup of member names in dependent base classes
Christopher Dykes [Fri, 18 Nov 2016 00:30:31 +0000 (16:30 -0800)]
Don't rely on implicit lookup of member names in dependent base classes

Summary:
The standard says this shouldn't be done, but GCC, Clang, and MSVC all do, at least, MSVC does if you don't pass the `/permissive-` switch to disable this non-compliant lookup.
This just qualifies it with `this->` which solves the problem.

MSVC plans to eventually (some time after the 2017 release) enable `/permissive-` by default, so let's start compiling with it now.

Reviewed By: yfeldblum

Differential Revision: D4200725

fbshipit-source-id: 8545c6bcda9ba6006733c15f668805cb1260517a

7 years agoInclude atomic in SingletonTestStructs.cpp
Christopher Dykes [Fri, 18 Nov 2016 00:30:12 +0000 (16:30 -0800)]
Include atomic in SingletonTestStructs.cpp

Summary: This was relying on it being transitively included by system headers, which isn't the case under MSVC.

Reviewed By: yfeldblum

Differential Revision: D4199882

fbshipit-source-id: c25dc1e86687e19851923a1a660a91bcf63f0e6d

7 years agoMark a couple more local constexpr values as static
Christopher Dykes [Fri, 18 Nov 2016 00:29:09 +0000 (16:29 -0800)]
Mark a couple more local constexpr values as static

Summary: Because MSVC doesn't let you access it without capturing it from within a lambda otherwise.

Reviewed By: yfeldblum

Differential Revision: D4199867

fbshipit-source-id: 7b829b2cc373edbebe3498901fa323c89a211818

7 years agoUpdate AtomicHashMap.md
Srinivas \"Teja\" Rao [Thu, 17 Nov 2016 22:55:03 +0000 (14:55 -0800)]
Update AtomicHashMap.md

Summary:
it seems second is the boolean that we need to compare.
Closes https://github.com/facebook/folly/pull/518

Differential Revision: D4197096

Pulled By: yfeldblum

fbshipit-source-id: 71987dafac0ddbdb7817b55732619edbe9aed81b

7 years agoReplace deprecated LZ4 functions
Nick Terrell [Thu, 17 Nov 2016 21:18:48 +0000 (13:18 -0800)]
Replace deprecated LZ4 functions

Summary:
Replace deprecated functions with their functionally equivalent counterparts.

See https://github.com/lz4/lz4/blob/dev/lib/lz4.c#L1405 and https://github.com/lz4/lz4/blob/dev/lib/lz4hc.c#L634

Reviewed By: Cyan4973

Differential Revision: D4194834

fbshipit-source-id: aa4f934c46fe764fcec8ea29221e3882da2b5cdf

7 years agoVirtualEventBase
Andrii Grynenko [Thu, 17 Nov 2016 20:44:52 +0000 (12:44 -0800)]
VirtualEventBase

Summary:
This implements a view onto an EventBase, which can keep track of all tasks created through it and join them on destruction. Multiple VirtualEventBases can be backed by the same EventBase. This can be useful to have the same IO thread/thread-pool be shared between multiple libraries, allowing them to each have it's own VirtualEventBase and control its lifetime.

Since VirtualEventBase also supports LoopKeepAlive and onDestruction functionality, it can be easily integrated with FiberManagerMap.

Reviewed By: yfeldblum

Differential Revision: D4158719

fbshipit-source-id: 7df964f36e5276e2b5665fd8394ea2e187aa298c

7 years agofolly: ExceptionWrapper: remove <iostream> from header
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

7 years agoAdd folly::getCurrentThreadID()
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