folly.git
8 years agoDelayedDestruction cleanup
Sophia Wang [Fri, 31 Jul 2015 16:32:55 +0000 (09:32 -0700)]
DelayedDestruction cleanup

Summary: remove unnecessary stuff

Reviewed By: @siyengar

Differential Revision: D2284095

8 years agoAdd accessor to estimate a FiberManager's run queue size
Brian Watling [Fri, 31 Jul 2015 15:52:36 +0000 (08:52 -0700)]
Add accessor to estimate a FiberManager's run queue size

Summary: Add accessor to estimate a FiberManager's run queue size

Reviewed By: @sarangbh

Differential Revision: D2293367

8 years agofolly: fix another test running under buck
Andrew Gallagher [Fri, 31 Jul 2015 10:31:44 +0000 (03:31 -0700)]
folly: fix another test running under buck

Reviewed By: @yfeldblum

Differential Revision: D2300047

8 years agofolly: fix tests running under buck (w/ clang and dynamic linking)
Andrew Gallagher [Fri, 31 Jul 2015 10:10:03 +0000 (03:10 -0700)]
folly: fix tests running under buck (w/ clang and dynamic linking)

Summary: Various fixes to get tests passing using buck's dev mode.

Reviewed By: @yfeldblum

Differential Revision: D2299981

8 years agofutures::retrying.
Yedidya Feldblum [Fri, 31 Jul 2015 03:10:19 +0000 (20:10 -0700)]
futures::retrying.

Summary: [Folly] futures::retrying.

Reviewed By: @fugalh

Differential Revision: D2201630

8 years agoFix 'missing declarations' and 'unusued parameter' warnings
Ondrej Lehecka [Fri, 31 Jul 2015 00:33:21 +0000 (17:33 -0700)]
Fix 'missing declarations' and 'unusued parameter' warnings

Summary: enum iterators operator!= didn't use the iterator parameter for comparison
because they assumed you only ever compare to end. Change the operator!= to
look at the iterator parameter to check if it was end.

Thrift generated code for reflection initializers for some types that weren't
declared before definition because they were never called outside of the file.
Marked those initializers as 'static'.

Reviewed By: @alandau

Differential Revision: D2284371

8 years agoadd EventBase-local storage abstraction
Mark McDuff [Tue, 30 Jun 2015 01:26:40 +0000 (18:26 -0700)]
add EventBase-local storage abstraction

Summary: This has come up a couple times, and the implementation is never nice.  Just like we have thread-local storage, it will be useful to also have evb-local storage.  Provides at pretty simple get/set/delete interface (see unittest).

Reviewed By: @djwatson

Differential Revision: D2203063

8 years agoFix Infinity
Nima Aghdaii [Thu, 30 Jul 2015 05:19:54 +0000 (22:19 -0700)]
Fix Infinity

Summary: folly only accepts "Infinity" while deserializing but writes "infinity" when serializing.
This means folly cannot deserialize what it serialized before.
If we agree on this, we could update ##fbcode/common## as well: https://fburl.com/136793901

Reviewed By: @marcinpe

Differential Revision: D2293627

8 years agoRemoved an unneeded typename in dynamic.h
Orvid King [Wed, 29 Jul 2015 23:57:06 +0000 (16:57 -0700)]
Removed an unneeded typename in dynamic.h

Summary: This `typename` qualifier was unneeded, and MSVC errors if it's there, so remove it.
Closes #275

Reviewed By: @yfeldblum

Differential Revision: D2284056

Pulled By: @sgolemon

8 years agoAdd MSVC support to Singleton's fatalHelper
Orvid King [Wed, 29 Jul 2015 21:51:04 +0000 (14:51 -0700)]
Add MSVC support to Singleton's fatalHelper

Summary: MSVC doesn't support constructor priorities, so use the same code as OSX.
Closes #272

Reviewed By: @yfeldblum

Differential Revision: D2283998

Pulled By: @sgolemon

8 years agoUse strerror_s on MSVC
Orvid King [Wed, 29 Jul 2015 21:51:46 +0000 (14:51 -0700)]
Use strerror_s on MSVC

Summary: Support for this under mingw was already present, this just uses that for MSVC as well.
Closes #273

Reviewed By: @yfeldblum

Differential Revision: D2284007

Pulled By: @sgolemon

8 years agoHandle MSVC in FBString.h
Orvid King [Wed, 29 Jul 2015 21:46:30 +0000 (14:46 -0700)]
Handle MSVC in FBString.h

Summary: Specifically, MSVC doesn't define `std::__ostream_insert`, so just write to the stream instead.
Closes #270

Reviewed By: @yfeldblum

Differential Revision: D2283960

Pulled By: @sgolemon

8 years agoSwitch a couple of uses of __thread to FOLLY_TLS
Orvid King [Wed, 29 Jul 2015 21:44:59 +0000 (14:44 -0700)]
Switch a couple of uses of __thread to FOLLY_TLS

Summary: Because MSVC doesn't support `__thread`, and `FOLLY_TLS` is already setup to use the MSVC syntax when needed.
Closes #269

Reviewed By: @yfeldblum

Differential Revision: D2283919

Pulled By: @sgolemon

8 years agoAdded asm_volatile_memory
Orvid King [Wed, 29 Jul 2015 18:36:32 +0000 (11:36 -0700)]
Added asm_volatile_memory

Summary: This adds `asm_volatile_memory`, which goes along with the same style used by `asm_volatile_pause`.
This also switches the two places in `RWSpinLock.h` that were using inline assembly for this to use the new functions instead.
Closes #260

Reviewed By: @yfeldblum

