5 years agoExpected coroutines support
Yedidya Feldblum [Thu, 26 Oct 2017 03:27:41 +0000 (20:27 -0700)]
Expected coroutines support

[Folly] `Expected` coroutines support.

Copied from `Optional` coroutines support.

Reviewed By: ericniebler, Orvid

Differential Revision: D5923792

fbshipit-source-id: 8661012c65762a0e540a4af2fd2fc237a8cb87a1

5 years agofolly: Fix data race in folly::Codel
Kenny Yu [Thu, 26 Oct 2017 01:11:02 +0000 (18:11 -0700)]
folly: Fix data race in folly::Codel

Data race reported by TSAN:

WARNING: ThreadSanitizer: data race (pid=608219)
  Read of size 1 at 0x7b5800000c29 by thread T314:
    #0 0x60b3441 in folly::Codel::overloaded(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) ./folly/executors/Codel.cpp:76
    #1 0x5c1222 in apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::Worker<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::run() ./thrift/lib/cpp/concurrency/ThreadManager.tcc:119
    #2 0x5d803e7 in apache::thrift::concurrency::PthreadThread::threadMain(void*) ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    #3 0x619739d in __tsan_thread_start_func crtstuff.c:?

  Previous write of size 1 at 0x7b5800000c29 by thread T315:
    #0 0x60b33e4 in folly::Codel::overloaded(std::chrono::duration<long, std::ratio<1l, 1000000000l> >) ??:?
    #1 0x5c1222 in apache::thrift::concurrency::ThreadManager::ImplT<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::Worker<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >::run() ./thrift/lib/cpp/concurrency/ThreadManager.tcc:119
    #2 0x5d803e7 in apache::thrift::concurrency::PthreadThread::threadMain(void*) ./thrift/lib/cpp/concurrency/PosixThreadFactory.cpp:200
    #3 0x619739d in __tsan_thread_start_func crtstuff.c:?

  Location is heap block of size 768 at 0x7b5800000c00 allocated by main thread:
    #0 0x616ab83 in operator new(unsigned long) ??:?
    #1 0x53cb92 in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<apache::thrift::concurrency::SimpleThreadManager<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > >, std::allocator<apache::thrift::concurrency::SimpleThreadManager<folly::LifoSemImpl<std::atomic, folly::Baton<std::atomic, true, true> > > >, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*)

It looks like there are multiple threads reading and writing the `overloaded_` bool. To fix it, wrap it in a `std::atomic`.

Reviewed By: yfeldblum, meyering

Differential Revision: D6149766

fbshipit-source-id: 605b29fa2f602d2ed2dfc22e46b739ef169f914e

5 years agorework reads/writes
Luca Niccolini [Wed, 25 Oct 2017 21:28:42 +0000 (14:28 -0700)]
rework reads/writes

the current implementation had problems with scheduling reads and writes and
it would sometimes get stuck when transfering large chunks of data

here I am restructuring the code to look more like the one in HTTPSession

session flow control is not implemented yet really, it's coming next

Depends on: D6048238

Reviewed By: afrind

Differential Revision: D6048238

fbshipit-source-id: ae601e771154a7f1a669a58a6e05c9e3720e7017

5 years agoSupply an explicit default dtor impl
Marko Novakovic [Wed, 25 Oct 2017 17:15:40 +0000 (10:15 -0700)]
Supply an explicit default dtor impl

Reviewed By: yfeldblum

Differential Revision: D6142252

fbshipit-source-id: 9ac98585a92299ca5915982c65c7d2cfa68bf60f

5 years agoFlesh out Optional members swap, reset, emplace, has_value
Yedidya Feldblum [Wed, 25 Oct 2017 05:05:23 +0000 (22:05 -0700)]
Flesh out Optional members swap, reset, emplace, has_value

[Folly] Flesh out `Optional` members `swap`, `reset`, `emplace`, `has_value`.

* `swap` as a member and deriving `noexcept`-ness to mimic `std::optional::swap`.
* `reset` v.s. `clear` to mimic `std::optional::reset`.
* `emplace` returning ref and overload taking initializer list to mimic `std::optional::emplace`.
* `has_value` v.s. `hasValue` to mimic `std::optional::has_value`.

Reviewed By: WillerZ

Differential Revision: D6132775

fbshipit-source-id: 34c58367b9dc63289e4b9721c5e79b1c41ba31e4

5 years agoSimplify IsUniquePtrToSL in IOBuf.h
Yedidya Feldblum [Wed, 25 Oct 2017 00:16:58 +0000 (17:16 -0700)]
Simplify IsUniquePtrToSL in IOBuf.h

Summary: [Folly] Simplify `IsUniquePtrToSL` in `IOBuf.h`.

Reviewed By: Orvid

Differential Revision: D6131231

fbshipit-source-id: b054ef7ef9f313943a3ac1022ca6a23874a464df

5 years agoMove folly/Hash.h to folly/hash/, leaving a shim
Yedidya Feldblum [Tue, 24 Oct 2017 21:12:03 +0000 (14:12 -0700)]
Move folly/Hash.h to folly/hash/, leaving a shim

Summary: [Folly] Move `folly/Hash.h` to `folly/hash/`, leaving a shim.

Reviewed By: Orvid

Differential Revision: D6132955

fbshipit-source-id: dc789e9c6daa28116be6a5d83c3cfbb40e247114

5 years agofix build with asan and static linking
Igor Sugak [Tue, 24 Oct 2017 17:55:58 +0000 (10:55 -0700)]
fix build with asan and static linking

Reviewed By: meyering

Differential Revision: D6117783

fbshipit-source-id: 048b056e119bf89ab88c33b1233297d197e8acb9

5 years agoPrefer bool literals rather than integers in boolean contexts
Christopher Dykes [Tue, 24 Oct 2017 02:26:29 +0000 (19:26 -0700)]
Prefer bool literals rather than integers in boolean contexts

Summary: Via clang-tidy's modernize-use-bool-literals

Reviewed By: yfeldblum

Differential Revision: D6130384

fbshipit-source-id: 359d5195897f04612c9b9042cf69383050a2ec7a

5 years agoConsistently have the namespace closing comment
Christopher Dykes [Tue, 24 Oct 2017 00:34:54 +0000 (17:34 -0700)]
Consistently have the namespace closing comment

Summary: It's done in a lot of places, but not all. clang-tidy gives us llvm-namespace-comment, which can force this consistently.

Reviewed By: yfeldblum

Differential Revision: D6108129

fbshipit-source-id: 1b44c5a26250364f9edf70f84173e9ba6389f06c

5 years agoModernize uses of std::make_shared
Christopher Dykes [Mon, 23 Oct 2017 23:52:19 +0000 (16:52 -0700)]
Modernize uses of std::make_shared

Summary: Via the modernize-make-shared from clang-tidy

Reviewed By: yfeldblum

Differential Revision: D6129464

fbshipit-source-id: 04f560c6beeb2b8631b819fd4e6a2d51b37eeb4b

