folly.git
5 years agoFixed documentation in folly/Random.h
Peter Goldsborough [Mon, 5 Jun 2017 21:17:02 +0000 (14:17 -0700)]
Fixed documentation in folly/Random.h

Summary:
The docs give `ThreadLocalPRNG rng = Random::threadLocalPRNG()` as an example
of creating a thread local PRNG, but `Random::threadLocalPRNG()` does not/no longer
exist. I think it's just `folly::ThreadLocalPRNG` right now.

Reviewed By: yfeldblum

Differential Revision: D5184992

fbshipit-source-id: 63a9ef62b32fca42088abec419ae53531910cc82

5 years agoFix JemallocNodumpAllocator destructor w/ jemalloc 5.0.
Qi Wang [Mon, 5 Jun 2017 19:45:43 +0000 (12:45 -0700)]
Fix JemallocNodumpAllocator destructor w/ jemalloc 5.0.

Summary: Destroy created arena which has extent_hooks linked.

Reviewed By: jasone

Differential Revision: D5177535

fbshipit-source-id: 7d75f4276fc174c4d4ce1102dfb8ec8c27c1f56d

5 years agoMake StringKeyed* more complete
Phil Willoughby [Mon, 5 Jun 2017 17:58:29 +0000 (10:58 -0700)]
Make StringKeyed* more complete

Summary: Add `count()` and `swap()` methods. Ensure that `operator==` works.

Reviewed By: yfeldblum

Differential Revision: D5169393

fbshipit-source-id: a8025f6fdf251e38b0d2f27733d18967a55c6a15

5 years agoDon't explicitly disable the C++1y-extensions warning in ForEach-inl and WhenN-inl v2017.06.05.00
Christopher Dykes [Sun, 4 Jun 2017 19:04:28 +0000 (12:04 -0700)]
Don't explicitly disable the C++1y-extensions warning in ForEach-inl and WhenN-inl

Summary: We are fully on C++14 now, so these warnings should never be firing.

Reviewed By: yfeldblum

Differential Revision: D5179124

fbshipit-source-id: 31c6ddbce5c45b60fe73990f49d65ac95d17fe87

5 years agoResolve the circular dependency between folly/futures/detail/Core.h and Future.h...
Christopher Dykes [Sun, 4 Jun 2017 18:35:40 +0000 (11:35 -0700)]
Resolve the circular dependency between folly/futures/detail/Core.h and Future.h and Promise.h

Summary: Do this by moving the two helpers that need to refer to them into `folly/futures/helpers.h`.

Reviewed By: yfeldblum

Differential Revision: D5179109

fbshipit-source-id: bdb319ff3432d3629a955c1390dc8bf6f27f4ce6

5 years agoDon't use folly::shellify in StaticTracepointTest
Christopher Dykes [Sun, 4 Jun 2017 03:10:38 +0000 (20:10 -0700)]
Don't use folly::shellify in StaticTracepointTest

Summary: It's deprecated, so use the non-deprecated form instead.

Reviewed By: yfeldblum

Differential Revision: D5179133

fbshipit-source-id: 91440bc3768ee68d2aada2299fbfbcdd852f946c

5 years agoApply clang-format to folly/gen/ (partial: namespace)
Yedidya Feldblum [Sat, 3 Jun 2017 00:51:28 +0000 (17:51 -0700)]
Apply clang-format to folly/gen/ (partial: namespace)

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

With some manual rearrangement in the places where `clang-format` does awkward things, with the result that clang-format over `folly/gen/` becomes a no-op.

Reviewed By: Orvid

Differential Revision: D5177428

fbshipit-source-id: 17f51d00454a7be7f29dcf1a2ff3d0eaf1de72ab

5 years agoApply clang-format to folly/portability/
Yedidya Feldblum [Fri, 2 Jun 2017 22:34:42 +0000 (15:34 -0700)]
Apply clang-format to folly/portability/

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

With some manual rearrangement in the places where `clang-format` does awkward things, with the result that `clang-format` over `folly/portability/` becomes a no-op.

Reviewed By: igorsugak

Differential Revision: D5170107

fbshipit-source-id: ceadd96740b4877cbae947846f0e738e6aaf5ed1

5 years agoFix JemallocNodumpAllocator extent_hooks API.
Qi Wang [Fri, 2 Jun 2017 19:32:01 +0000 (12:32 -0700)]
Fix JemallocNodumpAllocator extent_hooks API.

Summary: Using extent_hooks mallctl to update hooks.

Reviewed By: jasone

Differential Revision: D5174623

fbshipit-source-id: 9313ee9ae55c85d973736077727e54a5825f4c3d

5 years agoHazard pointers: Optimize memory order, add bulk reclamation control, add stats,...
Maged Michael [Fri, 2 Jun 2017 18:16:04 +0000 (11:16 -0700)]
Hazard pointers: Optimize memory order, add bulk reclamation control, add stats, add implementation switches, add benchmarks.

Summary: Make the implementation partially performant by optimizing memory order and using asymmetric memory barrier for full fences. Also added more control for bulk reclamation implementation, stats, and quality of implementation switches.

Reviewed By: djwatson

Differential Revision: D5129614

fbshipit-source-id: c597edf711fdc8f16f80523bd8cae42c51fbe140

5 years agoUpdate folly/JemallocNodumpAllocator to jemalloc 4 & 5 compatible.
Qi Wang [Fri, 2 Jun 2017 17:17:40 +0000 (10:17 -0700)]
Update folly/JemallocNodumpAllocator to jemalloc 4 & 5 compatible.

Summary:
jemalloc 5.0 comes replaced chunks with extents APIs. Make the API compatible
with both jemalloc 4 and 5.

Reviewed By: yfeldblum

Differential Revision: D5170925

fbshipit-source-id: ce25723975729b0b63371f89a96842a1b2e3b3cc

5 years agoRemove InlineExecutor.cpp
Christopher Dykes [Thu, 1 Jun 2017 18:37:08 +0000 (11:37 -0700)]
Remove InlineExecutor.cpp

Summary: It is nothing but a file with the license header in it and has been since it was introduced nearly 4 years ago.

Reviewed By: yfeldblum

Differential Revision: D5163176

fbshipit-source-id: f510411cbb3d9d4c90d68c9b8d1f04d9f97fcb89

5 years agoRephrase Optional usage to quite warnings
Tom Jackson [Thu, 1 Jun 2017 15:44:32 +0000 (08:44 -0700)]
Rephrase Optional usage to quite warnings

Reviewed By: yfeldblum

Differential Revision: D5105818

fbshipit-source-id: e3926a0c70a68855e0180bdd44cb0ec76e66bb94

5 years agoDocs for SingletonThreadLocal
Phil Willoughby [Thu, 1 Jun 2017 15:43:35 +0000 (08:43 -0700)]
Docs for SingletonThreadLocal

Summary:
Add a few keywords people search for when looking for this that won't otherwise
find this file.

Add a reference to the usage notes for Singleton which are a good description
of how you should operate SingletoThreadLocal as well.

Reviewed By: nbronson

Differential Revision: D5094598

fbshipit-source-id: 9980850805e1564e5c394af713e2fa17fe8844fe

5 years agoFix UB in folly/experimental/Bits.h
Tom Jackson [Thu, 1 Jun 2017 15:33:55 +0000 (08:33 -0700)]
Fix UB in folly/experimental/Bits.h