Differential Revision: D2283541

Pulled By: @sgolemon

8 years agoAdded FOLLY_ALIGNED(), to allow aligning on MSVC as well
Orvid King [Wed, 29 Jul 2015 18:44:32 +0000 (11:44 -0700)]
Added FOLLY_ALIGNED(), to allow aligning on MSVC as well

Summary: This adds `FOLLY_ALIGNED` to `Portability.h`, and adjusts the places that were previously using the raw aligned attribute to use this instead.

Closes #262

Reviewed By: @yfeldblum

Differential Revision: D2283639

Pulled By: @sgolemon

8 years agoFix Random-inl.h under MSVC
Orvid King [Wed, 29 Jul 2015 17:45:41 +0000 (10:45 -0700)]
Fix Random-inl.h under MSVC

Summary: With MSVC, `seedData.begin()` does not return a `void*`, so get a pointer to the data, and explicitly cast that to a `void*` instead.
Closes #251

Reviewed By: @yfeldblum

Differential Revision: D2282929

Pulled By: @sgolemon

8 years agoImplemented VersionCheck.h for MSVC
Orvid King [Wed, 29 Jul 2015 17:42:54 +0000 (10:42 -0700)]
Implemented VersionCheck.h for MSVC

Summary: This implements it via a function called on startup. The mechanism used is roughly equivelent of `__attribute__((__constructor__))` in that it doesn't have the ability to set the order of invokation.
Closes #249

Reviewed By: @yfeldblum

Differential Revision: D2282860

Pulled By: @sgolemon

8 years agoAdd space to error message
Andrey Goder [Wed, 29 Jul 2015 15:24:28 +0000 (08:24 -0700)]
Add space to error message

Summary: Before this change you would get an error like:
"Expected to get greater than or equal to1 for value 0"

Now it add in the space correctly:
"Expected to get greater than or equal to 1 for value 0"

Reviewed By: @snarkmaster

Differential Revision: D2288454

8 years agoAllow ProgramExit(0), add some comments
Tudor Bosman [Wed, 29 Jul 2015 14:48:48 +0000 (07:48 -0700)]
Allow ProgramExit(0), add some comments

Summary: exit() is evil, let's make it easier for programs that want to exit
successfully.

Reviewed By: @meyering

Differential Revision: D2290201

8 years agoAdd hasher specializations for enums, pairs and tuples
Alexander Shaposhnikov [Wed, 29 Jul 2015 03:35:46 +0000 (20:35 -0700)]
Add hasher specializations for enums, pairs and tuples

Summary: This diff adds partial specializations of folly::hasher for enum types, std::pair and std::tuple.
We also restrict the specialization for folly::Range to POD value types.

Reviewed By: @ot, @ddrcoder

Differential Revision: D2285554

8 years agoFix Build: FOLLY_SSE and preprocessor floats.
Yedidya Feldblum [Wed, 29 Jul 2015 02:55:09 +0000 (19:55 -0700)]
Fix Build: FOLLY_SSE and preprocessor floats.

Summary: [Folly] Fix Build: FOLLY_SSE and preprocessor floats.

Float values for preprocessor symbols are not a thing.

Reviewed By: @​fyan

Differential Revision: D2289436

8 years ago[folly] Enable support of applyTuple for const tuples
Alexander Shaposhnikov [Tue, 28 Jul 2015 23:35:54 +0000 (16:35 -0700)]
[folly] Enable support of applyTuple for const tuples

Summary: This diff fixes the helper template ReturnValue to enable using of applyTuple with
constant refs.

Reviewed By: @ot, @ddrcoder

Differential Revision: D2284733

8 years agoRegenerate README.md from source
Sara Golemon [Tue, 28 Jul 2015 23:41:16 +0000 (16:41 -0700)]
Regenerate README.md from source

Summary: Also fix URLs hand-modified by D2219135 which didn't quite update them enough.
Point them at the new repo.

Reviewed By: @yfeldblum

Differential Revision: D2285053

8 years agoMove various attributes before the declaration to be compatible with MSVC
Orvid King [Tue, 28 Jul 2015 22:59:31 +0000 (15:59 -0700)]
Move various attributes before the declaration to be compatible with MSVC

Summary: MSVC will just produce syntax errors if these are left where they currently are. GCC and LLVM support them in either location with the same meaning.
Closes #267

Reviewed By: @yfeldblum

Differential Revision: D2283889

Pulled By: @sgolemon

8 years agoUse fsync on MSVC, as fdatasync doesn't exist
Orvid King [Tue, 28 Jul 2015 22:15:49 +0000 (15:15 -0700)]
Use fsync on MSVC, as fdatasync doesn't exist

Summary: Closes #266

Reviewed By: @yfeldblum

Differential Revision: D2283774

Pulled By: @sgolemon

8 years agoUse intrinsics for RWSpinLock when on MSVC.
Orvid King [Tue, 28 Jul 2015 21:26:48 +0000 (14:26 -0700)]
Use intrinsics for RWSpinLock when on MSVC.

Summary: Closes #261

Reviewed By: @yfeldblum

Differential Revision: D2283554

Pulled By: @sgolemon

8 years agoAdd MSVC support for FOLLY_DEPRECATED
Orvid King [Tue, 28 Jul 2015 21:15:02 +0000 (14:15 -0700)]
Add MSVC support for FOLLY_DEPRECATED

Summary: This adds MSVC support for `FOLLY_DEPRECATED`.
Closes #257

Reviewed By: @yfeldblum

Differential Revision: D2283484

Pulled By: @sgolemon