5 years agoAdd a full drain for folly's ManualExecutor.
Lee Howes [Mon, 23 Oct 2017 20:36:48 +0000 (13:36 -0700)]
Add a full drain for folly's ManualExecutor.

Summary: ManualExecutor::run() is stable, which means that in cases where we want to fully drain the executor we have to loop over it. This adds ManualExecutor::drain() which does that internally.

Reviewed By: yfeldblum

Differential Revision: D6126840

fbshipit-source-id: e36cba5c373a57fe01de244977ec852636b58dbd

5 years agomove Iterator, Enumerate, EvictingCacheMap, Foreach, Merge, and
James Sedgwick [Mon, 23 Oct 2017 19:19:27 +0000 (12:19 -0700)]
move Iterator, Enumerate, EvictingCacheMap, Foreach, Merge, and

Summary: this is all non-hphp includes that are going in container/

Reviewed By: mzlee, yfeldblum

Differential Revision: D6121745

fbshipit-source-id: b024bde8835fc7f332686793d75eb8e71591c912

5 years agoMemoryIdler: use mallctl directly for tcache.flush
Qi Wang [Mon, 23 Oct 2017 19:09:40 +0000 (12:09 -0700)]
MemoryIdler: use mallctl directly for tcache.flush

tcache.flush may fail if tcache is disabled.  Avoid using mallctlCall
which throws on error.

Reviewed By: davidtgoldblatt

Differential Revision: D6115419

fbshipit-source-id: 39411c80af08dc7c855efd43297809b749f935bf

5 years agoModernize use of std::make_unique
Christopher Dykes [Mon, 23 Oct 2017 18:49:39 +0000 (11:49 -0700)]
Modernize use of std::make_unique

Summary: Via the clang-tidy check modernize-make-unique.

Reviewed By: yfeldblum

Differential Revision: D6107790

fbshipit-source-id: 1cf186feae511cbd91f44893059737a85778b6cf

5 years agoRename unique_lock variables in `TimedMutex` in order to avoid shadowing
Jon Maltiel Swenson [Mon, 23 Oct 2017 17:16:53 +0000 (10:16 -0700)]
Rename unique_lock variables in `TimedMutex` in order to avoid shadowing

Summary: Rename `std::unique_lock` variables named `lock` to `ulock` in `folly::fibers::TimedMutex` member functions in order to avoid shadowing.

Reviewed By: andreazevedo

Differential Revision: D6123449

fbshipit-source-id: 5fa331bb1541ac995d9b69360ee09923c14f6698

5 years agoGate std::invoke_result et. al. to appropriate MSVC versions.
Andrew Krieger [Mon, 23 Oct 2017 16:36:28 +0000 (09:36 -0700)]
Gate std::invoke_result et. al. to appropriate MSVC versions.

Summary: Only available in >= 2017 15.3, which is 1911+.

Reviewed By: aary, Orvid

Differential Revision: D6117237

fbshipit-source-id: 255804af5bfd0c743fd225b8a4fddf3cfc9cfeaf

5 years agomove Arena, ThreadCachedArena, and Malloc to memory/
James Sedgwick [Mon, 23 Oct 2017 14:27:04 +0000 (07:27 -0700)]
move Arena, ThreadCachedArena, and Malloc to memory/

Summary: all memory/-destined components besides hphp includes

Reviewed By: yfeldblum, mzlee

Differential Revision: D6121822

fbshipit-source-id: 6c6214d84dcdefe4789ed5200399ae27203d6340

5 years agomove futures/test/ExecutorTest.cpp to executors/ v2017.10.23.00
James Sedgwick [Sun, 22 Oct 2017 20:18:56 +0000 (13:18 -0700)]
move futures/test/ExecutorTest.cpp to executors/

Summary: also gotta split it up/rename it, that's coming later

Reviewed By: yfeldblum

Differential Revision: D6121525

fbshipit-source-id: 9c6dbabd47323d94657508a0f75a0c6e7f988ace

5 years agomove InlineExecutor, ManualExecutor, and GlobalThreadPoolList to
James Sedgwick [Sat, 21 Oct 2017 22:28:58 +0000 (15:28 -0700)]
move InlineExecutor, ManualExecutor, and GlobalThreadPoolList to

That's everything that's going in executors/ except for Executor.h
itself, which is included in hphp so will have to wait

Reviewed By: mzlee

Differential Revision: D6100274

fbshipit-source-id: 6be37892b1ad7f46828acfa6b2951e51b157a86a

5 years agomove MemoryMapping, Shell, ThreadId, ThreadName, and VersionCheck to system/
James Sedgwick [Sat, 21 Oct 2017 20:00:55 +0000 (13:00 -0700)]
move MemoryMapping, Shell, ThreadId, ThreadName, and VersionCheck to system/

Everything that's going in system/ besides CpuId and Subprocess,
which are included in hphp

Reviewed By: mzlee

Differential Revision: D6102263

fbshipit-source-id: 564ef584c341a4ac79db14a9d58fe23ce51e78b3