Summary:
Test output before the fix is applied:
```
folly/experimental/Bits.h:247:59: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
     #0 folly/experimental/Bits.h:247 folly::Bits<...>::set(int*, unsigned long, unsigned long, int)
     #1 folly/experimental/test/BitsTest.cpp:228 std::enable_if<...>::type (anonymous namespace)::testSet<...>(unsigned char*, unsigned long, unsigned long, int)
     #2 folly/experimental/test/BitsTest.cpp:263 Bits_Boundaries_Test::TestBody()
    #17 folly/experimental/test/BitsTest.cpp:381 main
```

Reviewed By: philippv

Differential Revision: D5160789

fbshipit-source-id: 43f1926d58f1a5c019d4f8794d10a7a80a5c4749

5 years agoRemove FiberManagerFuture.h as it's dead
Christopher Dykes [Thu, 1 Jun 2017 07:23:48 +0000 (00:23 -0700)]
Remove FiberManagerFuture.h as it's dead

Summary: All functions in this file are defined in `folly/fibers/FiberManager-inl.h`. There are no remaining references to this file.

Reviewed By: yfeldblum

Differential Revision: D5163160

fbshipit-source-id: 2fcb782a4de78f5c067610c876d0cf98f3b69e63

5 years agoDestroy promise/future callback functions before waking waiters
Yedidya Feldblum [Thu, 1 Jun 2017 05:41:16 +0000 (22:41 -0700)]
Destroy promise/future callback functions before waking waiters

Summary:
Code may pass a callback which captures an object with a destructor which mutates through a stored reference, triggering heap-use-after-free or stack-use-after-scope.

```lang=c++
void performDataRace() {
  auto number = std::make_unique<int>(0);
  auto guard = folly::makeGuard([&number] { *number = 1; });
  folly::via(getSomeExecutor(), [guard = std::move(guard)]() mutable {}).wait();
  // data race - we may wake and destruct number before guard is destructed on the
  // executor thread, which is both stack-use-after-scope and heap-use-after-free!
}
```

We can avoid this condition by always destructing the provided functor before setting any result on the promise.

Retry at {D4982969}.

Reviewed By: andriigrynenko

Differential Revision: D5058750

fbshipit-source-id: 4d1d878b4889e5e6474941187f03de5fa84d3061

5 years agoRefactor the CMake file to work with CMake 3.8.2
Christopher Dykes [Wed, 31 May 2017 22:12:02 +0000 (15:12 -0700)]
Refactor the CMake file to work with CMake 3.8.2

Summary:
The dirty hack I was using to link `folly_base` into `folly` doesn't work in newer versions of CMake :(
This refactors the makefile to not need to dirty hack by using an object library rule instead. It also makes the compiler version detection more generic.

Reviewed By: yfeldblum

Differential Revision: D5158919

fbshipit-source-id: cd052a5f58ed3d88c377c68cca07ca8497ca0c7a

5 years agoFuture: some fixes re: handling of universal references
Sven Over [Wed, 31 May 2017 16:43:09 +0000 (09:43 -0700)]
Future: some fixes re: handling of universal references

Summary:
Callables that are passed as rvalues to makeFutureWith should be
executed as rvalues.
Generally callables that get captured by value should be executed
as rvalues, to allow passing e.g. folly::Partial objects that contain
move-only objects like unique_ptr or folly::Promise.
`collect` would move out of parameters passed as lvalues.

Reviewed By: fugalh

Differential Revision: D5120420

fbshipit-source-id: 1633c6b7e3fbb562f4d31e21d28c98b053de9912

5 years agoAdd non-throwing alternative to decodeVarint
Jon Maltiel Swenson [Wed, 31 May 2017 15:20:51 +0000 (08:20 -0700)]
Add non-throwing alternative to decodeVarint

Summary:
In mcrouter code, we would like a non-throwing alternative to `decodeVarint()`. There
are real, expected scenarios where only part of a serialized varint fits into a packet,
in which case mcrouter fails to decode the varint and throws.  In these scenarios,
throwing too many exceptions can lead to lock contention and degrade performance.

Reviewed By: yfeldblum

Differential Revision: D5153823

fbshipit-source-id: 138273af832903f0b04bee0bcacddd66b4274129

5 years agoadd equals interface for Range class.
Bi Xue [Wed, 31 May 2017 04:09:55 +0000 (21:09 -0700)]
add equals interface for Range class.

Summary:
Add `equals` interface to StringPiece (Range class). To support following case insensitive compare case:
```
folly::StringPiece a("hello");
if (a.equals("HELLO", folly::AsciiCaseInsensitive())) {
  // Do something.
}
```

Reviewed By: ot

Differential Revision: D5150495

fbshipit-source-id: 26816820f93959678f550768396f55293b5588cb

5 years agoFix tryTo to support conversion to enumerations v2017.05.29.00
Qinfan Wu [Sun, 28 May 2017 20:49:28 +0000 (13:49 -0700)]
Fix tryTo to support conversion to enumerations

Summary:
[Folly] Fix `tryTo` to support conversion to enumerations.

`tryTo` should return `Expected<Tgt, ConversionCode>` instead of `Tgt`.

Reviewed By: yfeldblum

Differential Revision: D5144706

fbshipit-source-id: cd23f3cf75de7c5a26bc569f3cb47fff360f6e2a

5 years agofolly/portability/Memory.cpp: restructure preprocessor conditionals so includes are...
Yiding Jia [Sun, 28 May 2017 18:51:10 +0000 (11:51 -0700)]
folly/portability/Memory.cpp: restructure preprocessor conditionals so includes are at top level

Summary:
`#include` inside a namespace is disallowed when using clang modules. Here I
just unconditionally include them at top level, since they are available in all the
relevant platforms.

Reviewed By: yfeldblum, Orvid

Differential Revision: D5140355

fbshipit-source-id: bb87225c1d8f4ac64b90a7aff5f912c13e150e3a

5 years agoMoving DestructorCheck from proxygen library to folly.
Maxim Georgiev [Sun, 28 May 2017 14:25:17 +0000 (07:25 -0700)]
Moving DestructorCheck from proxygen library to folly.

Summary:
allow-large-files
Moving DestructorCheck from proxygen library to folly.

Reviewed By: djwatson

Differential Revision: D5110897

fbshipit-source-id: 02a6cf6336000e8c36484e75d2da820588baf2df

5 years agoClarify in the docs what belongs in portability/
Christopher Dykes [Sun, 28 May 2017 01:00:35 +0000 (18:00 -0700)]
Clarify in the docs what belongs in portability/

Summary: This has always been the design rule for what belongs in `folly/portability/`, but was never written down anywhere except in my head, so put it somewhere people can actually find it so I can free that space in my head for other things.

Reviewed By: yfeldblum

Differential Revision: D5140587

fbshipit-source-id: 1f09c17b7ccfff780e1825670a7ffaa75cd1b1d5

5 years agoAdded folly::hint_emplace_iterator to folly/Iterator.h
Philipp Unterbrunner [Sat, 27 May 2017 05:54:46 +0000 (22:54 -0700)]
Added folly::hint_emplace_iterator to folly/Iterator.h