8 years agoNormalize SSE support detection
Orvid King [Tue, 28 Jul 2015 21:23:14 +0000 (14:23 -0700)]
Normalize SSE support detection

Summary: This unifies ways of detecting SSE support into the FOLLY_SSE define which is a numeric value from 0 to 4.2 depending on detected level.
This also adds a `#define` for `__extension__` which is used in folly, but is GCC specific.
Closes #259

Reviewed By: @yfeldblum

Differential Revision: D2283522

Pulled By: @sgolemon

8 years agoAdd MSVC support for FOLLY_FINAL and FOLLY_OVERRIDE
Orvid King [Tue, 28 Jul 2015 21:18:10 +0000 (14:18 -0700)]
Add MSVC support for FOLLY_FINAL and FOLLY_OVERRIDE

Summary: This adds MSVC support for `FOLLY_FINAL` and `FOLLY_OVERRIDE`.
Closes #258

Reviewed By: @yfeldblum

Differential Revision: D2283502

Pulled By: @sgolemon

8 years agoAdd detection of MSVC RTTI
Orvid King [Tue, 28 Jul 2015 21:09:55 +0000 (14:09 -0700)]
Add detection of MSVC RTTI

Summary: This adds MSVC support to the detection of FOLLY_HAS_RTTI.
Closes #255

Reviewed By: @yfeldblum

Differential Revision: D2283036

Pulled By: @sgolemon

8 years agoAllow for mutable lambdas with Future::ensure()
Jason Rahman [Tue, 28 Jul 2015 06:48:48 +0000 (23:48 -0700)]
Allow for mutable lambdas with Future::ensure()

Summary: Update the internal lambda to mutable to support mutable lambdas as
parameters to Future::ensure()

Reviewed By: @yfeldblum

Differential Revision: D2286097

8 years agoAdd typename qualifiers to Singleton.h
Orvid King [Mon, 27 Jul 2015 22:42:23 +0000 (15:42 -0700)]
Add typename qualifiers to Singleton.h

Summary: MSVC complains if these are not there.
Closes #248

Reviewed By: @yfeldblum

Differential Revision: D2282845

Pulled By: @sgolemon

8 years agoSupport GroupVarint.h under MSVC
Orvid King [Mon, 27 Jul 2015 23:06:57 +0000 (16:06 -0700)]
Support GroupVarint.h under MSVC

Summary: MSVC supports the intrinsics used by it without any issue other changes, so just make sure the error doesn't trigger on MSVC.
Closes #252

Reviewed By: @yfeldblum

Differential Revision: D2282942

Pulled By: @sgolemon

8 years agoAdd support for MSVC in asm_pause in Portability.h
Orvid King [Mon, 27 Jul 2015 23:16:56 +0000 (16:16 -0700)]
Add support for MSVC in asm_pause in Portability.h

Summary: This implements support for `asm_volatile_pause` and `asm_pause`, as defined in `Portability.h`, for MSVC.
This is needed because MSVC x64 doesn't support inline assembly.
Closes #254

Reviewed By: @yfeldblum

Differential Revision: D2283006

Pulled By: @sgolemon

8 years agoAdjust a literal in AtomicHashMap.h to be correctly sized
Orvid King [Mon, 27 Jul 2015 22:09:31 +0000 (15:09 -0700)]
Adjust a literal in AtomicHashMap.h to be correctly sized

Summary: Noticed because of a warning emitted by MSVC, this fixees the literal for `kLockedPtr_` to correctly be 64-bits under MSVC, rather than 32-bit.
Closes #245

Reviewed By: @yfeldblum

Differential Revision: D2282806

Pulled By: @sgolemon

8 years agoFix the size of the enum in FBString.h under MSVC
Orvid King [Mon, 27 Jul 2015 22:17:32 +0000 (15:17 -0700)]
Fix the size of the enum in FBString.h under MSVC

Summary: MSVC defaults enum sizes to int, so explicitly use `size_t` as the base to have it correctly sized.
Closes #246

Reviewed By: @yfeldblum

Differential Revision: D2282816

Pulled By: @sgolemon

8 years agofix clang ASAN error in DelayedDestructionBaseTest
Sophia Wang [Mon, 27 Jul 2015 18:38:54 +0000 (11:38 -0700)]
fix clang ASAN error in DelayedDestructionBaseTest

Summary: fix a use after free bug. this line is stupid!

Reviewed By: @siyengar

Differential Revision: D2283041

8 years agodelete folly/wangle
James Sedgwick [Mon, 27 Jul 2015 18:11:00 +0000 (11:11 -0700)]
delete folly/wangle

Summary: she's gooooooone, oh why, oh why, i better learn how to face it...

https://www.youtube.com/watch?v=bnVXIUyshng

Reviewed By: @djwatson

Differential Revision: D2219135

8 years agoBump version to 52:0 v0.52.0
Sara Golemon [Mon, 27 Jul 2015 16:46:56 +0000 (09:46 -0700)]
Bump version to 52:0

8 years agoMake ProcessReturnCode default-constructible
Alexey Spiridonov [Mon, 27 Jul 2015 02:36:57 +0000 (19:36 -0700)]
Make ProcessReturnCode default-constructible

Summary: We have this previously-unused "NOT STARTED" status, which I recently appropriated to denote moved-out `ProcessReturnCode`s.

It's natural to also use this for default-constructed `ProcessReturnCodes`. Lacking a default constructor leads to a bunch of unnecessarily annoying use of `folly::Optional` in my upcoming diff, so I wanted to get rid of that, see e.g.

differential/diff/7657906/

Reviewed By: @tudor

Differential Revision: D2097368

