folly.git
7 years agofix double comparison in histogram test
Adam Simpkins [Wed, 5 Jul 2017 19:56:00 +0000 (12:56 -0700)]
fix double comparison in histogram test

Summary:
The TestDoubleWidthTooBig test was performing an exact equality check on
two double values. This equality check fails when run on 32-bit
platforms.

Replace the EXPECT_EQ() check with EXPECT_NEAR(), and simply check that
the two values do not differ by more than 1e-14.

Reviewed By: Orvid

Differential Revision: D652767

fbshipit-source-id: 7bf7ed560a4180a2e2d07a6050d1df18e18d1eea

7 years agologging: fix compiler compatibility for one more constexpr function
Adam Simpkins [Wed, 5 Jul 2017 17:48:49 +0000 (10:48 -0700)]
logging: fix compiler compatibility for one more constexpr function

Summary:
Update LogLevel's operator+() to consist only of a single return statement.
This is required for pre-C++14 compiler support.

Reviewed By: yfeldblum

Differential Revision: D5368256

fbshipit-source-id: 9ecbcde5edd1d0b3e7580d6263ad926e44908219

7 years agoPromise<T>::makeEmpty() and Future<T>::makeEmpty()
Yedidya Feldblum [Wed, 5 Jul 2017 16:38:08 +0000 (09:38 -0700)]
Promise<T>::makeEmpty() and Future<T>::makeEmpty()

Summary:
[Folly] `Promise<T>::makeEmpty()` and `Future<T>::makeEmpty()`.

These can currently be done by creating, and then moving away from, regular promises and futures. But that allocates; this is semantically equivalent but more efficient.

Differential Revision: D5368339

fbshipit-source-id: de054cfc75c701c5d39aac64d9a2949cd34b1896

7 years agofolly/futures/detail/Core.h: avoid FP from clang's -Wconditional-uninitialized
Jim Meyering [Wed, 5 Jul 2017 06:56:54 +0000 (23:56 -0700)]
folly/futures/detail/Core.h: avoid FP from clang's -Wconditional-uninitialized

Summary:
Avoid this false positive from clang:

  folly/futures/detail/Core.h:369:15: error: variable 'priority' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]

Reviewed By: yfeldblum

Differential Revision: D5369916

fbshipit-source-id: 49649417d1b799cc3945cba456b42ab438ad2ddc

7 years agoApply clang-format to folly/stats/
Yedidya Feldblum [Tue, 4 Jul 2017 05:28:37 +0000 (22:28 -0700)]
Apply clang-format to folly/stats/

Summary: [Folly] Apply clang-format to `folly/stats/`.

Reviewed By: Orvid

Differential Revision: D5366745

fbshipit-source-id: 3b7419d4ab4c6203693603722cd8e707741d3953

7 years agoApply clang-format to folly/ssl/
Yedidya Feldblum [Tue, 4 Jul 2017 03:01:32 +0000 (20:01 -0700)]
Apply clang-format to folly/ssl/

Summary: [Folly] Apply `clang-format` to `folly/ssl/`.

Reviewed By: Orvid

Differential Revision: D5366760

fbshipit-source-id: ad4ec0570050f80d69c78626906e18b5892a999f

7 years agoApply clang-format to folly/concurrency/
Yedidya Feldblum [Tue, 4 Jul 2017 02:41:36 +0000 (19:41 -0700)]
Apply clang-format to folly/concurrency/

Summary: [Folly] Apply `clang-format` to `folly/concurrency/`.

Reviewed By: Orvid

Differential Revision: D5366946

fbshipit-source-id: 2c9de7c4d8534e02c367fd235fb1ea943ba0539e

7 years agoExtract the namespace choice in FBString.h
Yedidya Feldblum [Tue, 4 Jul 2017 01:57:07 +0000 (18:57 -0700)]
Extract the namespace choice in FBString.h

Summary:
[Folly] Extract the namespace choice in `FBString.h`.

The funny `namespace` bits confuse `clang-format`, so let us remove the confusion.

Reviewed By: ot, Orvid

Differential Revision: D5367299

fbshipit-source-id: efca65fecc70076829c14e31a835bc91f3efb4a4

7 years agoApply clang-format to folly/io/ (namespace)
Yedidya Feldblum [Tue, 4 Jul 2017 00:52:24 +0000 (17:52 -0700)]
Apply clang-format to folly/io/ (namespace)

Summary: [Folly] Apply `clang-format` to `folly/io/` (namespace).

Reviewed By: Orvid, terrelln

Differential Revision: D5366477

fbshipit-source-id: b4efcdc66c62885f5574b2940e5138590710deae

7 years agoFix tests in CMake build
Christopher Dykes [Tue, 4 Jul 2017 00:32:55 +0000 (17:32 -0700)]
Fix tests in CMake build

Summary: The fix for this didn't get made before the commit landed.

Reviewed By: yfeldblum

Differential Revision: D5367593

fbshipit-source-id: 4ed9c781121d1b23db11d75d0f8d017d1d8663d9

7 years agoFix build of SysUio portability header
Christopher Dykes [Mon, 3 Jul 2017 22:15:31 +0000 (15:15 -0700)]
Fix build of SysUio portability header