5 years agomove io/Compression and io/compression/* to compression/
James Sedgwick [Sat, 21 Oct 2017 17:25:08 +0000 (10:25 -0700)]
move io/Compression and io/compression/* to compression/

as above

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D6099826

fbshipit-source-id: 20152487135aa8eaf6d2e99369801b6dde4992aa

5 years agoUse folly/portability/GTest.h in folly/executurs/test/
Yedidya Feldblum [Sat, 21 Oct 2017 05:25:03 +0000 (22:25 -0700)]
Use folly/portability/GTest.h in folly/executurs/test/

[Folly] Use `folly/portability/GTest.h` in `folly/executurs/test/`.

Applying the general rule for folly tests to some recently-introduced violations.

Reviewed By: Orvid

Differential Revision: D6113707

fbshipit-source-id: f9a2961ac845489b85b5a539595e4c82df03d922

5 years agomove executor task queues and thread factories into subdirectories
James Sedgwick [Fri, 20 Oct 2017 20:30:03 +0000 (13:30 -0700)]
move executor task queues and thread factories into subdirectories

as title, see moves

(Note: this ignores all push blocking failures!)

Reviewed By: mzlee

Differential Revision: D6112001

fbshipit-source-id: 1eb10b44ae8ee1f90a10e05c29e48c99d824afa5

5 years agoDrop redundant void parameters from function declarations
Christopher Dykes [Fri, 20 Oct 2017 17:29:30 +0000 (10:29 -0700)]
Drop redundant void parameters from function declarations

This is C++, not C, so let's keep things modern.
This is applying the modernize-redundant-void-arg clang-tidy check to Folly.

Reviewed By: yfeldblum

Differential Revision: D6106921

fbshipit-source-id: 06a56f036f59426df5dd475bf91a3f4a335266f5

5 years agoMatch commented argument names with actual names
Christopher Dykes [Fri, 20 Oct 2017 05:48:29 +0000 (22:48 -0700)]
Match commented argument names with actual names

Summary: Via the clang-tidy check misc-argument-comment.

Reviewed By: yfeldblum

Differential Revision: D6107482

fbshipit-source-id: a1fe6215c31fae472ad3b6e05abea974d706794e

5 years agoUse nullptr rather than 0 for a null pointer
Christopher Dykes [Thu, 19 Oct 2017 23:13:58 +0000 (16:13 -0700)]
Use nullptr rather than 0 for a null pointer

Summary: This time aided by clang-tidy's modernize-use-nullptr check.

Reviewed By: yfeldblum

Differential Revision: D6102739

fbshipit-source-id: aeb4bd0a8078d81cc88b766e0a034a37dd25fd1f

5 years agomove CallOnce to synchronization/
James Sedgwick [Thu, 19 Oct 2017 21:08:04 +0000 (14:08 -0700)]
move CallOnce to synchronization/

Summary: as above

Reviewed By: knekritz

Differential Revision: D6088687

fbshipit-source-id: 0efbb7f5fa33b5f553c0c2019658370fc6e8613f

5 years agoHandle timekeeperSingleton being nullptr in within()
Alex Yarmula [Thu, 19 Oct 2017 20:35:27 +0000 (13:35 -0700)]
Handle timekeeperSingleton being nullptr in within()

Summary: When timekeeper singleton no longer exists during shutdown and folly::Singleton::try_get() can return nullptr, make sure nullptr is handled gracefully.

Reviewed By: yfeldblum

Differential Revision: D6101311

fbshipit-source-id: fefeddfbd048d1a7632688bb3526db15b685dd72

5 years agoAdd InlineExecutor.cpp to
Yedidya Feldblum [Thu, 19 Oct 2017 19:33:58 +0000 (12:33 -0700)]
Add InlineExecutor.cpp to

Summary: [Folly] Add `InlineExecutor.cpp` to ``.

Reviewed By: Orvid

Differential Revision: D6101859

fbshipit-source-id: 4cd0f875dedb548189722fd719f4424d485e1b02

5 years agoFix fibers build on older boost
Yedidya Feldblum [Thu, 19 Oct 2017 18:37:54 +0000 (11:37 -0700)]
Fix fibers build on older boost

[Folly] Fix `folly/fibers/` build on older boost.

Where `jump_fcontext` takes `intptr_t` rather than an actual pointer, and we warn about implicit conversions from pointers to integral types.

Reviewed By: Orvid

Differential Revision: D6098230

fbshipit-source-id: 61bd7bdff5de728d3febe8b35c97d024ab6f236a

5 years agoEnsure curly-braces around control-flow
Christopher Dykes [Thu, 19 Oct 2017 18:04:53 +0000 (11:04 -0700)]
Ensure curly-braces around control-flow

Summary: The style guidelines say control flow should always have curly braces, and we follow that, mostly. This just uses clang-tidy to clean up everywhere that we weren't.

Reviewed By: markisaa, luciang

Differential Revision: D6097377

fbshipit-source-id: bfe6766c37bd863ecf68851ef93265a200d4259d

5 years agomove ApplyTuple to functional/
James Sedgwick [Thu, 19 Oct 2017 14:45:51 +0000 (07:45 -0700)]
move ApplyTuple to functional/

Summary: as above

Reviewed By: yfeldblum

Differential Revision: D6086563

fbshipit-source-id: ab7f50ba46ebd1dbef6438f956258b2fbb13cb5c

5 years agoAdd ProducerConsumerQueue::capacity()
Peter Alexander [Thu, 19 Oct 2017 09:46:56 +0000 (02:46 -0700)]
Add ProducerConsumerQueue::capacity()

Summary: Simple addition. Easy to track externally, but might as well provide it in the class if it is readily available.

Reviewed By: yfeldblum

Differential Revision: D6093826

fbshipit-source-id: 9d8c02891b2cea9ce0d3f6ea78e1e0055b536eb8

5 years agoRevert D6050464: [Folly] Move folly/Hash.h to folly/hash/
Yedidya Feldblum [Thu, 19 Oct 2017 09:30:31 +0000 (02:30 -0700)]
Revert D6050464: [Folly] Move folly/Hash.h to folly/hash/

This reverts commit 64eb65aac8e3e7cd0126e65ca3998bfe167e2d73


Differential Revision: D6050464

fbshipit-source-id: 1ed63f30837dc11ae57b316f1f7cb233a210894a

5 years agoAdd window overload that takes an executor to prevent stack overflow
Walker Mills [Thu, 19 Oct 2017 07:57:03 +0000 (00:57 -0700)]
Add window overload that takes an executor to prevent stack overflow

AIUI, if there is no executor available, then callbacks are executed inline. `folly::window` uses a recursive helper function (`spawn`) to handle chaining callbacks. So if `window` is used on a large enough collection of `Future`s without executors (e.g., created by `makeFuture`, or have otherwise already completed), you get a stack overflow. A minimal repro looks like:

int main(int argc, char** argv) {
  std::vector<int> v(100000);
  for(int i=0; i < v.size(); i++) {
    v[i] = i;

  std::vector<folly::Future<folly::Unit>> f =
          [](int /* unused */) { return folly::makeFuture(); },

This diff resolves the issue by adding an overload of `folly::window` which takes an executor as its first parameter. The executor-less `window` overload calls through to the new function using an `InlineExecutor` as the default executor.

Reviewed By: yfeldblum

Differential Revision: D6038733

fbshipit-source-id: 5dcab575592650efa2e106f12632ec06817a0009

5 years agoMove folly/Hash.h to folly/hash/
Yedidya Feldblum [Thu, 19 Oct 2017 07:37:48 +0000 (00:37 -0700)]
Move folly/Hash.h to folly/hash/

Summary: [Folly] Move `folly/Hash.h` to `folly/hash/`.

Reviewed By: jsedgwick

Differential Revision: D6050464

fbshipit-source-id: 64eb65aac8e3e7cd0126e65ca3998bfe167e2d73

5 years agoEnable bug workaround also for MSVC 2017.4
Arkady Shapkin [Thu, 19 Oct 2017 02:35:00 +0000 (19:35 -0700)]
Enable bug workaround also for MSVC 2017.4

Workaround a bug in template instantiation in MSVC 2017 U3/4 with /permissive-

/cc Orvid

Reviewed By: yfeldblum

Differential Revision: D6085652

Pulled By: Orvid

fbshipit-source-id: f068dc3f8e474163815fc497b05410fe76834a52

5 years agoFix incorrect example usage in stop_watch
Boliu Xu [Thu, 19 Oct 2017 02:08:13 +0000 (19:08 -0700)]
Fix incorrect example usage in stop_watch

Summary: As titled.

Reviewed By: yfeldblum

Differential Revision: D6087099

fbshipit-source-id: 1c346fa6f65b5ea58e728759905560ae5ad9cc9d

5 years agoMove small fields to avoid padding in AsyncSocket.h and AsyncSSLSocket.h
Richard Fillman [Thu, 19 Oct 2017 00:19:59 +0000 (17:19 -0700)]
Move small fields to avoid padding in AsyncSocket.h and AsyncSSLSocket.h