8 years agoImprove waitpid error handling
Alexey Spiridonov [Mon, 27 Jul 2015 02:32:03 +0000 (19:32 -0700)]
Improve waitpid error handling

Summary: Using `checkUnixError` after `waitpid()` is confusing and useless, because the only two possible errors are `ECHILD` (some other part of the program waited for this process!?) and `EINVAL` (invalid options, which are hardcoded in both `Subprocess::wait()` and `poll()`). Neither of these are recoverable. Moreover, even if the caller catches the exception, `~Subprocess` is still booby-trapped to `abort()` since its status remains `RUNNING`.

In short, just abort.

Reviewed By: @yfeldblum

Differential Revision: D2079415

8 years agoFix some warnings in folly
mwilliams [Fri, 24 Jul 2015 18:44:20 +0000 (11:44 -0700)]
Fix some warnings in folly

Summary: Remove a couple of unused variables, and move one
that was only used inside an ifdef

Reviewed By: @yfeldblum

Differential Revision: D2279989

8 years agoadded a missing hook to IndexedMemPool's testing harness
Nathan Bronson [Fri, 24 Jul 2015 21:57:33 +0000 (14:57 -0700)]
added a missing hook to IndexedMemPool's testing harness

Summary: IndexedMemPool had one bare usage of std::atomic, rather than
the templated type Atom.  This doesn't affect any non-testing template
instantiations, because those two are usually synonyms, but it could cause
spurious failures of DeterministicSchedule tests.  Found via inspection,
not via failed tests.

Reviewed By: @yfeldblum

Differential Revision: D2277424

8 years agoPrint type of singleton that is requested after destruction
Misha Shneerson [Fri, 24 Jul 2015 18:57:21 +0000 (11:57 -0700)]
Print type of singleton that is requested after destruction

Summary: As titled
Trying to troubleshoot shutdown problems in HHVM and I see:
  EventBase::runAfterDelay() callback threw St13runtime_error exception: Raw pointer to a singleton requested after its destruction.
Would be much easier to troubleshoot if I know what is it being requested.

Reviewed By: @chipturner

Differential Revision: D2274497

8 years agoimprovements to DeterministicSchedule
Nathan Bronson [Fri, 24 Jul 2015 15:20:45 +0000 (08:20 -0700)]
improvements to DeterministicSchedule

Summary: This diff isolates the CacheLocality back end for DeterministicSchedule
from one invocation to the next (the last one was deterministic
across the entire program but not per-DeterministicSchedule instance),
and makes it easy to do extensive tracing of memory accesses during
a deterministic test.  These changes were made while tracking down a
bug, but don't fix any bugs on their own (and in fact don't affect any
production code at all).

Reviewed By: @yfeldblum

Differential Revision: D1842390

8 years agoFix oss build
Andre Pinto [Fri, 24 Jul 2015 00:15:26 +0000 (17:15 -0700)]
Fix oss build

Summary: Add program_options to fix oss build

Reviewed By: @tudor

Differential Revision: D2274863

8 years agoDelete functions that return a pointer when the dynamic object is a rvalue.
Nick Terrell [Fri, 24 Jul 2015 00:46:30 +0000 (17:46 -0700)]
Delete functions that return a pointer when the dynamic object is a rvalue.

Summary: This diff is not yet complete, I want to see the contbuild before I change the
functions that return references to member functions.

It is unsafe to return a pointer when the dynamic object is a rvalue, because if
the pointer escapes the expression after the object is destroyed, we go into
segfault / undefined behavior land.
I have deleted these overloads.  The amount of valid code that is now disallowed
is minimal.  The only valid case I can think of is returing a pointer and
passing it to a function in the same expression that does not save the pointer.
However, this case is also dangerous, because if the function you pass it to
decides to save the pointer for later, we are in trouble, e.g.

  save_ptr(dynamic("str").c_str())

Since there are simple workarounds (naming the object), I think that is a small
price to pay for the greatly increased safety.

The next step is to overload all members that return a reference to a member
to move the member out if the dynamic is a rvalue:

  const dynamic& at(dynamic const&) const&;
        dynamic& at(dynamic const&)      &;
        dynamic  at(dynamic const&)      &&;  // Move out

I also need to go over the code more carefully to make sure that nothing went
wrong.

Reviewed By: @marcinpe

Differential Revision: D2257914

8 years agoHelper for writing nested command line apps
Tudor Bosman [Thu, 23 Jul 2015 14:30:52 +0000 (07:30 -0700)]
Helper for writing nested command line apps

Summary: Many command line apps are of the form
"program [--global_options] command [--command_options] args..."

Make writing such things less painful.

+jdelong because smcc

Reviewed By: @meyering

Differential Revision: D2217248

8 years agoMake gflags and boost::program_options play nice with each other
Tudor Bosman [Thu, 23 Jul 2015 14:30:41 +0000 (07:30 -0700)]
Make gflags and boost::program_options play nice with each other

Summary: GFlags is useful for global program options. boost::program_options makes it
easier to write command-line utilities. They don't, unfortunately, play
very nicely with each other.

Add a addGFlags() function to convert all GFlags to boost::program_options
options; you can then use boost::program_options::parse_command_line() to
parse all arguments, GFlags or not.

Also add a helper function to make parsing nested command lines easier.

Reviewed By: @fugalh

Differential Revision: D2215285

8 years agofix racy assert in SharedMutex
Nathan Bronson [Wed, 22 Jul 2015 22:14:58 +0000 (15:14 -0700)]
fix racy assert in SharedMutex