Summary:
In contrast to Container::insert(), for any STL container class, Container::emplace() does not have an overload that takes a Container::iterator as its first parameter. (The reason is to prevent ambiguity with respect to target class constructor parameters.) Instead, container classes have a separate emplace_hint() function.
Because of this separation, folly::emplace_iterator would fail to perform hinted emplacement in constructs where std::insert_iterator would perform hinted insertion.
This diff adds a new class, folly::hint_emplace_iterator(), and corresponding convenience function, folly::hint_emplacer(), which calls Container::emplace_hint() rather than Container::emplace().
It would have been trivial to copy&paste the existing folly::emplace_iterator class and simply replace the emplace() call with emplace_hint(), but I did not like the large amount of code repetition. So I decided to do some refactoring and move the emplace()/emplace_hint()/emplace_front()/emplace_back() calls into separate trait classes, and replace emplace_iterator()/hint_emplace_iterator()/front_emplace_iterator()/back_emplace_iterator() with suitable type aliases.

Reviewed By: yfeldblum

Differential Revision: D5097860

fbshipit-source-id: c0b733131a0d0d21fc0a8b08ad655142c6a41c19

5 years agoFix build with Ninja generator
Christopher Dykes [Fri, 26 May 2017 21:03:46 +0000 (14:03 -0700)]
Fix build with Ninja generator

Summary:
We were hitting a bug in CMake's Ninja generator that was causing it to incorrectly attempt to escape the closing quote on `_HAS_AUTO_PTR_ETC=1`, so remove the quotes, as they aren't actually needed.
This also makes a few quality-of-life changes to make building Folly with Ninja slightly easier.

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

Reviewed By: yfeldblum

Differential Revision: D5134585

fbshipit-source-id: 3816e53774f7963b9b4fd8ddf68b83ff7afdefe1

5 years agoFix reliance on the sign of char in fnv32 and fnv64
Christopher Dykes [Thu, 25 May 2017 19:48:25 +0000 (12:48 -0700)]
Fix reliance on the sign of char in fnv32 and fnv64