Summary: Compiled mcrouter with the 'Wpadded' flag to try to find any wasted space. Mcrouter itself did not have anything, but there was a lot in AsyncSocket.h and AsyncSSLSocket.h so looked into those and removed a bit of wasted space

Reviewed By: yfeldblum, brianwatling

Differential Revision: D6033977

fbshipit-source-id: 2dc127208e09980be6a5db576b45d30ac6e044ff

5 years agomove futures/QueuedImmediateExecutor to executors/QueuedImmediateExecutor
James Sedgwick [Wed, 18 Oct 2017 23:32:35 +0000 (16:32 -0700)]
move futures/QueuedImmediateExecutor to executors/QueuedImmediateExecutor

Summary: as above

Reviewed By: yfeldblum

Differential Revision: D6076779

fbshipit-source-id: 4c223ab9fce3be8544f6f807781c3d0a99b61dad

5 years agoWorkaround MSVC bug with referencing template constructors before definition
Andrew Krieger [Wed, 18 Oct 2017 22:44:01 +0000 (15:44 -0700)]
Workaround MSVC bug with referencing template constructors before definition

MSVC has a bug where it is unable to match an out-of-line constructor (and
possibly other kind of member) to the definition if it is implicitly referenced
before the definition is processed. The guilty method is
SemiFuture<Unit> makeSemiFuture(). Moving it after the constructor definitions
resolves the issue.

Reviewed By: yfeldblum

Differential Revision: D6042277

fbshipit-source-id: 97fe97c0edf3df3d9e3b808968b450c73959b600

5 years agomove futures/ScheduledExecutor to executors/ScheduledExecutor
James Sedgwick [Wed, 18 Oct 2017 22:01:33 +0000 (15:01 -0700)]
move futures/ScheduledExecutor to executors/ScheduledExecutor

Summary: see title

Reviewed By: yfeldblum

Differential Revision: D6062601

fbshipit-source-id: edd9a5e85f4ebecd1a6f1004a4d3b8b43b935c2b

5 years agoMove folly/MallctlHelper.h to folly/memory/
Yedidya Feldblum [Wed, 18 Oct 2017 21:18:47 +0000 (14:18 -0700)]
Move folly/MallctlHelper.h to folly/memory/

Summary: [Folly] Move `folly/MallctlHelper.h` to `folly/memory/`.

Reviewed By: aary

Differential Revision: D6087216

fbshipit-source-id: 4e0fa4aea976e2578127d3c340e0e9b559a224ca

5 years agomove Partial to functional/
James Sedgwick [Wed, 18 Oct 2017 18:49:02 +0000 (11:49 -0700)]
move Partial to functional/

Summary: as above

Reviewed By: ngoyal

Differential Revision: D6087941

fbshipit-source-id: 948ff4f2faa87dd34f87d14ea01c83335f850a27

5 years agoUse nullptr rather than 0 when initializing pointers
Christopher Dykes [Wed, 18 Oct 2017 16:49:45 +0000 (09:49 -0700)]
Use nullptr rather than 0 when initializing pointers

Because we do this in a few places, and `nullptr` makes it far clearer what the intention is.
Note that with `-Wzero-as-null-pointer-constant` under GCC, doing `std::function<void()> f = {}` initializes `f` with a `0` rather than `nullptr`, triggering the warning, so I've enabled it there as well.
It is not currently possible to actually enable `-Wzero-as-null-pointer-constant`, because GCC 5 reports conversions resulting from a default value as occuring at the call-site rather than at the location where the parameter is defined, and the default allocator in libstdc++ is not clean for this particular warning -_-...

Reviewed By: yfeldblum

Differential Revision: D6046746

fbshipit-source-id: 6135bb20a503c861838575cf973324d74d75ca69

5 years agomove futures/DrivableExecutor to executors/DrivableExecutor
James Sedgwick [Wed, 18 Oct 2017 16:44:09 +0000 (09:44 -0700)]
move futures/DrivableExecutor to executors/DrivableExecutor

Summary: as title

Reviewed By: yfeldblum

Differential Revision: D6062437

fbshipit-source-id: 4f99e779e280fdb0b1f035013caff18764e86ab5

5 years agoLift the invoke helper in Function.h
Yedidya Feldblum [Wed, 18 Oct 2017 06:36:06 +0000 (23:36 -0700)]
Lift the invoke helper in Function.h

Summary: [Folly] Lift the `invoke` helper in `Function.h`.

Reviewed By: aary

Differential Revision: D6050569

fbshipit-source-id: da07901b8d058b0199d23db675c0fb9082fdf67d

5 years agomove python/NotificationQueueExecutor to futures/
James Sedgwick [Wed, 18 Oct 2017 03:21:36 +0000 (20:21 -0700)]
move python/NotificationQueueExecutor to futures/

Summary: as above

Reviewed By: yfeldblum

Differential Revision: D6076757

fbshipit-source-id: afe144129e8a0242ba6baee96a84a9084e6e2571

5 years agoSimplify impl of setThreadName
Yedidya Feldblum [Wed, 18 Oct 2017 02:28:49 +0000 (19:28 -0700)]
Simplify impl of setThreadName

Summary: [Folly] Simplify impl of `setThreadName`.

Reviewed By: Orvid, ot

Differential Revision: D6075179

fbshipit-source-id: 720f29cc688f97b936813898238b8eb26b8a6141

5 years agoDo not set WriteFlags::WRITE_MSG_ZEROCOPY if the buffer ! isManaged()
Dan Melnic [Tue, 17 Oct 2017 23:27:56 +0000 (16:27 -0700)]
Do not set WriteFlags::WRITE_MSG_ZEROCOPY if the buffer ! isManaged()

Summary: Do not set WriteFlags::WRITE_MSG_ZEROCOPY if the buffer isShared()

Reviewed By: yfeldblum

Differential Revision: D6068711

fbshipit-source-id: fff14dcd4fcb20c9dbb60794420845042518922c

5 years agoUn-templatize Range::str
Yedidya Feldblum [Tue, 17 Oct 2017 23:12:20 +0000 (16:12 -0700)]
Un-templatize Range::str

Summary: [Folly] Un-templatize `Range::str`.

Reviewed By: ot

Differential Revision: D6075642

fbshipit-source-id: 08fc399c43750d34463de7634be4fe386b5db97c

5 years agoRefactor ShutdownSocketSet atomic state machine
Yedidya Feldblum [Tue, 17 Oct 2017 23:09:36 +0000 (16:09 -0700)]
Refactor ShutdownSocketSet atomic state machine

[Folly] Refactor `ShutdownSocketSet` atomic state machine.

* Format.
* Use `while` over `goto`.
* Avoid `memory_order_acq_rel` as the single-argument memory order; some platforms fail to build that.
* Use `memory_order_relaxed` for all atomic operations because stronger memory orders are not actually required: the atomic state never serves as a barrier for synchronizing loads and stores of associated data because there is no associated data.

Reviewed By: davidtgoldblatt

Differential Revision: D6058292