Summary: SharedMutex purposely allows the inline reader count to underflow in some
situations while preserving proper locking behavior (the inline reader
count is only trusted if all deferred locks have been applied), but there
was an additional way that this could occur that wasn't documented or
allowed by the asserts.  The effect was a false positive assert in rare
conditions or the possibility of losing track of a deferred lock slot.
This diff fixes both the over-aggressive assert and the potential loss
of the shared slot.  If the assert didn't fire for you then this diff
won't change the correctness of your program.

Reviewed By: @yfeldblum

Differential Revision: D2269018

8 years agoAdd executable_path() and convert SubprocessTest to use it
Tudor Bosman [Wed, 22 Jul 2015 19:43:36 +0000 (12:43 -0700)]
Add executable_path() and convert SubprocessTest to use it

Summary: Because I didn't want to write it again.

Reviewed By: @yfeldblum

Differential Revision: D2217246

8 years agomaking thrift and folly header files compile clean with -Wunused-parameter
Ondrej Lehecka [Wed, 22 Jul 2015 18:57:18 +0000 (11:57 -0700)]
making thrift and folly header files compile clean with -Wunused-parameter

Summary: fixing compiler errors when compiling with Wunused-parameter

Reviewed By: @yfeldblum

Differential Revision: D2267014

8 years ago(Wangle) window, fix test
Hannes Roth [Wed, 22 Jul 2015 16:35:19 +0000 (09:35 -0700)]
(Wangle) window, fix test

Summary: Thanks @​peijinz for finding this.

Reviewed By: @​peijinz

Differential Revision: D2268532

8 years agoAdd bounds check in get_ptr.
Nick Terrell [Tue, 21 Jul 2015 18:34:55 +0000 (11:34 -0700)]
Add bounds check in get_ptr.

Summary: `get_ptr()` checks if the index is past the end of the array, but it
doesn't check if it is less than 0, while `at()` does.

Reviewed By: @yfeldblum

Differential Revision: D2258548

8 years ago(Wangle) within should raise TimedOut()
Hannes Roth [Tue, 21 Jul 2015 02:42:45 +0000 (19:42 -0700)]
(Wangle) within should raise TimedOut()

Summary: A timeout now raises `TimedOut()` on the current Future.

Reviewed By: @fugalh

Differential Revision: D2261559

8 years agoFix "reference to 'thread' is ambiguous"
Hans Fugal [Tue, 21 Jul 2015 00:46:42 +0000 (17:46 -0700)]
Fix "reference to 'thread' is ambiguous"

Summary: This fixes github issue https://github.com/facebook/folly/issues/243

I don't understand why this is broken on osx, but the solution is to just `#include <thread>` in the header instead of trying to forward declare `std::thread`.

Reviewed By: @yfeldblum

Differential Revision: D2255026

8 years agofixing compiler errors when compiling with Wunused-parameter
Ondrej Lehecka [Mon, 20 Jul 2015 23:37:52 +0000 (16:37 -0700)]
fixing compiler errors when compiling with Wunused-parameter

Summary: fixing C++ compiler warnings for the -Wunused-parameter warning switch on.
This is fixing only the header files, not the library cpp files.

Reviewed By: @yfeldblum

Differential Revision: D2259957

8 years agoFix logspew in DelayedDestruction
Viswanath Sivakumar [Mon, 20 Jul 2015 23:07:03 +0000 (16:07 -0700)]
Fix logspew in DelayedDestruction

Summary: This is causing a log of spew in proxygen logs

Reviewed By: @afrind

Differential Revision: D2262006

8 years agoRemove EmptySequence exception in favor of optional returns
Tom Jackson [Mon, 20 Jul 2015 21:05:59 +0000 (14:05 -0700)]
Remove EmptySequence exception in favor of optional returns

Summary: Forces consumers to handle the empty sequence case instead of cumbersome exceptions.

Reviewed By: @​jrichey, @yfeldblum

Differential Revision: D2219505

8 years agoFix a namespace nit in folly/futures/Future.cpp.
Yedidya Feldblum [Mon, 20 Jul 2015 19:26:32 +0000 (12:26 -0700)]
Fix a namespace nit in folly/futures/Future.cpp.

Summary: [Folly] Fix a namespace nit in folly/futures/Future.cpp.

As soon as someone introduces a namespace `folly::futures::detail` this will blow up. Fix it so it won't blow up when that happens.

Reviewed By: @​hannesr

Differential Revision: D2258799

8 years agoBump version to 51:0 v0.51.0
Sara Golemon [Mon, 20 Jul 2015 19:26:38 +0000 (12:26 -0700)]
Bump version to 51:0

8 years agoAllow access to a FiberManager's currently running fiber
Brian Watling [Mon, 20 Jul 2015 18:46:02 +0000 (11:46 -0700)]
Allow access to a FiberManager's currently running fiber

Summary: Allow access to a FiberManager's currently running fiber

Reviewed By: @alikhtarov, @andriigrynenko

Differential Revision: D2257201

8 years agoOverload Optional::value() on object reference type.
Nick Terrell [Mon, 20 Jul 2015 16:03:11 +0000 (09:03 -0700)]
Overload Optional::value() on object reference type.

Summary: `folly::Optional` returns the stored value by reference when the object
is an rvalue.  This causes three issues:

  * If the user calls `value()` on an rvalue `Optional`, and assigns the result
    to a new variable, the copy constructor gets called, instead of the move
    constructor.  This causes the added test `value_move` to not compile.
  * If the user calls `value()` on an rvalue `Optional`, and assigns the result
    to a const lvalue reference, they might expect the lifetime to be extended
    when it isn't. See the added test `value_life_extention`.
  * Assigning the results of `value()` on an rvalue `Optional` to a mutable
    lvalue reference compiled in the old code, when it shouldn't, because that
    is always a dangling reference as far as I can tell.