Summary:
Clearly someone noticed this was an issue before and fixed the other 2 overloads, but never fixed these :(

Specifically, ARM has unsigned chars, so this would be producing the wrong values there.

Reviewed By: yfeldblum, mzlee

Differential Revision: D5122992

fbshipit-source-id: eb71dea82c187c09c2c4496f1f7c99bd01db6dd0

5 years agoReplace FOLLY_WARN_UNUSED_RESULT with FOLLY_NODISCARD everywhere
Eric Niebler [Thu, 25 May 2017 03:29:37 +0000 (20:29 -0700)]
Replace FOLLY_WARN_UNUSED_RESULT with FOLLY_NODISCARD everywhere

Summary: `[[nodiscard]]` is the future. Let's start now.

Reviewed By: yfeldblum

Differential Revision: D5108297

fbshipit-source-id: c98f44af9e282616af92f9171516b6ea18e68c6d

5 years agoAdd zstd streaming interface
Nick Terrell [Wed, 24 May 2017 21:59:42 +0000 (14:59 -0700)]
Add zstd streaming interface

Summary:
* Add streaming interface to the `ZstdCodec`
* Implement `ZstdCodec::doCompress()` and `ZstdCodec::doUncompress()` using the streaming interface.
  [fbgs CodecType::ZSTD](https://fburl.com/pr8chg64) and check that no caller requires thread-safety.

Reviewed By: yfeldblum

Differential Revision: D5026558

fbshipit-source-id: 61faa25c71f5aef06ca2d7e0700f43214353c650

5 years agoAdd streaming API
Nick Terrell [Wed, 24 May 2017 21:59:41 +0000 (14:59 -0700)]
Add streaming API

Summary:
Adds a C-style streaming API to `folly/io/Compression.h`, with a zlib-esque interface.
Stacked diffs will add streaming support to zstd, zlib, gzip, lzma, lz4_frame, and automatic codecs.
This interface is targeting advanced users who are building higher level interfaces.
They can use this as a common base so they don't have to reimplement the same code for every codec.

Reviewed By: yfeldblum

Differential Revision: D5026332

fbshipit-source-id: e3abf1767b493c2fef153b895858a3a81b67d989

5 years agoapply clang-tidy modernize-use-override
Victor Gao [Wed, 24 May 2017 18:03:04 +0000 (11:03 -0700)]
apply clang-tidy modernize-use-override

Summary:
This is generated by applying clang-tidy -checks=modernize-use-override to all .cpp files under folly.
It enforces the use of the keywords virtual, override and final in a way compliant to the style guide.

Reviewed By: yfeldblum

Differential Revision: D5108973

fbshipit-source-id: 61c55aa372feebe3b3be12a2705a04879aae57a4

5 years agoA core-cached shared_ptr
Giuseppe Ottaviano [Wed, 24 May 2017 05:52:12 +0000 (22:52 -0700)]
A core-cached shared_ptr

Summary:
This class serves a similar use case to `ReadMostlySharedPtr`, but with two differences:

- It returns actual `shared_ptr`s, so it can be used as a drop-in replacement.
- Its memory utilization is constant, independent of the number of threads that use it.

Also, the code is much simpler. On the other hand, it is about 4x slower (but it still scales linearly in the number of concurrent threads acquiring the reference).

Reviewed By: djwatson

Differential Revision: D5104730

fbshipit-source-id: 8c18b635e0390394b06417b6df8b790e4bd2d90d

5 years agoHeterogeneous comparisons
Nick Terrell [Wed, 24 May 2017 02:35:39 +0000 (19:35 -0700)]
Heterogeneous comparisons

Summary:
`std::optional` allows heterogeneous comparisons, so `folly::Optional` should as well.
This allows numerical comparisons between different types, like `size_t` and `uint64_t`.

Fixes https://github.com/facebook/folly/issues/602.

Reviewed By: AsyncDBConnMarkedDownDBException

Differential Revision: D5110651

fbshipit-source-id: 34f3368283953033fbb2423ab30b04e38b5b7974

5 years agoRFC: Embed exception_wrapper directly into Try
Yedidya Feldblum [Wed, 24 May 2017 02:18:12 +0000 (19:18 -0700)]
RFC: Embed exception_wrapper directly into Try

Summary:
[Folly] RFC: Embed `exception_wrapper` directly into `Try`.

Rather than storing it elsewhere on the heap. With `exception_wrapper` at 24 bytes on x64, it may now be small enough. However, it will expand the size of `Try<T>` for `sizeof(T) <= 16`, giving `Try` a new minimum size of 32 bytes on x64 instead of 16.

Reviewed By: ericniebler

Differential Revision: D5051436

fbshipit-source-id: 10d59686d64382c88d54340c97567eafb3e2f682

5 years agoFix some old license headers
Yedidya Feldblum [Tue, 23 May 2017 19:59:17 +0000 (12:59 -0700)]
Fix some old license headers

Summary: [Folly] Fix some old license headers.

Reviewed By: meyering

Differential Revision: D5110463

fbshipit-source-id: c7bb57194e0d33fbe1c6ddaa7d94437833b0cb0d

5 years agoAdd FOLLY_NODISCARD for [[nodiscard]] attribute when it exists, FOLLY_WARN_UNUSED_RES...
Eric Niebler [Tue, 23 May 2017 16:01:31 +0000 (09:01 -0700)]
Add FOLLY_NODISCARD for [[nodiscard]] attribute when it exists, FOLLY_WARN_UNUSED_RESULT uses FOLLY_NODISCARD.

Summary: The `nodiscard` attribute was added to standard C++ in C++17. Prefer the standard formulation when it is available; otherwise, use `__attribute__((__warn_unused_result__))` on compilers that support the GNU extensions, and `_Check_return_` on MSVC. The old `FOLLY_WARN_UNUSED_RESULT` is now expands to `FOLLY_NODISCARD`.

Reviewed By: yfeldblum

Differential Revision: D5105137

fbshipit-source-id: 9aa22e81cd9f0b89f9343433aeae3ba365227ccb

5 years agoMake a few implicit truncations either explicit, or not truncate
Christopher Dykes [Mon, 22 May 2017 23:54:41 +0000 (16:54 -0700)]
Make a few implicit truncations either explicit, or not truncate

Summary: This silences a few warnings under MSVC, and gets Folly closer to being able to compile with `-Wconversion` enabled.

Reviewed By: yfeldblum

Differential Revision: D5100686

fbshipit-source-id: e5e04c7aa143597e151a56a4d1f90dda26d0033b

5 years agoEnable -Wimplicit-fallthrough
Christopher Dykes [Mon, 22 May 2017 22:33:12 +0000 (15:33 -0700)]
Enable -Wimplicit-fallthrough

Summary: Because just having a linter enforce it isn't good enough to catch everything.

Reviewed By: yfeldblum

Differential Revision: D5101828

fbshipit-source-id: a1bc482b37139a1eddeb93bc298596af950aa87d

5 years agoShift the job of defining NOMINMAX into source rather than the build system
Christopher Dykes [Mon, 22 May 2017 22:19:00 +0000 (15:19 -0700)]
Shift the job of defining NOMINMAX into source rather than the build system

Summary:
This makes it easier to consume Folly from a non-cmake project.
Note that this also requires making libevent, which was previously categorized as a semi-portable header into a non-portable header, meaning it can't be referenced directly. (libevent includes `Windows.h` in one of its headers -_-....)

Reviewed By: yfeldblum

Differential Revision: D5106051

fbshipit-source-id: 5ce2d4188c9036d6ab206af3036c8fd4b09516a4

5 years agoAdd LOCK_SHAREDMUTEX SSLLockType.
Kyle Nekritz [Mon, 22 May 2017 21:36:33 +0000 (14:36 -0700)]
Add LOCK_SHAREDMUTEX SSLLockType.

Summary: To take advantage of read locks.

Reviewed By: siyengar

Differential Revision: D5106090

fbshipit-source-id: a32afd698e9204196aa3d23f21a7d41803b2eb66

5 years agoRefactor folly/gen/test/StringTest.cpp v2017.05.22.00
Yedidya Feldblum [Sat, 20 May 2017 20:32:49 +0000 (13:32 -0700)]
Refactor folly/gen/test/StringTest.cpp

Summary:
[Folly] Refactor `folly/gen/test/StringTest.cpp`.

Prefer to compare whole values once per test case, rather than sequentially comparing each part in turn.

Reviewed By: andrewjcg

Differential Revision: D5101467

fbshipit-source-id: 3d19d32bc6a5ecc5863bea76c4292935c775fe75

5 years agoAdded a new variant of byLine to keep the delimiter
Song Zhou [Sat, 20 May 2017 14:53:57 +0000 (07:53 -0700)]
Added a new variant of byLine to keep the delimiter

Summary: new method byLineFull will not trim the delimiter so that consumers can check if final line is ended up with delimiter or not.

Reviewed By: philippv, yfeldblum

Differential Revision: D5085371

fbshipit-source-id: 5045127ee11d008e3cd7d13d33bffad280fe0a7e

5 years agofix PicoSpinLock for aarch64 and allow PackedSyncPtr to compile for aarch64
Stephen Chen [Sat, 20 May 2017 03:59:15 +0000 (20:59 -0700)]
fix PicoSpinLock for aarch64 and allow PackedSyncPtr to compile for aarch64

Summary:
Looks like we never tried to compile or run the PicoSpinLock under aarch64. There were two problems:

if sizeof(IntType) is 64, we try to do
  1 << 63
in lock and unlock. This doesn't compile because sizeof(1) is 32.

Also for try_lock, we were returning the data instead of checking for the locked bit.

Reviewed By: djwatson, yfeldblum

Differential Revision: D5091656

fbshipit-source-id: 4f81b8b32633e87b491548a1a24b9bcf20264063

5 years agoFix the linking of various tests against GMock
Christopher Dykes [Sat, 20 May 2017 03:57:10 +0000 (20:57 -0700)]
Fix the linking of various tests against GMock

Summary: A define was needed to be able to link when built against a shared-library version of gmock and gtest.

Reviewed By: yfeldblum

Differential Revision: D5100409

fbshipit-source-id: 9a4c9df20f682a25edde642c451476b2d1e1ae22

5 years agoMake a few adjustments to the compile config for the CMake build
Christopher Dykes [Sat, 20 May 2017 03:36:50 +0000 (20:36 -0700)]
Make a few adjustments to the compile config for the CMake build

Summary: This includes adding options to toggle `/std:c++latest`, and `WIN32_LEAN_AND_MEAN`, along with giving a nice drop-down selector to `MSVC_FAVORED_ARCHITECTURE` when configured via the GUI, dropping `_WINSOCK_DEPRECATED_NO_WARNINGS` as it wasn't needed, and re-enabling warnings 4365 and 4775 within the scope of the standard library.

Reviewed By: yfeldblum

Differential Revision: D5100586

fbshipit-source-id: 87b20c6415391d4f0c75837cad5bc312910bf49f

5 years agoMark constexpr values needed within non-implicitly-capturing lambdas as static
Christopher Dykes [Sat, 20 May 2017 03:33:41 +0000 (20:33 -0700)]
Mark constexpr values needed within non-implicitly-capturing lambdas as static

Summary: MSVC needs these to be marked as `static` in order to be accessible within the lambdas without capturing them.

Reviewed By: yfeldblum

Differential Revision: D5099607

fbshipit-source-id: 0270e2191d504f74b1902789b662e1766b2056c4

5 years agoWork around a compiler crash in VS 2017.3 Preview 1
Christopher Dykes [Sat, 20 May 2017 01:37:20 +0000 (18:37 -0700)]
Work around a compiler crash in VS 2017.3 Preview 1

Summary:
MSVC is being grumpy, and I want to continue to work from the preview build, so commit the workaround, as there's no significant difference.
Upstream bug report: https://developercommunity.visualstudio.com/content/problem/59614/compiler-crash-when-constexpr-constructing-stdchro.html

Reviewed By: yfeldblum

Differential Revision: D5099876

fbshipit-source-id: 64d5573d78b14339ff3177dd910a22787463ccd2

5 years agoFix the header being included when trying to specialize std::hash
Christopher Dykes [Fri, 19 May 2017 23:42:25 +0000 (16:42 -0700)]
Fix the header being included when trying to specialize std::hash

Summary: `std::hash` lives in `<functional>`, not `<xstddef>`.

Reviewed By: yfeldblum

Differential Revision: D5097468

fbshipit-source-id: d0684491d1d4b0f83f07ad837a66a915ce2ec8a6

5 years agoRemove FOLLY_SKIP_LIBCPP_4000_THROW_BACKPORTS
Shoaib Meenai [Fri, 19 May 2017 23:11:07 +0000 (16:11 -0700)]
Remove FOLLY_SKIP_LIBCPP_4000_THROW_BACKPORTS

Summary: 4.0 has been out for three months now, so it's pretty safe to remove them.

Reviewed By: Orvid, yfeldblum, mzlee

Differential Revision: D5096007

fbshipit-source-id: 595c3e86cd7cf1a1706f27f107fb0af8ab89a676

5 years agoStampedPtr: use async-signal-safe assert
Xiao Shi [Fri, 19 May 2017 14:23:29 +0000 (07:23 -0700)]
StampedPtr: use async-signal-safe assert

Summary: Use SafeAssert instead of assert.

Reviewed By: nbronson

Differential Revision: D5085575

fbshipit-source-id: daeff427b9b1fc5dff6ea986d16a70364acd2dd7

5 years agoThreadedRepeatingFunctionRunner: Name all the threads
Alexey Spiridonov [Wed, 17 May 2017 22:56:39 +0000 (15:56 -0700)]
ThreadedRepeatingFunctionRunner: Name all the threads

Summary: Name all repeating function threads for ease of debugging.

Reviewed By: yfeldblum

Differential Revision: D5065281

fbshipit-source-id: e875e654dfa644a265e44416baf5fbf23c9da434

5 years agoTweak basic_fbstring construction from std types
Phil Willoughby [Wed, 17 May 2017 11:05:52 +0000 (04:05 -0700)]
Tweak basic_fbstring construction from std types

Summary:
Previously we defined an assignment from std::string on all basic_fbstring
specialisations, but we don't actually want to do that because it's nonsense to
construct a basic_fbstring<char16_t> from an std::string. Equally it's not
nonsense to construct one of those from an std::u16string but the previous code
didn't allow it.

We now permit basic_fbstring<C, T, A1, S> to be constructed or assigned-to from
std::basic_string<C, T, A2>. The character type and traits must match but the
allocator is permitted to vary.

Background on my determination that the allocator type was unimportant and
could be disregarded: In part this is because C++17 made the same choice for
basic_string_view. Another factor was C++17's std::pmr::string (it's a
std::string with a different allocator) which I thought should be convertible
to fbstring in the same way as std::string.

Reviewed By: Gownta

Differential Revision: D5060569

fbshipit-source-id: f8984c528b76356240970c67916c58995d3f228d

5 years agoSimplify ThreadedRepeatingFunctionRunner by requiring classes that contain it to...
Alexey Spiridonov [Tue, 16 May 2017 21:05:49 +0000 (14:05 -0700)]
Simplify ThreadedRepeatingFunctionRunner by requiring classes that contain it to be final

Summary: It is pretty confusing to inherit from classes that manage threads. See the docblocks in this diff.

Reviewed By: yfeldblum

Differential Revision: D4973498

fbshipit-source-id: 2fcf1ddf68ef46d4d78a9b40f304262064862715

5 years agogate sse42 implementation of checksum for x86 only
Stephen Chen [Tue, 16 May 2017 17:06:47 +0000 (10:06 -0700)]
gate sse42 implementation of checksum for x86 only

Summary:
folly/detail/ChecksumDetail.h gets included in Checksum.h and it
unconditionally includes <immintrin.h>. This doesn't compile on
aarch64 platform. Add #ifdefs for this.

Reviewed By: yfeldblum

Differential Revision: D5048636

fbshipit-source-id: d2074eb1b01487b02d95f3e2eebe683237d918fe

5 years agoFix violations of unused-lambda-capture
Yedidya Feldblum [Tue, 16 May 2017 15:07:22 +0000 (08:07 -0700)]
Fix violations of unused-lambda-capture

Summary: [Folly] Fix violations of `unused-lambda-capture`.

Reviewed By: Orvid

Differential Revision: D5060391

fbshipit-source-id: 34aabc847719603d13da8f2b52a7ec187d803a4a

5 years agoSwitch implicit references of folly::make_unique to std::make_unique
Christopher Dykes [Tue, 16 May 2017 01:23:54 +0000 (18:23 -0700)]
Switch implicit references of folly::make_unique to std::make_unique

Summary: It's *almost* dead. This switches things to explicitly reference `std::make_unique` so that `folly::make_unique` can be marked as deprecated until mobile catches up and it can be killed completely.

Reviewed By: yfeldblum

Differential Revision: D5026584

fbshipit-source-id: aefc8cb3de84583fd3722fdb9dfea620884590c5

5 years agoDrop support for deprecated associative containers
Yedidya Feldblum [Mon, 15 May 2017 19:31:24 +0000 (12:31 -0700)]
Drop support for deprecated associative containers

Summary:
[Folly] Drop support for deprecated associative containers.

Namely, `__gnu_cxx::hash_set` and `__gnu_cxx::hash_map`.

Reviewed By: wqfish

Differential Revision: D5058813

fbshipit-source-id: ebbcf10765f5d06776ee8f697cfb78614a3a566c

5 years agoStampedPtr
Nathan Bronson [Mon, 15 May 2017 19:12:55 +0000 (12:12 -0700)]
StampedPtr

Summary:
This diff adds StampedPtr, which packs a pointer and a uint16_t into
a uint64_t with maximum portability and without adding any additional
functionality.

Reviewed By: yfeldblum, davidtgoldblatt

Differential Revision: D4804614

fbshipit-source-id: 25fe7aff47d1e126ac8edfff4eb0bbb1d34071aa

5 years agoIn AsyncSocket::handleErrMessages() inside the loop check if the callback was not...
Maxim Georgiev [Mon, 15 May 2017 19:01:31 +0000 (12:01 -0700)]
In AsyncSocket::handleErrMessages() inside the loop check if the callback was not uninstalled

Summary: AsyncSocket::handleErrMessages() should check if the error message callback is still installing before calling it, since the callback could be uninstaled on the previous loop iteration.

Reviewed By: yfeldblum

Differential Revision: D5051001

fbshipit-source-id: fc01932c0d36bd8f72bf1905f12211fb83d28674

5 years agoList the new GCC 4.9 and C++14 minimum requirement
Yedidya Feldblum [Mon, 15 May 2017 18:33:10 +0000 (11:33 -0700)]
List the new GCC 4.9 and C++14 minimum requirement

Summary:
[Folly] List the new GCC 4.9 and C++14 minimum requirement.

We no longer support GCC 4.8 or C++11.

Closes #590.

Reviewed By: Orvid, mzlee

Differential Revision: D5058942

fbshipit-source-id: 0545d1bb294494e5ef5f17a40c9cf3ac688bd8d0

5 years agoFix compilation ChecksumDetail.cpp with MSVC
Arkady Shapkin [Mon, 15 May 2017 14:43:38 +0000 (07:43 -0700)]
Fix compilation ChecksumDetail.cpp with MSVC

Summary:
MSVC doesn't support `^` and `&` operator for __m128i type
Closes https://github.com/facebook/folly/pull/594

Reviewed By: yfeldblum, Orvid

Differential Revision: D5053356

Pulled By: djwatson

fbshipit-source-id: f789824052e0c679c265c83ad704109805c21402

5 years agoFix compilation on Linux systems without vDSO support v2017.05.15.00
Koen De Keyser [Sat, 13 May 2017 18:01:56 +0000 (11:01 -0700)]
Fix compilation on Linux systems without vDSO support

Summary:
Problems:
- The vDSO check code in configure.ac is broken, and will always fail (uses AC_LANG_PROGRAM but with arguments in the AC_LANG_SOURCE style)
- On Linux, using dlopen/dlsym requires -ldl (libdl) during the link phase. This check was missing and this argument was not added to the linker arguments.
- On a Linux system without vDSO support, libfolly.so still uses vDSO in ClockGettimeWrappers.cpp

Solution:
- Switched to AC_LANG_SOURCE
- Required libdl to exist when build target is Linux. This also adds this dependency to libfolly.la, resulting in fixing a dependency issue for Proxygen (recent Proxygen build would have issues in building examples due to failing linking step due to missing dlopen / dlsym / dlclose symbols)
- In ClockGettimeWrappers.cpp, checking if `__linux__` is set is not sufficient to determine that the system has vDSO support. The autoconf script already exposes a correct check: FOLLY_HAVE_LINUX_VDSO (this is already used in folly/detail/CacheLocality.cpp), so switched to that one.
Closes https://github.com/facebook/folly/pull/592

Reviewed By: yfeldblum

Differential Revision: D5049816

Pulled By: Orvid

fbshipit-source-id: 58b2ed4c4101274505c61b4825accf262c0d56ef

5 years agoreturn range from AsyncIO::cancel(), fix test
Philip Pronin [Fri, 12 May 2017 23:07:57 +0000 (16:07 -0700)]
return range from AsyncIO::cancel(), fix test

Summary:
Return not just number of cancelled ops, but all of them as well.
Test was incorrectly assuming `wait(1)` will return exactly one operation, fix
that as well.

Reviewed By: ot

Differential Revision: D5054684

fbshipit-source-id: 1c53c3f7ba855d1fcfeac8b1b27f90f0872d2c21

5 years agoexception_wrapper::get_object<>
Yedidya Feldblum [Fri, 12 May 2017 21:14:22 +0000 (14:14 -0700)]
exception_wrapper::get_object<>

Summary:
[Folly] `exception_wrapper::get_object<>`.

Returns a pointer to the stored object, if the template type parameter is of the right sort.

Reviewed By: jsedgwick

Differential Revision: D5000720

fbshipit-source-id: 2869439085e8dfb56e6cb439794b03876b7d715c

5 years agoFix broken promise error in folly::retrying
Yinghai Lu [Fri, 12 May 2017 17:21:06 +0000 (10:21 -0700)]
Fix broken promise error in folly::retrying

Summary: This diff shows an issue in `folly::retrying`. When the future generation function throws an exception and `folly::retrying` is nested in another functor that returns Future, it will throw `broken promise` instead of the actual exception message, which can be very generic and confusing. Fix is to capture the exception so that exact error message can be propagated up.

Reviewed By: yfeldblum

Differential Revision: D5050690

fbshipit-source-id: 5b9b24977788f60aa778bb8e9cdf4281ea9a0023

5 years agoinclude folly/portability/Sockets.h instead of netinet/tcp.h
James Sedgwick [Fri, 12 May 2017 09:44:24 +0000 (02:44 -0700)]
include folly/portability/Sockets.h instead of netinet/tcp.h

Summary: To satisfy internal linter

Reviewed By: yfeldblum

Differential Revision: D4957870

fbshipit-source-id: 191ac768790fbd8cc8a4d24036c016644ff1d125

5 years agoadd FOLLY_FALLTHROUGH throughout to satisfy internal linter
James Sedgwick [Fri, 12 May 2017 04:31:22 +0000 (21:31 -0700)]
add FOLLY_FALLTHROUGH throughout to satisfy internal linter

Summary: changes as suggested by FB-internal linter

Reviewed By: yfeldblum

Differential Revision: D4957742

fbshipit-source-id: c9d94c477d24f153cab0d25edccfd39ff31fdfdf

5 years agoinclude folly/portability/OpenSSL.h instead of openssl/*.h
James Sedgwick [Fri, 12 May 2017 02:50:27 +0000 (19:50 -0700)]
include folly/portability/OpenSSL.h instead of openssl/*.h

Summary: suggested by internal linter

Reviewed By: Orvid

Differential Revision: D4958232

fbshipit-source-id: 69c67d80be092db17703d672524124ca5ef7ba32

5 years agoCopying a non-const FunctionRef lvalue should be a trivial operation
Eric Niebler [Thu, 11 May 2017 23:55:38 +0000 (16:55 -0700)]
Copying a non-const FunctionRef lvalue should be a trivial operation

Summary: Before this change, when a non-const FunctionRef lvalue is copied, it is treated as any other callable: it is wrapped with an indirection. That's semantically incorrect and potentially creates lifetime problems. Instead, use the compiler generated copy constructor, which only copies the object and function pointers.

Reviewed By: yfeldblum

Differential Revision: D5040843

fbshipit-source-id: f691060bdced2e287ba22d22b961c02c2b924147

5 years agoSwitch uncompressedLength to an Optional<uint64_t>
Nick Terrell [Thu, 11 May 2017 21:56:02 +0000 (14:56 -0700)]
Switch uncompressedLength to an Optional<uint64_t>

Summary: Instead of using `UNKNWON_UNCOMPRESSED_LENGTH` use an `Optional`.

Reviewed By: yfeldblum

Differential Revision: D5038919

fbshipit-source-id: 7fb60542277019996be3ff50509df5a5060cb1a0

5 years agoOutline `Optional::require_value()`
Ashwin Bharambe [Thu, 11 May 2017 20:29:41 +0000 (13:29 -0700)]
Outline `Optional::require_value()`

Summary:
We would like to use `folly/Optional` in settings where exceptions
are disabled. An example is ObjC++ codebases where supporting exceptions
doesn't quite help (since objc_msgSend() can throw) and yet we need to pay the
additional binary size cost for the unwind tables.

This patch makes a small change to outline the "assert" utility included
inside Optional.h

Reviewed By: yfeldblum, mzlee

Differential Revision: D5030172

fbshipit-source-id: 7def3c6eda22c41c8cab2037444978e0a4c50abf

5 years agoAsyncIO::cancel
Philip Pronin [Thu, 11 May 2017 19:51:11 +0000 (12:51 -0700)]
AsyncIO::cancel

Summary:
It should be implemented with `io_cancel`, but it is not
supported (D682836), so still have to drain events, ignoring only
op callbacks.

Reviewed By: luciang, ot

Differential Revision: D5044020

fbshipit-source-id: 0bcd04c91a437fccaf2189ccf771a1cb61c68942

5 years agoFix a race on destruction of ScopedEventBaseThread
Victor Zverovich [Thu, 11 May 2017 16:19:42 +0000 (09:19 -0700)]
Fix a race on destruction of ScopedEventBaseThread

Summary:
This diff fixes a race that happens on destruction of `ScopedEventBaseThread`.

```
Thread1: ~ScopedEventBaseThread()
Thread1: eb_.terminateLoopSoon() <- preempted just after stop_ = true
Thread2: eb->loopForever() in run(...) exits because stop_ is true
Thread2: ...
Thread2: eb->~EventBase()
Thread1: queue_->putMessage(nullptr) <- accesses destroyed EventBase
```

Reviewed By: yfeldblum

Differential Revision: D5042654

fbshipit-source-id: 95515ed7cde09ff5f125ef121bea86ab3907f98a

5 years agohasher instances for 8-bit and 16-bit integral types
Yedidya Feldblum [Thu, 11 May 2017 05:41:55 +0000 (22:41 -0700)]
hasher instances for 8-bit and 16-bit integral types

Summary:
[Folly] `hasher` instances for 8-bit and 16-bit integral types.

Allowing the use of `Hash` with such types.

They are not necessarily the ideal algorithms for those widths, essentially forwarding to the 32-bit instances.

Reviewed By: luciang

Differential Revision: D5043094

fbshipit-source-id: 6ef96dfc8d1baf0a15b9bdd585b7c7672099e4f0

5 years agoAdd writable() to AsyncTransport
Kevin Chen [Thu, 11 May 2017 02:42:00 +0000 (19:42 -0700)]
Add writable() to AsyncTransport

Summary:
This is useful for checking if it's possible to still write to a transport,
even if its read side is closed (for transports that support half shutdown,
like AsyncSocket). Default implementation just returns true for now (up
to implementers to override).

Reviewed By: yfeldblum

Differential Revision: D4982649

fbshipit-source-id: 0a9a2e2b745ea3db57e9f151f3a8634e1bda2465

5 years agoadd missing const to fix `folly::toDynamic` on `std::vector<bool>`
Mathieu Baudet [Thu, 11 May 2017 02:05:01 +0000 (19:05 -0700)]
add missing const to fix `folly::toDynamic` on `std::vector<bool>`

Summary: [folly] add missing const to fix `folly::toDynamic` on `std::vector<bool>`

Reviewed By: ender-wieczorek, yfeldblum

Differential Revision: D5039403

fbshipit-source-id: edd052c7d1d832d424166cba15fcd9f4f8bd219c

5 years agoAdd pollWithRusage to Subprocess
Victor Loh [Wed, 10 May 2017 06:24:57 +0000 (23:24 -0700)]
Add pollWithRusage to Subprocess

Summary:
I was looking for a way to get rusage of a particular pid because
getrusage isn't good enough since it records the rusage of all the children
that has been terminated (and waited for). Even though wait4 is marked as
deprecated, wait3 (the cousin of wait4) is still being used in places like
time. Furthermore, there is no suitable replacement to get rusage with wait*.

Reviewed By: yfeldblum

Differential Revision: D5008084

fbshipit-source-id: 6e511ebec7464d21309e5112aca95083e9307ea1

5 years agoRevert D4982969: [Folly] Destroy promise/future callback functions before waking...
Anton Lunov [Wed, 10 May 2017 05:48:50 +0000 (22:48 -0700)]
Revert D4982969: [Folly] Destroy promise/future callback functions before waking waiters

Summary: This reverts commit 71134c1657bdd4c38c12d8ca17f8335ef4c27352

Differential Revision: D4982969

fbshipit-source-id: fc1e766a5fd03fbd02c345904c3c6587013f38d5

5 years agoFix FBString with MSVC
Arkadiy Shapkin [Tue, 9 May 2017 22:38:27 +0000 (15:38 -0700)]
Fix FBString with MSVC

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

Reviewed By: ericniebler

Differential Revision: D5029876

Pulled By: yfeldblum

fbshipit-source-id: 6a8f16373dcfb1c7b2741eb808da0f6dbc4207b6

5 years agoAdd folly::Identity function object to Utility.h; replace AtomicHashArray's AHAIdenti...
Eric Niebler [Tue, 9 May 2017 21:30:11 +0000 (14:30 -0700)]
Add folly::Identity function object to Utility.h; replace AtomicHashArray's AHAIdentity and folly/gen's Identity with it

Summary: Code duplication is bad.

Reviewed By: yfeldblum

Differential Revision: D5011806

fbshipit-source-id: cab7bb3af1c934a5a63cd3fb98aa33f2578aebfb

5 years agoSupport static gflags library
Arkady Shapkin [Tue, 9 May 2017 03:43:36 +0000 (20:43 -0700)]
Support static gflags library

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

Reviewed By: yfeldblum

Differential Revision: D5022071

Pulled By: Orvid

fbshipit-source-id: 2506087de76ba4544bf68a330bc2a18977c65f28

5 years agoDestroy promise/future callback functions before waking waiters
Yedidya Feldblum [Tue, 9 May 2017 01:50:51 +0000 (18:50 -0700)]
Destroy promise/future callback functions before waking waiters

Summary:
Code may pass a callback which captures an object with a destructor which mutates through a stored reference, triggering heap-use-after-free or stack-use-after-scope.

```lang=c++
void performDataRace() {
  auto number = std::make_unique<int>(0);
  auto guard = folly::makeGuard([&number] { *number = 1; });
  folly::via(getSomeExecutor(), [guard = std::move(guard)]() mutable {}).wait();
  // data race - we may wake and destruct number before guard is destructed on the
  // executor thread, which is both stack-use-after-scope and heap-use-after-free!
}
```

We can avoid this condition by always destructing the provided functor before setting any result on the promise.

Reviewed By: spacedentist

Differential Revision: D4982969

fbshipit-source-id: 71134c1657bdd4c38c12d8ca17f8335ef4c27352

5 years agoback_emplace_iterator and related classes and utility functions
Philipp Unterbrunner [Tue, 9 May 2017 01:37:28 +0000 (18:37 -0700)]
back_emplace_iterator and related classes and utility functions

Summary:
C++ up to and including C++17 lacks an alternative to std::back_inserter() that uses emplace_back() instead of push_back(). This causes unnecessary temporary objects in some cases, when using std::back_inserter() together with STL functions such as std::copy() or std::transform(). The same holds for std::front_inserter() and std::inserter().
This diff introduces folly::back_emplacer(), folly::front_emplacer(), folly::emplacer(), and related iterator classes, which call emplace_back(), emplace_front(), and emplace() respectively, with perfect forwarding of any arguments to the output iterator's operator=.
Includes support for variadic emplacement / multi-argument constructors through a utility function folly::make_emplace_args() which packs its arguments into a special tuple for use with operator=.

Reviewed By: ericniebler

Differential Revision: D4897174

fbshipit-source-id: c85c30c457e0c946938051819baa662d1a0b8ca1

5 years agoCodemod folly::make_unique to std::make_unique
Christopher Dykes [Tue, 9 May 2017 01:16:18 +0000 (18:16 -0700)]
Codemod folly::make_unique to std::make_unique

Summary: There are still some upstream references to `folly::make_unique` that need to be removed before it can be full killed, but this gets it most of the way there.

Reviewed By: yfeldblum

Differential Revision: D5024310

fbshipit-source-id: 6cfe8ea93662be18bb55588c8200dec72946e205

5 years agochange EXPECT_EQ(false, ... to EXPECT_FALSE(...; ditto for true/EXPECT_TRUE
Jim Meyering [Mon, 8 May 2017 23:41:07 +0000 (16:41 -0700)]
change EXPECT_EQ(false, ... to EXPECT_FALSE(...; ditto for true/EXPECT_TRUE

Summary:
Change every instance of EXPECT_EQ(false, ... to the simpler/shorter EXPECT_FALSE(...
Likewise, convert each EXPECT_EQ(true, ... to EXPECT_TRUE(...

Differential Revision: D5019004

fbshipit-source-id: 0203f10fa47237f869a75a057ac4456ef03e1f53

5 years agoMove OpenSSLPtrTypes.h from folly/io/async/ssl to folly/ssl
Anirudh Ramachandran [Mon, 8 May 2017 19:21:47 +0000 (12:21 -0700)]
Move OpenSSLPtrTypes.h from folly/io/async/ssl to folly/ssl

Summary:
There's nothing io/async/ssl-specific in this file. Moving to the
top-level directory will help this be more discoverable. Part of general cleanup
for io/async/ssl

Reviewed By: yfeldblum

Differential Revision: D5005566

fbshipit-source-id: 66a05a2139ee80a6d63791d1851da3f1858e8abf

5 years agoAdd hardware crc impl
Dave Watson [Mon, 8 May 2017 16:44:17 +0000 (09:44 -0700)]
Add hardware crc impl

Summary:
A faster crc32 impl for folly.  Similar to crc32c, except
intel doesn't provide crc32 directly in hardware - instead, pclmul can be used,
which is ~2x slower than crc32c, but still ~5-10x faster than software implementation.

Reviewed By: Orvid, yfeldblum

Differential Revision: D4994761

fbshipit-source-id: ad8ba856649eea6dc7b541d561329ff7d7fe2d60

5 years agoFix folly::call_once v2017.05.08.00
Andrii Grynenko [Sat, 6 May 2017 18:01:13 +0000 (11:01 -0700)]
Fix folly::call_once

Summary: std::call_once implementation is broken if function throws. This fixes folly::call_once to not depend on std::call_once.

Reviewed By: yfeldblum

Differential Revision: D5015897

fbshipit-source-id: bcbda68becf0930cdbf0b09125cbee61d75c2015

5 years agoMark future-core get-state members as const noexcept
Yedidya Feldblum [Sat, 6 May 2017 04:15:35 +0000 (21:15 -0700)]
Mark future-core get-state members as const noexcept

Summary: [Folly] Mark future-core get-state members as `const noexcept`.

Reviewed By: andrewjcg

Differential Revision: D5014358

fbshipit-source-id: e39b0b63c59267a4ecfab5aac02e6d96ce2e7e00

5 years agoStop trying to setrlimit(RLIMIT_AS) in ASAN builds
Yedidya Feldblum [Sat, 6 May 2017 00:14:26 +0000 (17:14 -0700)]
Stop trying to setrlimit(RLIMIT_AS) in ASAN builds

Summary:
[Folly] Stop trying to `setrlimit(RLIMIT_AS)` in ASAN builds.

ASAN needs to reserve plenty of memory outside of the limited address space imposed by the call to `setrlimit`.

Reviewed By: andriigrynenko

Differential Revision: D5014679

fbshipit-source-id: 2ab71b1cca9297d3a276cf72154fac30a2057f86

5 years agoFixedString gets comparisons with folly::Range and hence with std::string
Eric Niebler [Fri, 5 May 2017 21:10:47 +0000 (14:10 -0700)]
FixedString gets comparisons with folly::Range and hence with std::string

Summary: It should be possible to perform simple comparison operations between a FixedString and a std::string. By adding asymmetric comparison operators with FixedString and Range, we make FixedString comparable with anything convertible to Range, including std::string.

Reviewed By: yfeldblum

Differential Revision: D5007704

fbshipit-source-id: fee89d8807ac2d5378eec0d0a51eb8684976a271

5 years agoFix getCurrentThreadName() on OSX
Christopher Dykes [Fri, 5 May 2017 19:03:21 +0000 (12:03 -0700)]
Fix getCurrentThreadName() on OSX

Summary: OSX was sad. Now it should be happy.

Reviewed By: mzlee

Differential Revision: D5011751

fbshipit-source-id: 77f22ff461036d8530d8f650396d8e12503448e7

5 years agoControl the number of threads in TestExecutor
Yedidya Feldblum [Fri, 5 May 2017 18:52:53 +0000 (11:52 -0700)]
Control the number of threads in TestExecutor

Summary:
[Folly] Control the number of threads in `TestExecutor`.

Let the caller control the number of threads to use in each given case.

Reviewed By: spacedentist

Differential Revision: D4999699

fbshipit-source-id: 4acf68cf17fbca14f0779daf0268d54c5606e4a8

5 years agoFuture: improve test with task discarding executors
Sven Over [Fri, 5 May 2017 16:12:51 +0000 (09:12 -0700)]
Future: improve test with task discarding executors

Summary:
We have tests that check that the Future implementation deals
cleanly with executors discarding tasks. The existing tests destroy
the tasks immediately when they are passed to Executor::add. This
diff adds corresponding tests for the scenario where the task is
not destroyed right away, but after the call to Future::then has
completed.

This diff also adds a mechanism to detect that the passed callback
function is actually destroyed. We have tested already that the
promise returned by folly::then will be set to a BrokenPromise
exception when the executor discards the task. However, the task
passed to the executor is not only the callback we pass to
folly::then, as the Future implementation wraps it with some code
that stores the return value in a Promise. Existing tests check
that this Promise is destroyed. The added mechanism in this diff
checks that the orignal callback function itself gets destroyed.

Reviewed By: Krigpl

Differential Revision: D5002100

fbshipit-source-id: 4155f61b075d9fe8d1869ad229f4d350571ff4c6

5 years agoAdd full noexcept annotations to Indestructible
Yedidya Feldblum [Fri, 5 May 2017 06:43:22 +0000 (23:43 -0700)]
Add full noexcept annotations to Indestructible

Summary:
[Folly] Add full `noexcept` annotations to `Indestructible`.

And do it without requiring `<type_traits>`.

Reviewed By: Orvid

Differential Revision: D4999243

fbshipit-source-id: f3521237ef4d03d2b187e9ebd6d0c90887872c42

5 years agoDelete operator=(std::string&&) from StringPiece
Christopher Dykes [Fri, 5 May 2017 01:32:45 +0000 (18:32 -0700)]
Delete operator=(std::string&&) from StringPiece

Summary: This can only ever be used unsafely, so delete it.

Reviewed By: yfeldblum

Differential Revision: D4951294

fbshipit-source-id: bbc266d1550fceb48946c7c48e76af07292b4a53

5 years agoSupport naming a ScopedEventBaseThread
Christopher Dykes [Thu, 4 May 2017 23:46:53 +0000 (16:46 -0700)]
Support naming a ScopedEventBaseThread

Summary:
The setThreadName API is in the process of being changed to not accept a thread id, which means the thread itself needs to set the name.
There are times where a `ScopedEventBaseThread` needs to be named, and this makes that possible.

Reviewed By: yfeldblum

Differential Revision: D4916781

fbshipit-source-id: dab05b520a715183ce069151ed16864fa1331abc

5 years agoAdd support for getting the current thread's name
Christopher Dykes [Thu, 4 May 2017 23:31:01 +0000 (16:31 -0700)]
Add support for getting the current thread's name

Summary: It's primarily for use in testing, but is useful for log output as well.

Reviewed By: yfeldblum

Differential Revision: D4943072

fbshipit-source-id: 0ca259d6c90f439e733a6179e7cba85dcd1ec9e7

5 years agoAdd thread-safe priority queue with arbitrary priorities using flat combining
Maged Michael [Thu, 4 May 2017 02:57:21 +0000 (19:57 -0700)]
Add thread-safe priority queue with arbitrary priorities using flat combining

Summary: This template uses flat combining and takes any sequential priority queue implementation that supports the `std::priority_queue` interface (`empty()`, `size()`, `push()`, `top()`, `pop()`) and any lock that meets the standard //Lockable// requirements to implement a thread-safe priority queue that supports arbitrary priorities. The template supports both unbounded and bounded size, and blocking, non-blocking, and timed variants of push, pop, and peek operations.

Reviewed By: djwatson

Differential Revision: D4873602

fbshipit-source-id: 96e1548b4f7427ecd2ee2ead7a19993df4441b33