fbshipit-source-id: d45d7fcfa472e6e393a5f980e75ad9ea3358bab3

5 years agoAn InlineExecutor singleton
Yedidya Feldblum [Tue, 17 Oct 2017 20:09:48 +0000 (13:09 -0700)]
An InlineExecutor singleton

[Folly] An `InlineExecutor` singleton.

Using the Leaky Meyers Singleton pattern, so that it is always available whenever required.

Differential Revision: D6074534

fbshipit-source-id: bd4c9cd6a1e60c80de5d2eef1cb6a1e7f16b4e50

5 years agoDon't make copies of std::string or fbstring when converting.
Andrew Krieger [Tue, 17 Oct 2017 16:17:30 +0000 (09:17 -0700)]
Don't make copies of std::string or fbstring when converting.

This overload of estimateSpaceNeeded was taking a Src by
value, but Src is constrained by IsSomeString which only returns
true for std::string or fbstring, so this was inducing a copy
in any situation where folly::to<> is used with varargs which
contain fb/string arguments.

Reviewed By: yfeldblum

Differential Revision: D6059517

fbshipit-source-id: adc239f9049e161fc4b750bae0e3de5dbdcd1bfc

5 years agoMake Range.h and FBString.h mutually independent
Yedidya Feldblum [Tue, 17 Oct 2017 03:10:35 +0000 (20:10 -0700)]
Make Range.h and FBString.h mutually independent

[Folly] Make `Range.h` and `FBString.h` mutually independent.

This means that `Range` cannot directly know about `fbstring`, so any interactions between the two types must be indirected through templates.

Motivation: `FBString.h` is a relatively heaviweight `#include` for things that need `Range.h` but which do not use `fbstring`.

Reviewed By: ericniebler

Differential Revision: D6062434

fbshipit-source-id: e2f21c33f482eadffd0a8679eff4ece59bab53e9

5 years agoShrink integral hasher specialization implementations
Yedidya Feldblum [Tue, 17 Oct 2017 02:25:47 +0000 (19:25 -0700)]
Shrink integral hasher specialization implementations

[Folly] Shrink integral `hasher` specialization implementations.

Instead of giving them bodies, just use inheritance.

Reviewed By: luciang

Differential Revision: D6067757

fbshipit-source-id: f71bd36132e1b66002493474825894b03754b34f

5 years agofix typo in invalid log level error message
Chad Austin [Mon, 16 Oct 2017 23:22:25 +0000 (16:22 -0700)]
fix typo in invalid log level error message

Reviewed By: simpkins

Differential Revision: D6068742

fbshipit-source-id: a3b3b7fe4a6da8f250e5b9593f66b9f8a9345136

5 years agofix typo
qiao hai-jun [Mon, 16 Oct 2017 18:18:55 +0000 (11:18 -0700)]
fix typo

Summary: Closes

Differential Revision: D6066294

Pulled By: yfeldblum

fbshipit-source-id: a533527058b8b5bc71fb6f40bad31a50e8c3f585

5 years ago4-way overloads for SemiFuture::value
Yedidya Feldblum [Mon, 16 Oct 2017 17:56:48 +0000 (10:56 -0700)]
4-way overloads for SemiFuture::value

[Folly] 4-way overloads for `SemiFuture::value`.

Overload on the receiver reference category and `const`-qualification, deriving the return type reference category and `const`-qualification. Like `Optional`, `Try`, etc.

Differential Revision: D6062006

fbshipit-source-id: d7396cd4d4bb62e99445d5f61cb360898fa1c3f3

5 years agoFix hash overloads for integral types
Ognjen Dragoljevic [Mon, 16 Oct 2017 14:24:15 +0000 (07:24 -0700)]
Fix hash overloads for integral types

`folly/Hash.h:379:12: error: implicit instantiation of undefined template 'folly::hasher<unsigned long, void>'`
So, folly is unable to hash the very type it returns: `size_t`. Namely, folly has overloads for `uint32_t` and `uint64_t` which on my Mac map to `int` and `long long` respectively. `size_t` on the other hand maps to `long` which is neither.
Rather than overloading library types (which are just typedefs), we should overload all the built-in types: `char`, `short`, `int`, `long`, `long long`, `signed` and `unsigned` variants (with special treatment of `char`).

Reviewed By: yfeldblum, luciang

Differential Revision: D6051600

fbshipit-source-id: d59569dab963cbe0329aa589ff321cfb22308193

5 years agoconstexpr estimateSpaceNeeded for string literals. v2017.10.16.00
Andrew Krieger [Mon, 16 Oct 2017 04:30:56 +0000 (21:30 -0700)]
constexpr estimateSpaceNeeded for string literals.