I'm not sure how strict `folly` is with compatibility, but I believe the
breakage would be minimal, and any code that gets broken probably deserves it.

I'm not exactly sure who I should add as a reviewer, so hopefully herald has got
my back.

Reviewed By: @yfeldblum

Differential Revision: D2249548

8 years agofolly Singleton: clear some state if creator function fails
Steve O'Brien [Sun, 19 Jul 2015 16:22:34 +0000 (09:22 -0700)]
folly Singleton: clear some state if creator function fails

Summary: The creator thread ID is saved to indicate the singleton is already being built (to help detect dependency cycles).  However if the creation function throws an error, that thread ID persists, and then if the same thread tries again to build the singleton it will be falsely detected as a dependency cycle.  This clears that state in the case of failure.

Reviewed By: @chipturner

Differential Revision: D2256441

8 years agoRevert: (Wangle) within should raise TimedOut()
Hannes Roth [Sat, 18 Jul 2015 18:58:52 +0000 (11:58 -0700)]
Revert: (Wangle) within should raise TimedOut()

Summary: This reverts commit 956351018a495af89575526536af7e7c0bb285aa.

Reviewed By: @​labrams

Differential Revision: D2258219

8 years agofolly HHWheelTimer: fix loop variable
Steve O'Brien [Fri, 17 Jul 2015 19:41:02 +0000 (12:41 -0700)]
folly HHWheelTimer: fix loop variable

Summary: In nested loop, loop condition is incorrect.  Fixed var (should be `ii` not `i`)

Reviewed By: @pgriess

Differential Revision: D2255702

8 years agoMaking Optional throw exceptions instead of assert
Tom Jackson [Thu, 16 Jul 2015 20:59:07 +0000 (13:59 -0700)]
Making Optional throw exceptions instead of assert

Summary: I'm upgrading assertions to throws, since these are fatal in all circumstances. If something is explicitly `Optional`, it makes sense to fail loudly if it is misused in this manner.

Reviewed By: @yfeldblum

Differential Revision: D2247612

8 years agoadd SocketPair.h/.cpp to Makefile
James Sedgwick [Thu, 16 Jul 2015 17:16:45 +0000 (10:16 -0700)]
add SocketPair.h/.cpp to Makefile

Summary: to unbreak OSS wangle tests build

Reviewed By: @bugok

Differential Revision: D2240264

8 years agofolly::Future-istic barrier
Tudor Bosman [Thu, 16 Jul 2015 16:50:03 +0000 (09:50 -0700)]
folly::Future-istic barrier

Summary: What it says on the tin.

Reviewed By: @fugalh

Differential Revision: D2230390

8 years agoAdd an option to disable guard pages for fiber stacks
Pavlo Kushnir [Thu, 16 Jul 2015 04:06:29 +0000 (21:06 -0700)]
Add an option to disable guard pages for fiber stacks

Summary: guard pages may make debugging more painful. For example, in some cases they increased "perf" initialization time.

Reviewed By: @alikhtarov

Differential Revision: D2247188

8 years ago(Wangle) within should raise TimedOut()
Hannes Roth [Wed, 15 Jul 2015 23:39:48 +0000 (16:39 -0700)]
(Wangle) within should raise TimedOut()

Summary: I figured it out. This works. The two extra futures are a small overhead
(just two pointers). The `Core`s are allocated anyway, so this is pretty
much optimal.

A timeout now raises on the current Future, and a fulfilled promise
cancels the timeout Future.

Reviewed By: @yfeldblum

Differential Revision: D2232463

8 years agoOnly try to use F_SETPIPE_SZ if it's available
Sara Golemon [Wed, 15 Jul 2015 16:44:05 +0000 (09:44 -0700)]
Only try to use F_SETPIPE_SZ if it's available

Summary: As the comment says, we can ignore errors in setting the size.
So it stands to reason we can ignore setting the size as well.

Reviewed By: @yfeldblum

Differential Revision: D2242882

8 years agoMake DestructorGuard inherit from a base
Sophia Wang [Wed, 15 Jul 2015 00:18:18 +0000 (17:18 -0700)]
Make DestructorGuard inherit from a base

Summary: There are more use cases that the Destruction/Guard pattern can be
used than current DelayedDestruction provides. This diff makes the pattern more
general (remove self destruct) and lets DelayedDestruction derive from that.
The functionalities of DelayedDestruction is kept unchanged.

I leave destroy(), Destructor class, and destroyPending_ in DelayedDestruction
since they are not required by our CallbackGuard in proxygen.

I add a shouldDestruct() function to allow customized conditions on when to
call destructor.

I haven't made destroyNow() a std::function since I only need it to be set at
instatiation time. If there is any other use case that needs destroyNow() to be
a std::function, I can do that as well.

Reviewed By: @afrind

Differential Revision: D2202575

8 years agoActually denote when we have infinite generators
Joe Richey [Tue, 14 Jul 2015 20:50:31 +0000 (13:50 -0700)]
Actually denote when we have infinite generators

Summary: Before we didn't do anything at all with the ::infinite value for our
generators, now all the sources operators and sinks are properly notated. The
one signifcant change regarding what is allowed concerns 'cycle' which now (when
called with no arguments) always produces an infinite generator. This is fine
for all but the weirdest of generators fed into cycle.

Reviewed By: @ddrcoder

Differential Revision: D2240328