Summary: When I moved the change internally, I failed to add the `#include` that was required :(

Reviewed By: yfeldblum

Differential Revision: D5366037

fbshipit-source-id: 7ddf8fc0b7a0468d0831e886d8025c1893f7f8ae

7 years agoconstexpr the Unit comparison ops
Eric Niebler [Mon, 3 Jul 2017 21:13:27 +0000 (14:13 -0700)]
constexpr the Unit comparison ops

Summary: `constexpr` All The Things!

Reviewed By: Orvid

Differential Revision: D5364910

fbshipit-source-id: 11abeb8adc38aef3ac4f2596ecf0f533b9e74203

7 years agoFor futures::retrying, detect policy type using std::result_of
Yedidya Feldblum [Mon, 3 Jul 2017 20:20:29 +0000 (13:20 -0700)]
For futures::retrying, detect policy type using std::result_of

Summary:
[Folly] For `futures::retrying`, detect policy type using `std::result_of`.

`FOLLY_CREATE_HAS_MEMBER_FN_TRAITS` does not work in all cases. For example, it does not work with inherited members.

And it is not really what we want, anyway, which is to dispatch based on the result type of invoking the policy with a particular set of arguments. We can do that more directly using `std::result_of`. And if we did not have `std::result_of`, then we could do that with SFINAE directly.

Reviewed By: WillerZ

Differential Revision: D5361808

fbshipit-source-id: 23f969dfd6dbaaa944dc2288e70c3ea11d3398f0

7 years agoContent-conversion constructors for Future
Phil Willoughby [Mon, 3 Jul 2017 12:55:21 +0000 (05:55 -0700)]
Content-conversion constructors for Future

Summary:
Allows you to construct a `Future<A>` from a `Future<B>` if A can be constructed from `B&&`.

The constructor is `implicit` if and only if `B&&` is convertible to `A`.

This is the same philosophy as Optional, and has the same use-cases.

Reviewed By: yfeldblum

Differential Revision: D5264185

fbshipit-source-id: e2fae373ab549c186a69dc5f4e32481ef7b11bba

7 years agoReplace folly::asm_pause with folly::asm_volatile_pause v2017.07.03.00
Christopher Dykes [Mon, 3 Jul 2017 04:20:10 +0000 (21:20 -0700)]
Replace folly::asm_pause with folly::asm_volatile_pause

Summary: There is no difference, as the statements are already implicitly volatile.

Reviewed By: yfeldblum

Differential Revision: D5363491

fbshipit-source-id: ab5bb878f5ca72aa0de96f82e345213729c071e2

7 years agoIn-place construction for Try
Yedidya Feldblum [Sun, 2 Jul 2017 17:22:35 +0000 (10:22 -0700)]
In-place construction for Try

Summary:
[Folly] In-place construction for `Try`.

Using `in_place` as the first argumenbt. Avoid move operations.

Reviewed By: Orvid

Differential Revision: D5362568

fbshipit-source-id: 5c2aaf5dba1253c59e384940add411f0f2b570b2

7 years agoIn-place construction for Optional
Yedidya Feldblum [Sun, 2 Jul 2017 17:22:33 +0000 (10:22 -0700)]
In-place construction for Optional

Summary:
[Folly] In-place construction for `Optional`.

Using `in_place` as the first argument. Avoid move operations.

Reviewed By: Orvid, ot

Differential Revision: D5362563

fbshipit-source-id: 771db2556842d5dec35d1bf2ad6c23358a417d54

7 years agoMove in_place and friends to Utility.h
Yedidya Feldblum [Sun, 2 Jul 2017 17:22:31 +0000 (10:22 -0700)]
Move in_place and friends to Utility.h

Summary:
[Folly] Move `in_place` and friends to `Utility.h`.

Document that they are backports from C++17.

Reviewed By: Orvid

Differential Revision: D5362364

fbshipit-source-id: 495cb7f339fc558f20d89100c141fc7a243239d5

7 years agoRemove construct_in_place
Yedidya Feldblum [Sun, 2 Jul 2017 17:22:29 +0000 (10:22 -0700)]
Remove construct_in_place

Summary:
[Folly] Remove `construct_in_place`.

It is an alias for `in_place`, and unnecessary.

Reviewed By: Orvid

Differential Revision: D5362354

fbshipit-source-id: 39ce07bad87185e506fe7d780789b78060008182

7 years agoDisambiguate the various in_place overloads, following C++17
Yedidya Feldblum [Sun, 2 Jul 2017 17:22:27 +0000 (10:22 -0700)]
Disambiguate the various in_place overloads, following C++17

Summary:
[Folly] Disambiguate the various `in_place` overloads, following C++17.

Forwarding `folly::in_place` is ambiguous because there are multiple overloads and we depend on deduction to choose the correct overload. For example:

```lang=c++
enum struct Err {};
Expected<Expected<int, Err>, Err> val(in_place, in_place, 3); // fails to compile
```

So we must disambiguate the three overloads: the default, the typed, and the indexed.

C++17 defines `std::in_place`, `std::in_place_type<typename>`, and `std::in_place_index<std::size_t>`. Let us mimic that exactly, so that it becomes trivial to swap out our implementations for the standard implementations once we jump to C++17.

Reviewed By: Orvid

Differential Revision: D5362339

fbshipit-source-id: d4012b01796390e74d8c14cdf68af70102608039

7 years agoDon't attempt to lock the file descriptor in readv/writev if it's a socket
Christopher Dykes [Sun, 2 Jul 2017 06:50:37 +0000 (23:50 -0700)]
Don't attempt to lock the file descriptor in readv/writev if it's a socket

Summary:
There is no way to lock a socket on Windows, so these calls will always fail. Just don't do the lock on Windows.
To do it properly with sockets, this should probably be forwarding to `sendmsg`/`recvmsg`, but this is good enough for now.

Reviewed By: simpkins

Differential Revision: D5307901

fbshipit-source-id: 9855274e932a3e2ec3cacae10363200187e0c01b

7 years agoEnable a missing test in the CMake build
Christopher Dykes [Sat, 1 Jul 2017 03:17:55 +0000 (20:17 -0700)]
Enable a missing test in the CMake build

Summary: This also silences a few warnings in the stl vector tests.

Reviewed By: yfeldblum

Differential Revision: D5350383

fbshipit-source-id: 84df2a7dbfbb23ebb3f15a09f0cb58080b3e06d6

7 years agoFix undefined warning errors
Nate Stedman [Sat, 1 Jul 2017 01:01:42 +0000 (18:01 -0700)]
Fix undefined warning errors

Summary: Xcode 9 is throwing errors because `-Wshadow-local` and `-Wshadow-compatible-local` are undefined in Clang.

Reviewed By: Orvid

Differential Revision: D5356476

fbshipit-source-id: 4cc9f48f796f66decb4beaa66d3e66f486449c19

7 years agoDrop std::max_align_t hack present for GCC 4.8
Christopher Dykes [Fri, 30 Jun 2017 23:20:37 +0000 (16:20 -0700)]
Drop std::max_align_t hack present for GCC 4.8

Summary: Folly no longer supports GCC 4.8, so this is no longer needed.

Reviewed By: yfeldblum

Differential Revision: D5354542

fbshipit-source-id: bd9a2732f22f2176f64f92f0af6f7d59dd59a8d9

7 years agoauto-dep the rest of Folly
Christopher Dykes [Fri, 30 Jun 2017 22:18:55 +0000 (15:18 -0700)]
auto-dep the rest of Folly

Summary: This is so we can do some magic internally.

Reviewed By: yfeldblum

Differential Revision: D5354341

fbshipit-source-id: 96abf92f4765f5ae21aa3c0dc4bcadcc22560ab5

7 years agoDon't try to access XlogFileScopeInfo->category if not supported
Adam Simpkins [Fri, 30 Jun 2017 19:36:56 +0000 (12:36 -0700)]
Don't try to access XlogFileScopeInfo->category if not supported

Summary: This was breaking Windows builds.

Reviewed By: Orvid

Differential Revision: D5351468

fbshipit-source-id: 3385931b82b11d71d98861fb45efc71a632d470b

7 years agoUse #warning rather than #warn
Christopher Dykes [Fri, 30 Jun 2017 18:19:54 +0000 (11:19 -0700)]
Use #warning rather than #warn

Summary: Because `#warn` isn't actually a thing.

Reviewed By: ot

Differential Revision: D5356878

fbshipit-source-id: 57751ca57e7f6aaf9f4d8be70958b9cacc4f7335

7 years agoRemove the now dead StringBase.cpp
Christopher Dykes [Fri, 30 Jun 2017 17:52:18 +0000 (10:52 -0700)]
Remove the now dead StringBase.cpp

Summary: The empty file was left to stop the bleeding without breaking things. Time to remove it.

Reviewed By: mzlee

Differential Revision: D5354310

fbshipit-source-id: cd3039811cf9d7371578e4078cd7d32e3bc6d8a1

7 years agoFlat combining: Fix typos in comments
Maged Michael [Fri, 30 Jun 2017 12:27:49 +0000 (05:27 -0700)]
Flat combining: Fix typos in comments

Summary: reserved

Reviewed By: djwatson

Differential Revision: D5352232

fbshipit-source-id: e3c27e22320e12bd635acb8a1b394a9de02cecfc

7 years agoHazard pointers: Fix leak in hazptr_priv destruction
Maged Michael [Fri, 30 Jun 2017 04:21:32 +0000 (21:21 -0700)]
Hazard pointers: Fix leak in hazptr_priv destruction

Summary:
- Fixed leak in hazptr_priv destruction
- Updated tests to detect leak

Reviewed By: djwatson

Differential Revision: D5351280

fbshipit-source-id: 724810cbbe0565f0cbd41f9d2121abefd98487bd

7 years agoMerge StringBase.cpp into String.cpp
Christopher Dykes [Fri, 30 Jun 2017 03:13:49 +0000 (20:13 -0700)]
Merge StringBase.cpp into String.cpp

Summary: It doesn't need to exist anymore

Reviewed By: yfeldblum

Differential Revision: D5318746

fbshipit-source-id: c70b184f4b3fc12ede4632d6b3d43de16ed758c7

7 years agologging: support building with gcc-4.9
Adam Simpkins [Thu, 29 Jun 2017 21:45:09 +0000 (14:45 -0700)]
logging: support building with gcc-4.9

Summary:
Versions of gcc prior to 5.x only support C++11 constexpr functions, and
require that they consist of only a single return statement.

This updates isLogLevelFatal() to meet those requirements so that it can still
be compiled with gcc 4.9.

Reviewed By: ikobzar

Differential Revision: D5350304

fbshipit-source-id: 2a9c256236c484f8c3d5f83690fde8b7333aa4fc

7 years agoRemoving memory leaks in rsa setter test
Ankit Shah [Thu, 29 Jun 2017 20:24:19 +0000 (13:24 -0700)]
Removing memory leaks in rsa setter test

Summary:
Using RSA free and removing unnecessary Bignum allocations to prevent
test failures due to memory leaks

Reviewed By: anirudhvr

Differential Revision: D5348232

fbshipit-source-id: 7c76f3dced26a3080fc82b4bacc06bc0768d6fda

7 years agoHazard pointers: Add support for thread local lists of retired objects and other...
Maged Michael [Thu, 29 Jun 2017 14:16:37 +0000 (07:16 -0700)]
Hazard pointers: Add support for thread local lists of retired objects and other optimizations

Summary:
- Add support for private lists of retired objects
- Add an option for one domain
- More scalable thread cache managemnt
- hazptr_rec alignment
- FOLLY_ALWAYS_INLINE
- Refactor management of retired objects in hazptr_domain
- Refactor benchmarks

Reviewed By: davidtgoldblatt

Differential Revision: D5322646

fbshipit-source-id: 9d31582b9a8216861e7e78e2e1cd08dc11cf7f88

7 years agoRemove dependency on Conv.h from FileUtil.h
Andrew Krieger [Thu, 29 Jun 2017 00:12:01 +0000 (17:12 -0700)]
Remove dependency on Conv.h from FileUtil.h

Summary: So we can use writeFile in projects which compile with -fno-rtti

Reviewed By: mzlee

Differential Revision: D5341469

fbshipit-source-id: bb77baf9576604ff862d54d59bf382862bd0dd58

7 years agoAdd `mode` parameter to FileUtil.h writeFile
Andrew Krieger [Wed, 28 Jun 2017 23:42:40 +0000 (16:42 -0700)]
Add `mode` parameter to FileUtil.h writeFile

Summary:
writeFileAtomic variants all have a mode, lets just hoist the mode parameter
up and use what was hardcoded as the default.

Reviewed By: Orvid

Differential Revision: D5341481

fbshipit-source-id: 6976915dd73d2382b42bd991782730601b918978

7 years agoMove CacheLocality out of detail/ and into concurrency/
Giuseppe Ottaviano [Wed, 28 Jun 2017 18:09:42 +0000 (11:09 -0700)]
Move CacheLocality out of detail/ and into concurrency/

Summary: There's no reason these utilities should only be used by folly.

Reviewed By: mzlee

Differential Revision: D5317894

fbshipit-source-id: 5a9bdf4c5efaa5bcbe78e6723a03a468f2fe5e32

7 years agoAdding getter and setter methods for RSA
Ankit Shah [Wed, 28 Jun 2017 15:25:32 +0000 (08:25 -0700)]
Adding getter and setter methods for RSA

Summary:
Added getter and setter methods for the RSA struct in OpenSSL. This is
needed for compatibility between OpenSSl 1.1.0 and other versions.

Reviewed By: yfeldblum

Differential Revision: D5331948

fbshipit-source-id: ab52ffd38bb5e0bd59e058bcbc6ec6122839844e

7 years agoShift Future::then and Future::thenMulti into the class definition
Christopher Dykes [Wed, 28 Jun 2017 00:29:12 +0000 (17:29 -0700)]
Shift Future::then and Future::thenMulti into the class definition

Summary:
GCC 7 has issues with `this->` in trailing return type declarations. This takes the approach of eliminating the trailing return types entirely.

Closes https://github.com/facebook/folly/pull/621

Reviewed By: yfeldblum

Differential Revision: D5324763

fbshipit-source-id: e38ae76c13ff60bc227146c1ec25afbac8b6982f

7 years agoFixes for Try::withException
Yedidya Feldblum [Tue, 27 Jun 2017 21:27:31 +0000 (14:27 -0700)]
Fixes for Try::withException

Summary:
[Folly] Fixes for `Try::withException`.

* Fix the overload with the exception type specified so that the specified exception type is checked. A mismatch between the specified exception type and the parameter type of the passed invokable will result in the expected compiler error.
* Add an overload where the exception type is deduced intentionally, as opposed to accidentally.

Of course, these simply forward to their corresponding `exception_wrapper::withException` overloads.

Reviewed By: ericniebler

Differential Revision: D5216691

fbshipit-source-id: 7e85c906c3aa17dfede6e0980c6ac8bf75034073

7 years agoMove folly/experimental/AtomicSharedPtr.h -> folly/concurrency/AtomicSharedPtr.h
Dave Watson [Tue, 27 Jun 2017 19:09:05 +0000 (12:09 -0700)]
Move folly/experimental/AtomicSharedPtr.h -> folly/concurrency/AtomicSharedPtr.h

Summary: As title.

Reviewed By: WillerZ, yfeldblum, ivmaykov

Differential Revision: D5312308

fbshipit-source-id: 91ad4bb39df0619f2885e13c1fda1e018292a40e

7 years agoallow AsyncSignalHandler to attach and detach from an EventBase
Adam Simpkins [Tue, 27 Jun 2017 02:27:32 +0000 (19:27 -0700)]
allow AsyncSignalHandler to attach and detach from an EventBase

Summary:
Add attachEventBase() and detachEventBase() methods to AsyncSignalHandler,
similar to the methods of AsyncSocket.

The main benefit of this is that it allows creating an AsyncSignalHandler with
an initially null EventBase, and then attaching it to an EventBase at some
later point in time.

Reviewed By: yfeldblum

Differential Revision: D5315325

fbshipit-source-id: 8a4ca483a62ca86837ea0bb54fa9a70d59f2f04e

7 years agomake io::Cursor::push() safe to call with an empty ByteRange
Adam Simpkins [Tue, 27 Jun 2017 02:15:05 +0000 (19:15 -0700)]
make io::Cursor::push() safe to call with an empty ByteRange

Summary:
Clang's UndefinedBehaviorSanitizer flagged an issue that pushAtMost() could
call `memcpy(dest, nullptr, 0)` if the input was an empty `ByteRange`.  A
default constructed `ByteRange` (or `StringPiece`) will be empty and both its
begin and end pointers will be null.  Unfortunately it is undefined behavior to
call `memcpy()` with a null source pointer even if the length is 0.

This updates the `Cursor` and `Appender` code to avoid calling `memcpy()` at
all when the input length is 0.

Reviewed By: yfeldblum

Differential Revision: D5322917

fbshipit-source-id: 67fce9579f97e7e93a5767b11cc5e43ff7be5876

7 years agoImprove Format's handling of temporaries
Giuseppe Ottaviano [Mon, 26 Jun 2017 21:42:31 +0000 (14:42 -0700)]
Improve Format's handling of temporaries

Summary:
`FormatValue` holds non-integral objects by reference, which
can cause subtle problems if a formatter is constructed with temporary
arguments and used beyond the expression that constructs it.

With this diff the arguments are perfectly forwarded into a tuple, so
the formatter will take ownership of the temporaries while holding
references to lvalues as before.

The only downside is that now `FormatValue` objects are constructed
every time the formatter is used, rather than only at formatter
construction. This should not be noticeable as those objects'
constructors should just take a reference to the argument.

Note that the format string is still held by reference, but this is
fine because it should almost always be a string literal.

Reviewed By: ericniebler

Differential Revision: D5317382

fbshipit-source-id: ef8355194b634d3751ef1ccca32dd1db29e27c48

7 years agoSupport marking a file-descriptor as blocking via fcntl
Christopher Dykes [Mon, 26 Jun 2017 21:39:26 +0000 (14:39 -0700)]
Support marking a file-descriptor as blocking via fcntl

Summary: Previously, only marking it as non-blocking was supported.

Reviewed By: simpkins

Differential Revision: D5307769

fbshipit-source-id: 03ed7c35632dbc9551552b21c401ea709bd6eaaa

7 years agoEdited folly synchronized doc because one of the functions was incorrect
Marie Bremner [Mon, 26 Jun 2017 21:21:01 +0000 (14:21 -0700)]
Edited folly synchronized doc because one of the functions was incorrect

Summary: Edited the example function for withWLock

Reviewed By: simpkins

Differential Revision: D5322000

fbshipit-source-id: 6d95b173087dec33cfdc0d0cee9c605cdf4e2593

7 years agoLet make_exception_wrapper construct on-heap objects in-place
Yedidya Feldblum [Mon, 26 Jun 2017 20:22:19 +0000 (13:22 -0700)]
Let make_exception_wrapper construct on-heap objects in-place

Summary:
[Folly] Let `make_exception_wrapper` construct on-heap objects in-place.

Currently, it constructs on-heap objects on the stack and then move-constructs them into on-heap storage.

Reviewed By: ericniebler

Differential Revision: D5315104

fbshipit-source-id: cc0493e7d98aacadd342eb56601028ced4a19bb3

7 years agoFix SharedPromise::isFulfilled doesn't get back correct value when it's running in...
Bi Xue [Mon, 26 Jun 2017 19:19:40 +0000 (12:19 -0700)]
Fix SharedPromise::isFulfilled doesn't get back correct value when it's running in a different thread of SharedPromise::setValue

Summary: The implementation of `SharedPromise::isFulfilled` return `hasValue_` directly without taking a lock. `isFulfilled` can be accessed concurrently, but `hasValue_` is not synchronized. Adding a lock fix the issue.

Reviewed By: yfeldblum

Differential Revision: D5319030

fbshipit-source-id: a94b12ed277aa64254680ae84cb18946226cceea

7 years agoResolve the circular dependency between ThreadLocalDetail and ThreadLocal
Christopher Dykes [Mon, 26 Jun 2017 18:42:42 +0000 (11:42 -0700)]
Resolve the circular dependency between ThreadLocalDetail and ThreadLocal

Summary: There was a circular dependency between the `detail/ThreadLocalDetail.(cpp|h)` files and `ThreadLocal.(cpp|h)`, this resolves that circular dependency by moving a couple of declarations into the detail file.

Reviewed By: yfeldblum

Differential Revision: D5318875

fbshipit-source-id: 61de7c4b3ffa30f9eb11bd97e0493e9de12c5804

7 years agoRevert D5312574: [folly] Fix up and namespace clock_gettime and clock_getres for... v2017.06.26.01
Christopher Dykes [Mon, 26 Jun 2017 17:25:00 +0000 (10:25 -0700)]
Revert D5312574: [folly] Fix up and namespace clock_gettime and clock_getres for MacOS

Summary: This reverts commit f16634ce92ee6c299613d3db22f0537bd31ac14d

Differential Revision: D5312574

fbshipit-source-id: 1557ac17f79fb8e3530a09d69fa978ddd38e5093

7 years agoImprove efficiency of trivial toDelim calls
Phil Willoughby [Mon, 26 Jun 2017 14:08:25 +0000 (07:08 -0700)]
Improve efficiency of trivial toDelim calls

Summary:
`toDelim` with a single parameter of the same type as the target type was
previously copy-constructing its result. It will now construct it with perfect
forwarding which is more efficient if the input is a temporary.

This brings `toDelim` into line with the similar implementations of `to` and
`tryTo`

Reviewed By: yfeldblum

Differential Revision: D5301427

fbshipit-source-id: 843a2d93384de88cce42f26da6562a1a6ed0dc9c

7 years agoExplicitly specify that timezone is a struct v2017.06.26.00
Christopher Dykes [Sun, 25 Jun 2017 00:00:32 +0000 (17:00 -0700)]
Explicitly specify that timezone is a struct

Summary: In the parameter declarations for the `gettimeofday` portability header implementation. More details on exactly why can be found in the newly added comment on the function.

Reviewed By: yfeldblum

Differential Revision: D5281301

fbshipit-source-id: 1b246adc7743b5470201e452c008418429f7f142

7 years agoExclude experimental/logging/example from the main folly_base rule
Christopher Dykes [Sat, 24 Jun 2017 23:59:30 +0000 (16:59 -0700)]
Exclude experimental/logging/example from the main folly_base rule

Summary: It's an example, not part of the main Folly library.

Reviewed By: yfeldblum

Differential Revision: D5304985

fbshipit-source-id: 7cfb95da5795af61e9307882f71836ef7fa5a463

7 years agoSplit the futures and logging tests in the CMake build
Christopher Dykes [Sat, 24 Jun 2017 23:58:33 +0000 (16:58 -0700)]
Split the futures and logging tests in the CMake build

Summary: They are intended to be run as separate sets of tests, and the logging tests define multiple mains.

Reviewed By: yfeldblum

Differential Revision: D5307503

fbshipit-source-id: ed38a762177cec3c600791b861584dd47019b5a9

7 years agoFix up and namespace clock_gettime and clock_getres for MacOS
Michael Lee [Sat, 24 Jun 2017 03:11:14 +0000 (20:11 -0700)]
Fix up and namespace clock_gettime and clock_getres for MacOS

Summary:
Resolve two issues with folly's clock_gettime() shim on Apple platforms (iOS, macOS, etc.):

When detecting whether folly should define clock_gettime() on Apple platforms, don't assume clock_gettime() is declared in Apple's headers just because MAC_OS_X_VERSION_10_12/__IPHONE_10_0 is defined. Someone might use a newer macOS or iOS SDK (which defines MAC_OS_X_VERSION_10_12/__IPHONE_10_0), but not have clock_gettime() (because _DARWIN_FEATURE_CLOCK_GETTIME isn't set).

When defining a shim for clock_gettime(), don't rely on Apple's clock_gettime() declaration. Instead, shadow Apple's declaration with our own. This prevents folly from inheriting Apple's availability and visibility attributes for clock_gettime().

Reviewed By: yfeldblum

Differential Revision: D5312574

fbshipit-source-id: f16634ce92ee6c299613d3db22f0537bd31ac14d

7 years agoMove address caching logic from AsyncSSLSocket to AsyncSocket.
Kyle Nekritz [Fri, 23 Jun 2017 22:51:53 +0000 (15:51 -0700)]
Move address caching logic from AsyncSSLSocket to AsyncSocket.

Summary: So that it is available on other transports.

Reviewed By: Orvid

Differential Revision: D5302039

fbshipit-source-id: cbfdadd158061ed9a2b3ed3e0960ce66f0d545fd

7 years agofix UBSAN failure in atomic_shared_ptr_test
Ilya Maykov [Fri, 23 Jun 2017 22:43:48 +0000 (15:43 -0700)]
fix UBSAN failure in atomic_shared_ptr_test

Summary: Fix UBSAN failure in atomic_shared_ptr_test by using reinterpret_cast instead of static_cast.

Reviewed By: yfeldblum

Differential Revision: D5314116

fbshipit-source-id: 8479c9c4bdeeb155067a3de75efe4e97c36519e5

7 years agoMoveOnly utility
Giuseppe Ottaviano [Fri, 23 Jun 2017 22:19:01 +0000 (15:19 -0700)]
MoveOnly utility

Summary: Same as `boost::noncopyable` but it does not disable move constructor/assignment.

Reviewed By: luciang

Differential Revision: D5311043

fbshipit-source-id: 44fe95712169b95a00e474385be43fa857cfd8ec

7 years agoFix AsyncFileWriterTest due to long being 32-bit on Windows
Christopher Dykes [Fri, 23 Jun 2017 21:13:19 +0000 (14:13 -0700)]
Fix AsyncFileWriterTest due to long being 32-bit on Windows

Summary: `long` is only 32-bits on Windows, which means this call to `std::min` was ambiguous, which caused a compile error.

Reviewed By: simpkins

Differential Revision: D5305964

fbshipit-source-id: 7e4152006e163a0301652be46318f0fc937e5ead

7 years agoFix exception_wrapper on Windows by abusing internals
Andrew Krieger [Fri, 23 Jun 2017 20:58:11 +0000 (13:58 -0700)]
Fix exception_wrapper on Windows by abusing internals

Summary:
exception_wrapper's non-allocating variant was depending
on the exception reference being a reference to a heap object,
which is not the case on Windows. All thrown exceptions are
copied to the stack first.

So, we abuse internals of exception_ptr to get the internally
heap allocated copy of the object. What could possibly go wrong.

Reviewed By: yfeldblum, ericniebler, Orvid

Differential Revision: D5270634

fbshipit-source-id: 2983a6af9a2c3cb66cbee8a382707a76b582c489

7 years agomove input shared_ptr in atomic_shared_ptr constructor
Ilya Maykov [Fri, 23 Jun 2017 18:32:32 +0000 (11:32 -0700)]
move input shared_ptr in atomic_shared_ptr constructor

Summary: By moving the input shared_ptr instead of copying it, we avoid doing an unnecessary ref count increment + decrement.

Reviewed By: djwatson, yfeldblum

Differential Revision: D5298467

fbshipit-source-id: b9f0b6999278609417bb4dc062030ca2388ba20a

7 years agoFix GlogFormatterTest on Windows
Christopher Dykes [Fri, 23 Jun 2017 02:55:36 +0000 (19:55 -0700)]
Fix GlogFormatterTest on Windows

Summary:
It was missing a portability header needed for `setenv`, and was assuming that the `system_clock` was represented as nanoseconds.
On Windows `std::chrono::system_clock` is represented as 100s of nanoseconds, ie. `FILETIME`.

Reviewed By: simpkins

Differential Revision: D5308182

fbshipit-source-id: facb922ebe1587723358b38499dadac683e3517b

7 years agoStop MSVC from complaining about digraphs not being supported
Christopher Dykes [Fri, 23 Jun 2017 01:09:20 +0000 (18:09 -0700)]
Stop MSVC from complaining about digraphs not being supported

Summary: MSVC complains about `<:` being a digraph and that it isn't interpreting it as one (C4628). Make it be quiet by making it not look like a digraph.

Reviewed By: simpkins

Differential Revision: D5305162

fbshipit-source-id: 7385164e8f73226ce18bc04c32894c2f27f8ae25

7 years agoSwitch the logging tests from .native() to .string()
Christopher Dykes [Fri, 23 Jun 2017 01:08:23 +0000 (18:08 -0700)]
Switch the logging tests from .native() to .string()

Summary: These were using `boost::filesystem::path.native()` in contexts where an `std::string` was the expected output. `boost::filesystem::path.native()` returns a `std::wstring` on Windows, so use `.string()` instead.

Reviewed By: simpkins

Differential Revision: D5305649

fbshipit-source-id: 3c7cd53d2f33d2dbb222731655cdab69d1c4a187

7 years agoFix ThreadName.cpp on Windows
Christopher Dykes [Fri, 23 Jun 2017 01:07:39 +0000 (18:07 -0700)]
Fix ThreadName.cpp on Windows

Summary: I failed to realize that this helper function also needs to be guarded on `!_WIN32`, because the assertions are false on Windows.

Reviewed By: ot, luciang

Differential Revision: D5304914

fbshipit-source-id: f2564cb2fcbfdc73a2529d4a41df2995748bc3f6

7 years agoEnable more auto-deps in Folly
Christopher Dykes [Fri, 23 Jun 2017 01:06:21 +0000 (18:06 -0700)]
Enable more auto-deps in Folly

Summary: This enables auto-deps support in more places in Folly. It also fixes a couple of auto-deps declarations that were missing an `s`.

Reviewed By: yfeldblum

Differential Revision: D5289542

fbshipit-source-id: 7d34b29bcc172fb31f91f1ba880864e2d5869ffd

7 years agoallow passing function pointers to Future::onError()
Adam Simpkins [Thu, 22 Jun 2017 20:39:56 +0000 (13:39 -0700)]
allow passing function pointers to Future::onError()

Summary:
Add appropriate specializations for detail::Extract() so that you can pass a
plain function pointer to `onError()`.  Previously the code only worked with
member function pointers and functor-style objects.

Reviewed By: yfeldblum, wez

Differential Revision: D5286773

fbshipit-source-id: 67b44d1d7573eb1da501475045fd24ad4ab1c074

7 years agologging: fix issues detecting XLOG(FATAL) statements as noreturn
Adam Simpkins [Thu, 22 Jun 2017 18:44:38 +0000 (11:44 -0700)]
logging: fix issues detecting XLOG(FATAL) statements as noreturn

Summary:
Update the FB_LOG() and XLOG() macros so that FATAL log messages are correctly
detected as not returning, by both clang and gcc.

We have to ensure that both sides of the log statement check (log message
enabled or disabled) evaluate to `[[noreturn]]` expressions.  I did try
updating the log check itself so that it could be constexpr detected as always
passing, but this was not sufficient.

Reviewed By: wez

Differential Revision: D5290780

fbshipit-source-id: 773a56a8392dfd7c310d5d84fc9311e66edf99cb

7 years agoAsyncSSLSocket connect without SSL
Aaron Balsara [Thu, 22 Jun 2017 18:26:36 +0000 (11:26 -0700)]
AsyncSSLSocket connect without SSL

Summary:
Currently when calling connect with AsyncSSLSocket in unencrypted
mode it still attempts to perform a SSL handshake. Add check to not
do SSL. Calling sslConnect will always run the SSL handshake

Reviewed By: jrahman

Differential Revision: D5153456

fbshipit-source-id: 4d9164115be72c8ee76e383535561e3083a327e3

7 years agologging: improve the AsyncFileWriter flush test()
Adam Simpkins [Thu, 22 Jun 2017 03:38:47 +0000 (20:38 -0700)]
logging: improve the AsyncFileWriter flush test()

Summary:
This test has run into occasional failures on continuous build test runs.
Unfortunately when something goes wrong it crashes in the std::thread
destructor due to this thread still being joinable when it is destroyed, which
hides information about what actually failed in the test.

This updates the test to immediately detach the thread, so that on error we
will be able see the real failure reason.

This also increases the size of the message that we write, which will hopefully
help ensure that this write always blocks.

Reviewed By: wez

Differential Revision: D5295574

fbshipit-source-id: ea8cfa855613398f88f9f982c600ec661018a31c

7 years agologging: fully convert the ERROR level to ERR
Adam Simpkins [Thu, 22 Jun 2017 00:23:21 +0000 (17:23 -0700)]
logging: fully convert the ERROR level to ERR

Summary:
Switch all code in the logging library from using `ERROR` to `ERR`,
and remove the `ERROR` LogLevel entirely, even if it is not already
defined as a macro.

Previously the code kept `ERROR` available as a LogLevel name if it had
not already been defined as a macro (which is done by common Windows header
files).  However, this made for inconsistent behavior, and made it easy to
write code that would not be portable to Windows.

This diff fully drops the `ERROR` name for consistency across platforms.

Reviewed By: wez

Differential Revision: D5288600

fbshipit-source-id: 8d2d52e955959c278345fc9c2086c7cacf9660f9

7 years agologging: add more tests for fatal log messages
Adam Simpkins [Thu, 22 Jun 2017 00:05:20 +0000 (17:05 -0700)]
logging: add more tests for fatal log messages

Summary:
Add some tests for fatal log messages during static initialization and
destruction.  Ideally most programs won't actually do much real work before or
after main, but make sure the logging framework behaves sanely in these
situations.

This also fixes a bug in the `test_none()` test, which previously caused it to
always succeed without testing the desired behavior.

Reviewed By: wez

Differential Revision: D5281718

fbshipit-source-id: ca838c098886e99418264acf9a4d651ea9e7502c

7 years agoAdd support for move operations on hazptr-holder. Other optimizations.
Maged Michael [Wed, 21 Jun 2017 22:56:45 +0000 (15:56 -0700)]
Add support for move operations on hazptr-holder. Other optimizations.

Summary:
- Support empty hazptr_holder, move constructor and assignment operator
- Limit thread caching to the default domain to improve performance of thread caching
- Fix unnecessary calls to stats singleton
- Use the mprotect version of AsymmetricMemoryBarrier for reducing the overhead of bulkReclaim().
- Update read-side benchmark results

Reviewed By: djwatson

Differential Revision: D5292885

fbshipit-source-id: bc5713ac95492a7114e1e467e71d2278e64b165d

7 years agologging: shorten output of logLevelToString()
Adam Simpkins [Wed, 21 Jun 2017 20:23:28 +0000 (13:23 -0700)]
logging: shorten output of logLevelToString()

Summary:
Remove the "LogLevel::" prefix from the logLevelToString() output.

This makes the output shorter and easier to read, and makes it simpler to write
LogFormatter implementations that want a short human-readable level
description.  Callers can always add a "LogLevel::" prefix on their own if
desired.

Reviewed By: wez

Differential Revision: D5288601

fbshipit-source-id: 046579ebdda76842d5a44c33d68941d73dd81162

7 years agoPrint expected/actual thread names when running EventBase logic in unexpected thread
Giuseppe Ottaviano [Wed, 21 Jun 2017 19:28:52 +0000 (12:28 -0700)]
Print expected/actual thread names when running EventBase logic in unexpected thread

Summary: The existing assertion errors do not give a lot of information to track down which thread is incorrectly using the `EventBase`. Print both the current thread name and the name of the thread running the event base loop.

Reviewed By: luciang

Differential Revision: D5289790

fbshipit-source-id: 563c7f68b7f9b7a6e85e22290d7e81afbf89871e

7 years agoCall onRecycle after element is marked as deallocated in IndexedMemPool
Victor Zverovich [Wed, 21 Jun 2017 18:38:32 +0000 (11:38 -0700)]
Call onRecycle after element is marked as deallocated in IndexedMemPool

Summary: Make `IndexedMemPool` call `Traits::onRecycle` on the element just before it is marked as deallocated. This mirrors the allocation behavior implemented in D5177462 and simplifies preventing access to recycled elements (the client just needs to check `isAllocated` before accessing the element).

Reviewed By: nbronson

Differential Revision: D5275283

fbshipit-source-id: 58365b5b7b32b07fa56529c476078f241fc20811

7 years agoShift the exception tracer benchmark and test into the test directory
Christopher Dykes [Wed, 21 Jun 2017 18:22:23 +0000 (11:22 -0700)]
Shift the exception tracer benchmark and test into the test directory

Summary: Tests and benchmarks don't belong in the same directory as source code.

Reviewed By: yfeldblum

Differential Revision: D5288080

fbshipit-source-id: 865c6dfbeff751bda49870e5284e168d33aff256

7 years agoAdd flags to asymmetric mem barrier
Dave Watson [Wed, 21 Jun 2017 17:54:54 +0000 (10:54 -0700)]
Add flags to asymmetric mem barrier

Summary:
Original sys_membarrier call supported an EXPEDITED flag, that was much faster than the current version, at some extra CPU cost.

The basic idea was a normal one would be used in a background thread, while EXPEDITED would be useful inline in foreground threads.

Add the flag here, and use the mprotect hack until sys_membarrier supports both.

Reviewed By: magedm

Differential Revision: D5292680

fbshipit-source-id: 30edf27514976991bbaa8e776a7138eb815ade36

7 years agoHave reserved sockopt to disable TSOCKS
Petr Lapukhov [Wed, 21 Jun 2017 14:41:46 +0000 (07:41 -0700)]
Have reserved sockopt to disable TSOCKS

Summary: as title, similar to TTLS

Reviewed By: djwatson

Differential Revision: D5284200

fbshipit-source-id: 7eb95668740b239349c6e73f3b152e6506671072

7 years agoAdd missing uint32 type to folly::ProgramOptions::gFlagAdders
Uladzislau Paulovich [Wed, 21 Jun 2017 13:19:44 +0000 (06:19 -0700)]
Add missing uint32 type to folly::ProgramOptions::gFlagAdders

Summary: Absence of "uint32" type in gFlagAdders map breaks all apps that use gflags of this type (i.e. define a flag with "DEFINE_uint32").

Reviewed By: WillerZ

Differential Revision: D5286720

fbshipit-source-id: c02bd959cb9ea9a47fba1e01429181ba09edf5dd

7 years agoAdd support for getting other threads' names
Giuseppe Ottaviano [Wed, 21 Jun 2017 06:03:57 +0000 (23:03 -0700)]
Add support for getting other threads' names

Summary: Complete the `ThreadName.h` API.

Reviewed By: luciang, Orvid

Differential Revision: D5289160

fbshipit-source-id: a48e61093008039da50b1c568364fa5b8744b401

7 years agologging: reduce the amount of code emitted for log statements
Adam Simpkins [Wed, 21 Jun 2017 02:44:20 +0000 (19:44 -0700)]
logging: reduce the amount of code emitted for log statements

Summary:
This refactors the logging code with the aim of reducing the amount of assembly
code emitted for each log statement, particularly for `XLOG()` statements.
Ideally it should be possible to put debug `XLOG()` statements throughout your
code without having to worry about the performance overhead.  Therefore we
should attempt to make sure that `XLOG()` statements do not generate a lot of
assembly and hurt icache performance.

This diff does not have any code behavior changes--it just moves code around a
bit.  The high-level summary is:

- Move as much code as possible into the LogStreamProcessor constructors and
  destructor.  Make sure these methods are defined in LogStreamProcessor.cpp to
  avoid having them be emitted inline at each log statement.
- Move some of the XLOG level checking logic into separate non-inline functions
  defined in xlog.cpp
- Pass xlog category information around as a pair of (categoryName,
  isOverridden) parameters.  If isOverridden is true then the categoryName
  parameter should be used as the category name directly.  If isOverridden is
  false, then categoryName is a filename that needs to go through filename to
  category name string processing.  This allows the category name processing to
  be done in non-inlined code.

Reviewed By: wez

Differential Revision: D5269976

fbshipit-source-id: 7a7877ddfed66cd27ed82f052330b6aa2be4b37b

7 years agologging: add printf-style logging macros
Adam Simpkins [Wed, 21 Jun 2017 02:44:18 +0000 (19:44 -0700)]
logging: add printf-style logging macros

Summary:
Add new `FB_LOGC()` and `XLOGC()` macros that accept C-style printf format
strings.  (The `FB_LOGF()` and `XLOGF()` macro names are already used for
`folly::format()` style formatting.)

This will make it easier for users to update existing printf-style code to use
this new logging library.

These are in a separate `printf.h` header file that must be explicitly included
to have access to these macros.  The intent is to encourage users to use one of
the other APIs (streaming, append-style, or `folly::format()`) instead of these
printf-like APIs in new code.

Reviewed By: omry

Differential Revision: D5269974

fbshipit-source-id: 56e55f9642bb00806d9b4c762fb6a91778ef6ad3

7 years agologging: make XLOG_GET_CATEGORY() safe for all callers
Adam Simpkins [Wed, 21 Jun 2017 02:44:17 +0000 (19:44 -0700)]
logging: make XLOG_GET_CATEGORY() safe for all callers

Summary:
The `XLOG_GET_CATEGORY()` macro was previously written assuming it was only
used inside `XLOG()` statement.  When used inside the main translation unit
being compiled (e.g., a .cpp file and not a header file), the code assumed that
the file-scope category had already been initialized, since a level check had
presumably already been performed.

However, it is useful in some places for external users (outside of the logging
library itself) to call `XLOG_GET_CATEGORY()`.  In these cases a log level
check may not have been performed yet, so the file-scope category may not be
initialized yet.

This diff renames the existing `XLOG_GET_CATEGORY()` macro to
`XLOG_GET_CATEGORY_INTERNAL()` and adds a new `XLOG_GET_CATEGORY()` macro that
is slower (it always looks up the category by name) but always safe to use.

This also adds a new `XLOG_GET_CATEGORY_NAME()` macro, and renames the existing
`XLOG_SET_CATEGORY()` macro to `XLOG_SET_CATEGORY_NAME()` for API consistency.

Reviewed By: wez

Differential Revision: D5269975

fbshipit-source-id: 373805255823855282fa7a8d4a4d232ba06367f6

7 years agologging: improve the AsyncFileWriterTest discard test
Adam Simpkins [Wed, 21 Jun 2017 02:44:16 +0000 (19:44 -0700)]
logging: improve the AsyncFileWriterTest discard test

Summary:
This improves the test that exercises the AsyncFileWriter message discarding
logic.

Previously each writer thread wrote a fixed number of small messages.  This was
fairly slow, and wasn't always guaranteed to reliably produce discards.
Now each writer thread writes larger messages, which produce discards faster.
The test also automatically stops after 10 separate discard events, so that it
finishes faster (typically a few hundred milliseconds, rather than 5+ seconds).

This also updates the test to use XLOG() internally rather than using fprintf()
to print to stderr, now that the XLOG() diffs have landed.

Reviewed By: wez

Differential Revision: D5261059

fbshipit-source-id: 120224706fee36948ef76efbeb579ccc56400c51

7 years agologging: implement FATAL and DFATAL log levels
Adam Simpkins [Tue, 20 Jun 2017 21:01:59 +0000 (14:01 -0700)]
logging: implement FATAL and DFATAL log levels

Summary:
Add new `FATAL` and `DFATAL` log levels.

Any log message with a level of `FATAL` always crashes the program.  Log
messages with a level of `DFATAL` crash the program in debug build modes.

Before crashing, the code makes sure to flush all LogHandlers, so that the
fatal message is not lost if some of the LogHandlers process messages
asynchronously.  If no LogHandlers were configured, the message is printed to
stderr.

Reviewed By: wez

Differential Revision: D5189497

fbshipit-source-id: c45dbd582fb1c3a962d00effb2967737ef97cc8b

7 years agoUpdate hazard pointer interface to standard proposal P0233R4
Maged Michael [Tue, 20 Jun 2017 19:10:45 +0000 (12:10 -0700)]
Update hazard pointer interface to standard proposal P0233R4

Summary:
Updated to the interface to be in synch with the latest standard proposal in P0233R4 as follows:
- Renamed hazptr_owner as hazptr_holder.
- Combined hazptr_holder member functions set() and clear() as reset().
- Replaced the template parameter A for hazptr_holder member function templates try_protect() and get_protected with atomic<T*>.
- Moved the template parameter T from the class hazptr_holder to its member functions try_protect(), get_protected(), and reset().
- Added a non-template overload of hazptr_holder::reset() with an optional nullptr_t parameter.
- Removed the template parameter T from the free function swap() as hazptr_holder is no longer a template.

Reviewed By: davidtgoldblatt

Differential Revision: D5283863

fbshipit-source-id: 2bc1a09f4f844aa72d9b7dff9c450540bbe09972

7 years agofix folly::FunctionScheduler.cancelFunctionAndWait() hanging issue
Qi Zhou [Tue, 20 Jun 2017 18:36:53 +0000 (11:36 -0700)]
fix folly::FunctionScheduler.cancelFunctionAndWait() hanging issue

Summary:
When
- only one function is scheduled in FunctionScheduler; and
- the function is running while cancelFunctionAndWait() is being called;
FunctionScheduler.cancelFunctionAndWait() will hang forever.  The root cause is that the condition in cancelFunctionAndWait() is incorrect:

```
runningCondvar_.wait(l, [currentFunction, this]() {
  return currentFunction != currentFunction_;
});
```

because currentFunction will not be changed if only one function is in the scheduler.

The fix here is to
- clear currentFunction as nullptr.  This also makes the internal behaviors of cancelFunction() and cancelFunctionAndWait() consistent.
- introduces additional variable to indicate the state of cancelling current function.  After running the function, the background thread will detect cancellation of current function and clear the variable.
- cancelFunctionAndWait() condition variable will wait for the variable to be cleared.

Similarly, cancelAllFunctionsAndWait() also suffers from the same issue.

Unit tests are added to reproduce the issue.

Reviewed By: yfeldblum

Differential Revision: D5271664

fbshipit-source-id: acb223304d3eab23129907ce9ff5e57e55f1e909

7 years agologging: add LoggerDB::flushAllHandlers()
Adam Simpkins [Tue, 20 Jun 2017 18:02:00 +0000 (11:02 -0700)]
logging: add LoggerDB::flushAllHandlers()

Summary:
Add a method to flush all LogHandler objects.

This will be necessary to implement FB_LOG(FATAL), as we will want to flush all
outstanding messages before crashing.

Reviewed By: wez

Differential Revision: D5189501

fbshipit-source-id: faf260b8e71e5dfed4a3b1c1aee32f072bd7b764

7 years agologging: add a LogHandler::flush() call
Adam Simpkins [Tue, 20 Jun 2017 18:01:57 +0000 (11:01 -0700)]
logging: add a LogHandler::flush() call

Summary:
Add a flush() call to the LogHandler interface.  This is needed to implement
`FB_LOG(FATAL)` so that we can flush all LogHandlers before aborting the
program.

Reviewed By: wez

Differential Revision: D5189499

fbshipit-source-id: 75fa4d7e75ea26de5b7383bf7e8d073fb37e9309

7 years agologging: add a NEVER_DISCARD flag to LogWriter
Adam Simpkins [Tue, 20 Jun 2017 18:01:55 +0000 (11:01 -0700)]
logging: add a NEVER_DISCARD flag to LogWriter

Summary:
Add a flag to the LogWriter so we can ensure that particular messages are never
discarded, even when the LogWriter is throttling messages.

This functionality will be necessary to implement `FB_LOG(FATAL)` to that we
can avoid discarding the reason for crashing.

Reviewed By: wez

Differential Revision: D5189498

fbshipit-source-id: dc4322ea5ba449a341cdbdc32afb0ed466019801

7 years agologging: add a small example program
Adam Simpkins [Tue, 20 Jun 2017 18:01:53 +0000 (11:01 -0700)]
logging: add a small example program

Summary:
This adds a small example program which demonstrates using the logging library.

This gives a very basic example of how the library is intended to be used, and
can also be used to play around with controlling the log levels from the
command line argument.

Reviewed By: wez

Differential Revision: D5083104

fbshipit-source-id: ab09c6c88db33065f6e39f35b28014f2a6153cef

7 years agoDelete folly/futures/OpaqueCallbackShunt.h
Christopher Dykes [Tue, 20 Jun 2017 17:11:42 +0000 (10:11 -0700)]
Delete folly/futures/OpaqueCallbackShunt.h

Summary: It is not used anywhere, not even in tests, so kill it.

Reviewed By: yfeldblum

Differential Revision: D5280800

fbshipit-source-id: 7e6a308bf09198548b77dcc1bfacc0ee95eb4887

7 years agoRevert D5278412: [Folly] Merge StringBase.cpp and String.cpp
Christopher Dykes [Tue, 20 Jun 2017 04:23:56 +0000 (21:23 -0700)]
Revert D5278412: [Folly] Merge StringBase.cpp and String.cpp

Summary: This reverts commit 07639e155421f31a6cc7ed16cba2034750e44325

Differential Revision: D5278412

fbshipit-source-id: 4b4d60f1f472ebe2e68e8eea1a31f42bc55c60ed

7 years agoMerge StringBase.cpp and String.cpp
Christopher Dykes [Tue, 20 Jun 2017 00:24:45 +0000 (17:24 -0700)]
Merge StringBase.cpp and String.cpp

Summary: The only reason these were split was because of the use of `folly::format`

Reviewed By: yfeldblum

Differential Revision: D5278412

fbshipit-source-id: 07639e155421f31a6cc7ed16cba2034750e44325

7 years agoSwitch pid_t to be defined as int rather than void*
Christopher Dykes [Tue, 20 Jun 2017 00:23:19 +0000 (17:23 -0700)]
Switch pid_t to be defined as int rather than void*

Summary: Because an `int` plays much much nicer with code already written for Windows than `void*` does. It takes quite a bit of hackery to make it possible with the pthread implementation we support using, but it is possible and is worth the effort.

Reviewed By: yfeldblum

Differential Revision: D5276968

fbshipit-source-id: 4cd0d3120a4f19976e76853ef4b337e96d5005a8

7 years agoMake semaphore.h a non-portable header
Christopher Dykes [Mon, 19 Jun 2017 21:34:21 +0000 (14:34 -0700)]
Make semaphore.h a non-portable header

Summary: On Windows it has include order requirements.

Reviewed By: yfeldblum

Differential Revision: D5277151

fbshipit-source-id: a6cf923d78e5944ac34e885e32a7cf072f904720

7 years agoDocument the preferred alternatives in Foreach.h
Phil Willoughby [Mon, 19 Jun 2017 12:51:34 +0000 (05:51 -0700)]
Document the preferred alternatives in Foreach.h

Reviewed By: yfeldblum

Differential Revision: D5228760

fbshipit-source-id: bcad4237997e611e06c93b476c5b673dc93c0621

7 years agoFix the build of detail/CacheLocality.h on Windows
Christopher Dykes [Mon, 19 Jun 2017 07:04:43 +0000 (00:04 -0700)]
Fix the build of detail/CacheLocality.h on Windows

Summary: It was broken by D5139886 which added a call to `std::__throw_bad_alloc` without first including the correct portability header.

Reviewed By: yfeldblum

Differential Revision: D5273016

fbshipit-source-id: cac1772f41ae5942a29cefa69fb07d9cf94b5aab

7 years agoFix the CMake build with tests enabled
Christopher Dykes [Mon, 19 Jun 2017 05:42:40 +0000 (22:42 -0700)]
Fix the CMake build with tests enabled

Summary: I broke it when I moved the stats tests around.

Reviewed By: yfeldblum

Differential Revision: D5258526

fbshipit-source-id: 70982ffaaed89a548e943e4b011b013c89808666