Partially inspired by WillerZ's investigation into faster compiling
StringPiece work, I thought this would be an easy drop in that short
circuits some compilation logic (or possibly is strictly better, since the
StringPiece conversion method isn't constexpr).

Reviewed By: yfeldblum

Differential Revision: D6059537

fbshipit-source-id: 072f56e58aa47db10b54825cac8a05dc035b295c

5 years agoMove retrying method to separate header in folly/futures
Marc Celani [Sun, 15 Oct 2017 21:24:44 +0000 (14:24 -0700)]
Move retrying method to separate header in folly/futures

Summary: folly/futures depends on folly/Random.h, which in turn depends on <random>, which is a fairly large header. Most users of folly::futures do not use retrying, so separate it into a separate header.

Reviewed By: yfeldblum

Differential Revision: D6028468

fbshipit-source-id: d8155fe2ddff1a65c265a18f040ee6f1be3f3f0a

5 years agoStyle fixes for folly/experimental/gdb/
Yedidya Feldblum [Fri, 13 Oct 2017 23:14:37 +0000 (16:14 -0700)]
Style fixes for folly/experimental/gdb/

[Folly] Style fixes for `folly/experimental/gdb/`.

Should have no effect on Github rendering, but should affect PHabricator rendering.

Reviewed By: Orvid, kennyyu

Differential Revision: D6055017

fbshipit-source-id: 54204a2b77beeb884cdc486207809f78ac80afe2

5 years agoAdd AsyncSocketException.cpp to build sources
Neel Goyal [Fri, 13 Oct 2017 19:22:08 +0000 (12:22 -0700)]
Add AsyncSocketException.cpp to build sources

Summary: Add AsyncSocketException.cpp to the list of files to build in

Reviewed By: knekritz

Differential Revision: D6051989

fbshipit-source-id: 72083a609fc994770eca078bfef5a0ed04322bfc

5 years agoReplace ShutdownSocketSet to singleton
Vitaly Berov [Fri, 13 Oct 2017 16:30:02 +0000 (09:30 -0700)]
Replace ShutdownSocketSet to singleton

We recently found out that ShutdownSocketSet consumes 150+MB for our service, which uses duplex channels. The problem is that we create ~1000 of ThriftServers, and each of the creates its own ShutdownSocketSet.
In reality, ShutdownSocketSet is only needed to kill all socket's FD in emergency before crash dump is taken, so they don't hand around waiting for crash dump to complete. There is no need to keep a SSS per ThriftServer, singleton should work just fine.
There is a problem here, though. Currently a ThriftServer has 'immediateShutdown' method, which kills all sockets from SSS. So, if SSS becomes a singleton, and we have more than one ThriftServer, calling 'immediateShutdown' on one will kill sockets from the other one. First, it's a quite surprising behavior, and second, it complicates unit tests, which emulate thrift servers running in different processes.

As a result,
1. ShutdownSocketSet is created as a singleton, but each ThriftServer still keeps weak ptr to it (mostly for unit tests support).
2. replaceShutdownSocketSet method is added to ThriftServer.h, so unit tests could set different SSS for different ThriftServers.
3. method immediateShutdown is removed from ThriftServer, because its behavior would be 'surprising'.

There still may be unexpected consequences of this change for the tests because of Singleton, but let's see.

Reviewed By: yfeldblum

Differential Revision: D6015576

fbshipit-source-id: dab70dbf82d01bcc71bbe063f983e862911ceb24

5 years agofolly: AsyncSocketException: move implementation to .cpp, refactor
Lucian Grijincu [Fri, 13 Oct 2017 08:58:11 +0000 (01:58 -0700)]
folly: AsyncSocketException: move implementation to .cpp, refactor

Reviewed By: yfeldblum

Differential Revision: D6042832

fbshipit-source-id: c716ee672c4acfa39cab9f10f3b3f88ca770cd20

5 years agoMove folly/Checksum.h into folly/hash/
Yedidya Feldblum [Fri, 13 Oct 2017 04:21:17 +0000 (21:21 -0700)]
Move folly/Checksum.h into folly/hash/

Summary: [Folly] Move `folly/Checksum.h` into `folly/hash/`.

Reviewed By: Orvid

Differential Revision: D6045825

fbshipit-source-id: 02d3e6a49e2c0fc115cfee09e1186be7a13525ba

5 years agoAdd support for clang intrinsic constexpr
Miroslav Crnic [Wed, 11 Oct 2017 08:43:41 +0000 (01:43 -0700)]
Add support for clang intrinsic constexpr

Summary: Newer versions of clang >=3.4 support intrinsic constexpr

Reviewed By: Orvid

Differential Revision: D6008856

fbshipit-source-id: 4e40a7032464216d181d76a854cafb2ab4be1be0

5 years agoHandle nullptr from getTimekeeperSingleton
Cameron Pickett [Tue, 10 Oct 2017 09:39:20 +0000 (02:39 -0700)]
Handle nullptr from getTimekeeperSingleton

According to folly::Singleton::try_get(),, the caller is responsible for handling a nullptr return. In this case, we handle it poorly, via a crash both in production and debug code.

This diff opts for handling the nullptr more gracefully, via a future loaded with an exception.

Reviewed By: yfeldblum

Differential Revision: D6006864

fbshipit-source-id: e8fde57ed161b33fa1f157ce663ed85e69640c25

5 years agoAdd SO_ZEROCOPY support v2017.10.09.00
Dan Melnic [Mon, 9 Oct 2017 01:27:54 +0000 (18:27 -0700)]
Add SO_ZEROCOPY support

Summary: Add SO_ZEROCOPY support

Reviewed By: djwatson

Differential Revision: D5851637

fbshipit-source-id: 5378b7e44ce9d888ae08527506218998974d4309

5 years agoLet EventBase::runInEventBaseThreadAndWait consume its argument
Yedidya Feldblum [Sat, 7 Oct 2017 01:04:56 +0000 (18:04 -0700)]
Let EventBase::runInEventBaseThreadAndWait consume its argument

[Folly] Let `EventBase::runInEventBaseThreadAndWait` consume its argument.

Likewise `EventBase::runImmediatelyOrRunInEventBaseThreadAndWait`.

And enforce that the function is destructed before returning, so that, in the case of a wrapped lambda, all captured objects' destructors run before returning from the function.

Reviewed By: elsteveogrande

Differential Revision: D5994106

fbshipit-source-id: 816c9431a85a3d41e4fda321065614f4c18f0697

5 years agofuture.then() is identical to future.unit()
Stiopa Koltsov [Fri, 6 Oct 2017 20:07:02 +0000 (13:07 -0700)]
future.then() is identical to future.unit()

Document that `future.then()` is identical to `future.unit()`.

Put functions next to each other to make it clear, and use identical

Reviewed By: yfeldblum

Differential Revision: D5955451

fbshipit-source-id: 1b55d5785dc0995d4d9364f48241e98ad01b31f4

5 years agoRemove Executor::addPtr
Yedidya Feldblum [Fri, 6 Oct 2017 18:45:18 +0000 (11:45 -0700)]
Remove Executor::addPtr

[Folly] Remove `Executor::addPtr`.

It was there to support passing non-copyable callable objects wrapped as `std::shared_ptr`. It is no longer useful since we have `Function`, which is a non-copyable version of `std::function` which can support capturing non-copyable objects, and it is generally unused.

Reviewed By: spacedentist

Differential Revision: D5983801

fbshipit-source-id: b49a86f8dd7e5250a097b0e714a1bdf9ac362916

5 years agoWorkaround for a gcc crash
Jun Qu [Fri, 6 Oct 2017 16:54:59 +0000 (09:54 -0700)]
Workaround for a gcc crash

Summary: I recently got a gcc crash when using `ConcurrentHashMap`

Reviewed By: djwatson

Differential Revision: D5994587

fbshipit-source-id: 412d48aa6da12c428bb9ab5ed7a317d89c9580b9

5 years agoadd static makeFromPath to construct SocketAddress from a unix domain socket path
Valeriy Khromov [Fri, 6 Oct 2017 11:38:06 +0000 (04:38 -0700)]
add static makeFromPath to construct SocketAddress from a unix domain socket path

Add `SocketAddress::makeFromPath(StringPiece)` static member function to
constructor `SocketAddress` from a path to Unix domain socket.

Reviewed By: yfeldblum

Differential Revision: D5974523

fbshipit-source-id: b5c1537e67d07d1ef401fea75e35753392eeaf6b

5 years agoUse fewer keep-alives in VirtualEventBase::keepAliveRelease
Yedidya Feldblum [Fri, 6 Oct 2017 00:02:00 +0000 (17:02 -0700)]
Use fewer keep-alives in VirtualEventBase::keepAliveRelease

[Folly] Use fewer keep-alives in `VirtualEventBase::keepAliveRelease`.

{D5982132} mistakenly used `VirtualEventBase::add`, which holds a keep-alive on the master `EventBase`, instead of calling `EventBase::add` directly.

(Note: this ignores all push blocking failures!)

Reviewed By: andriigrynenko

Differential Revision: D5992403

fbshipit-source-id: f427025c06f01e6a93d6eae8a051c3553f58be20

5 years agoMake keepAliveRelease consistent between EventBase and VirtualEventBase
Yedidya Feldblum [Thu, 5 Oct 2017 22:52:28 +0000 (15:52 -0700)]
Make keepAliveRelease consistent between EventBase and VirtualEventBase

Summary: [Folly] Make `keepAliveRelease` consistent between `EventBase` and `VirtualEventBase`.

Reviewed By: elsteveogrande

Differential Revision: D5982132

fbshipit-source-id: 536d48e5672567e78786691bfb283c34d1f31960

5 years agoMove GlobalThreadPoolList.h into folly/concurrency/
Yedidya Feldblum [Thu, 5 Oct 2017 22:40:50 +0000 (15:40 -0700)]
Move GlobalThreadPoolList.h into folly/concurrency/

[Folly] Move `GlobalThreadPoolList.h` into `folly/concurrency/`.

This seems like a better place than the top-level. It seems reasonable because this has *something* to do with concurrency. This is used by executors, but is not itself an executor, so it was not clear that it should go to `folly/executors/`, although that also seems like quite the reasonable choice.

Reviewed By: Orvid

Differential Revision: D5985142

fbshipit-source-id: 6117d133757af74023d6cffb838741da83d173bd

5 years agoAdd an overload to use backlashify with StringPiece
Andre Pinto [Thu, 5 Oct 2017 15:34:49 +0000 (08:34 -0700)]
Add an overload to use backlashify with StringPiece

Summary: Allows calling backlashify on a StringPiece.

Reviewed By: yfeldblum

Differential Revision: D5930015

fbshipit-source-id: ca14c78d9a90c45781da7229eb5d2f437792b2d1

5 years agoAdd SemiFuture class.
Lee Howes [Thu, 5 Oct 2017 02:59:14 +0000 (19:59 -0700)]
Add SemiFuture class.

Offer a clean separation between future as a vocabulary type for crossing
library interfaces, and future as a type to manage continuations.

The principle is that if we want an API with clean separation of execution it
should both return and receive SemiFutures. The returned SemiFuture would
only be awaitable, but not continuable. If the caller wants to enqueue a
continuation then it is efficiently convertable into a folly::Future by
calling .via.

This means that an API a) Does not have to take an executor to ensure it
returns a valid future. That can be deferred to the caller or the caller's
caller/target for true separation. b) The API can ensure that its own executor
is not exposed to the caller, while still having a clean API.