8 years agoChanging behavior of 'any' and 'all' sinks, adding in 'isEmpty' and 'notEmpty' sinks
Joe Richey [Tue, 14 Jul 2015 20:50:24 +0000 (13:50 -0700)]
Changing behavior of 'any' and 'all' sinks, adding in 'isEmpty' and 'notEmpty' sinks

Summary: When adding in the 'filter()' default behavior, I considered adding in similar
behavior for 'any' and 'all'. However, we had 'any' with no funciton call
basically check if anything was present, not testing a predicate. This can
create a confusing senario, so I removed this behavior from 'any' and added in
the 'isEmpty' and 'notEmpty' sinks. Now the calls 'any()' and 'all()' (called
with parens, so old uses won't compile) check for truthy values simlar to
'filter()'.

I also added some unit tests and changed 'static const' objects to 'constexpr'.

Reviewed By: @ddrcoder

Differential Revision: D2234637

8 years agoRequestContext support
Andrii Grynenko [Tue, 14 Jul 2015 17:29:36 +0000 (10:29 -0700)]
RequestContext support

Summary: Integrating RequestContext into fibers library. RequestContext is saved for every task, when that task is created. If RequestContext is overriden when a task is being run (within fiber, in runInMainContext, within function passed to await call) the new context will continue to be used for the task.

Reviewed By: @alikhtarov

Differential Revision: D2240152

8 years agofolly: AsyncIOOp: improve logging message: add strerror
Lucian Grijincu [Tue, 14 Jul 2015 17:31:26 +0000 (10:31 -0700)]
folly: AsyncIOOp: improve logging message: add strerror

Reviewed By: @philippv

Differential Revision: D2240628

8 years agoFix Build: folly/io/async/test/ScopedEventBasedThreadTest.cpp
Yedidya Feldblum [Tue, 14 Jul 2015 00:18:23 +0000 (17:18 -0700)]
Fix Build: folly/io/async/test/ScopedEventBasedThreadTest.cpp

Summary: [Folly] Fix Build: folly/io/async/test/ScopedEventBasedThreadTest.cpp

Failure with latest clang:

    folly/io/async/test/ScopedEventBaseThreadTest.cpp:72:8: error: explicitly moving variable of type 'folly::ScopedEventBaseThread' to itself [-Werror,-Wself-move]
      sebt = std::move(sebt);

Reviewed By: @markisaa

Differential Revision: D2238762

8 years agoFile ctor should take StringPiece.
Yedidya Feldblum [Mon, 13 Jul 2015 20:25:25 +0000 (13:25 -0700)]
File ctor should take StringPiece.

Summary: [Folly] File ctor should take StringPiece.

This way we can use it with `std::string` and `folly::fbstring` a touch more easily.

Reviewed By: @luciang

Differential Revision: D2235870

8 years agoBump version to 50:0 v0.50.0
Sara Golemon [Mon, 13 Jul 2015 18:17:36 +0000 (11:17 -0700)]
Bump version to 50:0

8 years agoFix examples in folly::Singleton code
Andrii Grynenko [Mon, 13 Jul 2015 17:39:32 +0000 (10:39 -0700)]
Fix examples in folly::Singleton code

Reviewed By: @chipturner

Differential Revision: D2235232

8 years agosplit SmallLocks.h to get a larger portion of folly compiled on 32bit platforms
Kjell Schubert [Sat, 11 Jul 2015 16:12:08 +0000 (09:12 -0700)]
split SmallLocks.h to get a larger portion of folly compiled on 32bit platforms

Summary: This is only a simple #include file split, no functional change was made. SmallLocks.h provides 2 classes: MicroSpinLock and PicoSpinLock, with the latter not being available on 32bit platforms. There are several classes in folly that included SmallLocks.h but only needed MicroSpinLock, these also refused to compile on 32bit, e.g. folly/futures/Future.h. Now these compile fine.

Reviewed By: @yfeldblum

Differential Revision: D2234263

8 years agoAn has_member_type macro.
Yedidya Feldblum [Sat, 11 Jul 2015 04:24:17 +0000 (21:24 -0700)]
An has_member_type macro.

Summary: [Folly] An has_member_type macro.

Reviewed By: @juchem

Differential Revision: D2229775

8 years agoAdded default value for filter's predicate argument
Joe Richey [Thu, 9 Jul 2015 21:48:17 +0000 (14:48 -0700)]
Added default value for filter's predicate argument

Summary: After discussion with Tom about frozen files, we noticed that the use
case of filtering out somthing that looks like false (0, nullptr, folly::none)
is unnecessarily tedious. So folly::gen::filter now filters by the value of
the item by default.

Reviewed By: @ddrcoder

Differential Revision: D2220582

8 years agoAdd mocks for isBufferMovable
Subodh Iyengar [Thu, 9 Jul 2015 05:44:59 +0000 (22:44 -0700)]
Add mocks for isBufferMovable

Summary: Add mocks for the new isBufferMovable methods.

Reviewed By: @yfeldblum

Differential Revision: D2222642

8 years agoThreadedExecutor.
Yedidya Feldblum [Thu, 9 Jul 2015 00:54:16 +0000 (17:54 -0700)]
ThreadedExecutor.

Summary: [Folly] ThreadedExecutor.

It's an Executor that runs functions each in its own thread.

Kind of simple. Suitable for a few types of strange cases.

Reviewed By: @​hannesr

Differential Revision: D2226211

8 years agoAdd isManaged / makeManaged
Tudor Bosman [Wed, 8 Jul 2015 15:39:55 +0000 (08:39 -0700)]
Add isManaged / makeManaged

Summary: Add a way to tell whether an IOBuf (either indvidually or the whole chain)
refers to memory that's outside of IOBuf's control (via WRAP_BUFFER). That is,
can you assume that clone() will extend the lifetime of the memory? Is it safe
to use clone() instead of copying the data (and avoid a copy)?

Reviewed By: @simpkins

Differential Revision: D2191883

8 years agofolly/singleton: fatal in unrecoverable error cases
Steve O'Brien [Tue, 7 Jul 2015 23:10:07 +0000 (16:10 -0700)]
folly/singleton: fatal in unrecoverable error cases

Summary: Early in the startup process there may not be a default signal handler installed, and stack traces are not available; also during the startup process is when init-order fiascos occur.  Dump a stacktrace and fatal when an unregistered singleton is used.

Also fatals -- with glog `LOG(FATAL)`, which triggers an ABRT signal -- on other illegal and unrecoverable usage like double-registration or circular dependency.

Reviewed By: @andriigrynenko

Differential Revision: D2200408

8 years agohigh init priority for FiberManagerMap data
Mark McDuff [Tue, 7 Jul 2015 22:20:59 +0000 (15:20 -0700)]
high init priority for FiberManagerMap data

Summary: Ran into a bug in D2158570 where we dtor'ing these data structures before the event bases destructed, so the assert on line 47 (of the old code) failed.

Reviewed By: @andriigrynenko

Differential Revision: D2198318

8 years agoBump version to 49:1 v0.49.1
Sara Golemon [Tue, 7 Jul 2015 20:45:17 +0000 (13:45 -0700)]
Bump version to 49:1

8 years agoInstall Ubuntu 12.04 LTS dependencies for Travis CI
Alexey Spiridonov [Tue, 7 Jul 2015 20:36:16 +0000 (13:36 -0700)]
Install Ubuntu 12.04 LTS dependencies for Travis CI

Summary: This is the first of a series of diffs to get folly, fbthrift, and bistro to run on Ubuntu 12.04 LTS, which is what powers Travis CI.

It's important for folly to be easily usable with Travis CI, since everything C++ depends on it, and we really want all FB open-source projects to be monitored via continuous integration to avoid breaking their OSS builds.

Thanks to @int's work on `mcrouter`, this was considerably easier than it would have been otherwise.

This puts us a hop and a skip away from actually running folly's `make && make check && make install` on Travis CI. Do y'all think this is useful?

Reviewed By: @yfeldblum

Differential Revision: D2217441

8 years agoBump version to 49:0 v0.49.0
Sara Golemon [Tue, 7 Jul 2015 17:26:57 +0000 (10:26 -0700)]
Bump version to 49:0

8 years agofolly/wangle -> wangle cutover
James Sedgwick [Mon, 6 Jul 2015 18:35:30 +0000 (11:35 -0700)]
folly/wangle -> wangle cutover

Summary: Another stab at D2111063 now that we have the go ahead to actually open up the wangle github repo

Reviewed By: @djwatson, @mdordal

Differential Revision: D2178291

8 years agocleanup CompressedList / MutableCompressedList interfaces
Philip Pronin [Mon, 6 Jul 2015 00:29:39 +0000 (17:29 -0700)]
cleanup CompressedList / MutableCompressedList interfaces

Summary: Drop those `const_cast<>` hacks.

Reviewed By: @ot

Differential Revision: D2217629

8 years agofolly/futures Update README.md
Hans Fugal [Thu, 2 Jul 2015 23:03:25 +0000 (16:03 -0700)]
folly/futures Update README.md

Summary: This is a documentation dump, with updates from the past couple weeks. Most notably, the new information about `Future<Unit>` replacing `Future<void>`.

Reviewed By: @​hannesr

Differential Revision: D2211135

8 years agoLift thrift/lib/cpp/test/TNotificationQueueTest.
Yedidya Feldblum [Thu, 2 Jul 2015 20:58:58 +0000 (13:58 -0700)]
Lift thrift/lib/cpp/test/TNotificationQueueTest.

Summary: [Folly] Lift thrift/lib/cpp/test/TNotificationQueueTest.

`NotificationQueue` is already moved into folly; move its accompanying test suite as well.

Reviewed By: @simpkins

Differential Revision: D2207104

8 years agoFix typo - ac defined are prefixed with FOLLY_
Sara Golemon [Thu, 2 Jul 2015 21:02:18 +0000 (14:02 -0700)]
Fix typo - ac defined are prefixed with FOLLY_

Summary: Got this ifdef wrong in my last change here.

Reviewed By: @paulbiss

Differential Revision: D2213708

8 years agonice error message if you try to Future<void>
Hans Fugal [Thu, 2 Jul 2015 18:43:42 +0000 (11:43 -0700)]
nice error message if you try to Future<void>

Summary: If you try to make a future or promise of `void`, you will get this nice error message telling you to use `Unit` instead.

Reviewed By: @djwatson

Differential Revision: D2211239

8 years agoAdd an exception for building on OSX.
Michael Lee [Thu, 2 Jul 2015 14:49:15 +0000 (07:49 -0700)]
Add an exception for building on OSX.

Summary: The Homebrew setup fails to compile on OSX.

Reviewed By: @paulbiss

Differential Revision: D2212084

8 years agofolly::Unit::Drop.
Yedidya Feldblum [Thu, 2 Jul 2015 01:39:41 +0000 (18:39 -0700)]
folly::Unit::Drop.

Summary: [Folly] folly::Unit::Drop.

Antisymmetric to folly::Unit::Lift.

Reviewed By: @fugalh

Differential Revision: D2211725