Obviously if some API wants to allow returning of a continuable future, then it
can also provide an executor-taking API.

Reviewed By: yfeldblum

Differential Revision: D5769284

fbshipit-source-id: 46241d1274bf7b1698a7d28a47cff2a65a983740

5 years agogive folly future's exceptions default visibility
Eric Niebler [Wed, 4 Oct 2017 21:56:25 +0000 (14:56 -0700)]
give folly future's exceptions default visibility

Summary: Exception types should have default visibility, otherwise RTTI doesn't work right.

Reviewed By: elsteveogrande

Differential Revision: D5976415

fbshipit-source-id: 45dcfe3476b513aa49a6f78352318f31d381ada7

5 years agoMove keepalive-acquire code into Executor::keepAliveAcquire overrides
Yedidya Feldblum [Wed, 4 Oct 2017 18:56:32 +0000 (11:56 -0700)]
Move keepalive-acquire code into Executor::keepAliveAcquire overrides

[Folly] Move keepalive-acquire code into `Executor::keepAliveAcquire` overrides.

This makes the API more symmetric and allows for more flexibility. Also serves as preparation for generalizing the keepalive-token interface.

Reviewed By: andriigrynenko

Differential Revision: D5974080

fbshipit-source-id: 26209e49a0f5834ba229d4bbfc9272c2e4ffb3fd

5 years agoBenchmark comparison
Tom Jackson [Wed, 4 Oct 2017 17:31:05 +0000 (10:31 -0700)]
Benchmark comparison

I couldn't find anything that consumes `--json` output, so I made this. It prints out benchmark results from two runs, comparing each benchmark to its corresponding baseline. This should help with benchmarking changes across revisions.

Along the way:
- Two small transparent `struct`s replaces the use of `tuple`s everywhere.
- New output JSON format (additive), formatted as array of arrays so order is preserved.
- New comparison binary in `folly/tools/benchmark_compare`

Sample output:


Reviewed By: yfeldblum

Differential Revision: D5908017

fbshipit-source-id: d7411e22b459db16bd897f656e48ea4e896cb1bf

5 years agoLet keep-alive tokens from VirtualEventBase be destroyed from any thread
Yedidya Feldblum [Wed, 4 Oct 2017 06:50:27 +0000 (23:50 -0700)]
Let keep-alive tokens from VirtualEventBase be destroyed from any thread

[Folly] Let keep-alive tokens from `VirtualEventBase` be destroyed from any thread.

This case was missed in {D5951397} (facebook/folly@6f3b7616f3402355441c62ca60a36159435aa818).

Reviewed By: andriigrynenko

Differential Revision: D5970670

fbshipit-source-id: 19e2b00134516e68113234acd6111e21c3e23e8d

5 years agoDynamic MPMCQueue: Backout of last change as it may deadlock
Maged Michael [Tue, 3 Oct 2017 19:19:29 +0000 (12:19 -0700)]
Dynamic MPMCQueue: Backout of last change as it may deadlock

Summary: The previous change can lead to deadlock. Backing out.

Reviewed By: djwatson

Differential Revision: D5957084

fbshipit-source-id: 72ea1cb6236367912b4b087da7e4d57f8a2daed0

5 years agoFixes: prevent compiler reporting UB, hazptr_array move operator, empty array test
Maged Michael [Tue, 3 Oct 2017 14:56:57 +0000 (07:56 -0700)]
Fixes: prevent compiler reporting UB, hazptr_array move operator, empty array test

Three fixes:
(1) The compiler reports UB in line 432 for the case M > HAZPTR_TC_SIZE even though it is executed only if M <= HAZPTR_TC_SIZE. Added a condition M <= HAZPTR_TC_SIZE to help the compiler determine that line 432 is not executed in that case.
(2) Added missing management of empty state in hazptr_array move operator
(3) Added nullptr argument to empty hazptr_array in Array test

Reviewed By: djwatson

Differential Revision: D5951283

fbshipit-source-id: cb8e61421ab06c7733f67bf2d2274d3311260ac4

5 years agoLet keep-alive tokens be destroyed from any thread
Yedidya Feldblum [Tue, 3 Oct 2017 02:45:55 +0000 (19:45 -0700)]
Let keep-alive tokens be destroyed from any thread

Summary: [Folly] Let keep-alive tokens be destroyed from any thread.

Reviewed By: andriigrynenko

Differential Revision: D5951397

fbshipit-source-id: 91e72588de4ef33a730ebef5770e77635d4e93ba

5 years agofix -Wvexing-parse
Igor Sugak [Mon, 2 Oct 2017 20:42:09 +0000 (13:42 -0700)]
fix -Wvexing-parse

folly/test/stl_tests/StlVectorTest.cpp:1975:11: error: parentheses were disambiguated as redundant parentheses around declaration of variable named 'm' [-Werror,-Wvexing-parse]
folly/test/stl_tests/StlVectorTest.cpp:1975:11: note: add a variable name to declare a 'Vector' initialized with 'm'
folly/test/stl_tests/StlVectorTest.cpp:1975:5: note: add enclosing parentheses to perform a function-style cast
    (        )
folly/test/stl_tests/StlVectorTest.cpp:1975:11: note: remove parentheses to silence this warning
          ^ ~

1 error generated.

Reviewed By: Gownta

Differential Revision: D5955613

fbshipit-source-id: 3015570ce111603b3561914d07b55365a221c686

5 years agoMove Merge.h into folly/algorithm/ v2017.10.02.00
Yedidya Feldblum [Mon, 2 Oct 2017 05:11:27 +0000 (22:11 -0700)]
Move Merge.h into folly/algorithm/

Summary: [Folly] Move `Merge.h` into `folly/algorithm/`.

Reviewed By: Orvid

Differential Revision: D5951346

fbshipit-source-id: 487203e55e2a44888e599ca22849798154e5b386

5 years agoOptimize local and bulk management of hazptr_holder-s
Maged Michael [Sun, 1 Oct 2017 01:11:41 +0000 (18:11 -0700)]
Optimize local and bulk management of hazptr_holder-s

- Added hazptr_local<M> for optimized management of local hazptr_holder-s.
- Added hazptr_array<M> for optimized management of hazptr_holder-s
- Added benchmarks for hazptr_local and hazptr_array
- Added tests for hazptr_local and hazptr_array
- Changed SWMRList example to use hazptr_local<2> instead of two hazptr_holder-s.
- Updated benchmark performance results.

Reviewed By: davidtgoldblatt

Differential Revision: D5833721

fbshipit-source-id: 154811f67c38abac7342cecb71f829778ccf76b2

5 years agoShort-Circuit within() When Future Is Already Complete
Felix Handte [Fri, 29 Sep 2017 19:41:24 +0000 (12:41 -0700)]
Short-Circuit within() When Future Is Already Complete

As title. No sense adding a timeout to the timeout manager when the future is
already complete.

Reviewed By: yfeldblum

Differential Revision: D5933144

fbshipit-source-id: 4d1bbd866c47ccee6bd0518cbe063afc1d34cbca

5 years agodelete deprecated SSLContext::setSSLLockTypes
Igor Sugak [Fri, 29 Sep 2017 06:35:24 +0000 (23:35 -0700)]
delete deprecated SSLContext::setSSLLockTypes

Summary: This is deprecated and not used.

Reviewed By: yfeldblum

Differential Revision: D5936286

fbshipit-source-id: 68f757be06ebe375e14db008d0e5828fad0c3aa5

5 years agoAdd AsyncSocketExceptionType for early data rejection.
Kyle Nekritz [Wed, 27 Sep 2017 20:11:31 +0000 (13:11 -0700)]
Add AsyncSocketExceptionType for early data rejection.

Summary: To be used to signal that data that was sent as TLS 1.3 early data was lost. This needs its own exception type as it requires special handling (ie it should usually be retried immediately).

Reviewed By: siyengar

Differential Revision: D5869914

fbshipit-source-id: ca0d8ef19cb991e9d6ffe0f8c99abfb03b748ce6

5 years agoFix unittest compile error on futures/test/RetryingTest.cpp.
Mohamed Amin JABRI [Wed, 27 Sep 2017 17:38:18 +0000 (10:38 -0700)]
Fix unittest compile error on futures/test/RetryingTest.cpp.

On MacOS compiling unittests with "make chek" shows the following compile
../futures/test/RetryingTest.cpp:168:26: error: no matching function for call to 'min'
 newMemLimit.rlim_cur = std::min(1UL << 30, oldMemLimit.rlim_max);

Reviewed By: elsteveogrande

Differential Revision: D5921433

Pulled By: yfeldblum

fbshipit-source-id: 236d8336f852750a983c2e268db8811d1a4ed9ee

5 years agoDelete conversion from Objective-C block to folly::Function
Michael Lee [Tue, 26 Sep 2017 15:35:09 +0000 (08:35 -0700)]
Delete conversion from Objective-C block to folly::Function

Summary: Objective-C blocks are stack allocated, and unless there is a proper assignment it isn't retained and the memory is freed. Because folly::Function used to move, it would hold a reference, but after switch to a constructor by-value, it no longer does this and we see a use-after-free.

Reviewed By: yfeldblum, ericniebler

Differential Revision: D5888606

fbshipit-source-id: fe4cabb2f2ae289cce0e7429e0af3935ba314720

5 years agoLet ProcessReturnCode be publicly constructible v2017.09.25.00
Yedidya Feldblum [Sun, 24 Sep 2017 06:12:57 +0000 (23:12 -0700)]
Let ProcessReturnCode be publicly constructible

[Folly] Let `ProcessReturnCode` be publicly constructible.

Via provided constructor functions, which limit how it may be constructed so that it is only constructible into a valid state.

Differential Revision: D5898739

fbshipit-source-id: 7490018adfc39408b4290248ef1220e8fd0238cb

5 years agoAvoid tautological compare in folly/experimental/symbolizer/
Yedidya Feldblum [Sat, 23 Sep 2017 04:19:34 +0000 (21:19 -0700)]
Avoid tautological compare in folly/experimental/symbolizer/

[Folly] Avoid tautological compare in `folly/experimental/symbolizer/`.

`x < 0` when `x` is unsigned is tautological and there are warnings against such comparisons. The underlying type of an unscoped enumerations without a fixed underlying type is not specified, and whether it is signed is also not specified; it could be unsigned, and is unsigned in practice in common cases.

Reviewed By: Orvid, eduardo-elizondo

Differential Revision: D5897792

fbshipit-source-id: 24d84f9bf2c61c907585e1b675c2bbf11ef1720b

5 years agoFix deadlock in TimedMutex
Matthew Tolton [Sat, 23 Sep 2017 00:32:21 +0000 (17:32 -0700)]
Fix deadlock in TimedMutex

If a lock is stolen from fiber f1, and then fiber f2 is notified before f1 one
wakes up and discovers the crime, then f1 will clear notifiedFiber_ so that f2
thinks the lock was stolen from it as well and hence recurses back into lock().

Reviewed By: andriigrynenko

Differential Revision: D5896323

fbshipit-source-id: 528ec1ed983175d3e08f3dc07b69bbc783a86cfb

5 years agofix ASAN stl_tests:stl_vector_test
Nathan Bronson [Fri, 22 Sep 2017 19:01:30 +0000 (12:01 -0700)]
fix ASAN stl_tests:stl_vector_test

folly/test/stl_tests/StlVectorTest.cpp was too slow under
mode/dev-asan, resulting in timeouts, and the relinquish test allocated
with malloc and freed with operator delete.  This diff reduces the vector
size for testing under ASAN, and fixes the allocation mismatch.

Reviewed By: Orvid

Differential Revision: D5890969

fbshipit-source-id: 49a9498f6c0c4b3c7165906efd1262e518fea810