folly.git
3 years agoFix integer sign consistency. v2018.01.22.00
Maged Michael [Sat, 20 Jan 2018 05:46:22 +0000 (21:46 -0800)]
Fix integer sign consistency.

Summary: Keeping all variables that interact with hazptr_domain::rcount_ signed int to avoid conversion errors.

Reviewed By: yfeldblum

Differential Revision: D6754593

fbshipit-source-id: e283f127a112a529a0e98eb82b6061b44aa9d2ca

3 years agoRemove unsafe tag and add presorted tag
Yedidya Feldblum [Sat, 20 Jan 2018 00:21:57 +0000 (16:21 -0800)]
Remove unsafe tag and add presorted tag

Summary:
[Folly] Remove `unsafe` tag and add `presorted` tag.

There are varieties of unsafety, so let us be more explicit about which variety of unsafety is invoked in each case.

Differential Revision: D6758520

fbshipit-source-id: d198a3c7601971460f91acc7787c9da02ae283c0

3 years agoremove unused include in Demangle.cpp
Adam Simpkins [Fri, 19 Jan 2018 22:57:43 +0000 (14:57 -0800)]
remove unused include in Demangle.cpp

Summary: folly/memory/Malloc.h was included but not needed.

Reviewed By: yfeldblum

Differential Revision: D6757598

fbshipit-source-id: 241b939724b21a94739e14335ddfaadfcd00dda3

3 years agoremove closure from assert
Nathan Bronson [Fri, 19 Jan 2018 20:41:05 +0000 (12:41 -0800)]
remove closure from assert

Summary:
Somebody reported compilation issues with the closure in post()'s
assert, resulting in "error: lambda-expression in unevaluated context".
While I haven't been able to reproduce the problem locally, it is easy
enough to work around in this case.

Reviewed By: djwatson, mcallahan

Differential Revision: D6759739

fbshipit-source-id: 9f8082a1e20cd9ddf626cb176542e4e861a7e702

3 years agoUse MemoryIdler in SaturatingSemaphore
Yedidya Feldblum [Fri, 19 Jan 2018 19:47:48 +0000 (11:47 -0800)]
Use MemoryIdler in SaturatingSemaphore

Summary:
[Folly] Use `MemoryIdler` in `SaturatingSemaphore`.

As is used in `Baton`.

And merge the two invocations of `futexWait` and `futexWaitUntil` - `futexWaitUntil` also tests for the max-deadline internally.

Reviewed By: djwatson

Differential Revision: D6720045

fbshipit-source-id: a48187a6c866dbf99bb5c7283e0288b939bef2e5

3 years agoHandle max deadlines in Futex
Yedidya Feldblum [Fri, 19 Jan 2018 19:47:46 +0000 (11:47 -0800)]
Handle max deadlines in Futex

Summary:
[Folly] Handle max deadlines in `Futex`.

Some of the synchronization code internally treats deadlines which are equivalent to `time_point::max()` for the same clock as a sentinel value indicating a deadline at infinity, or equivalently the lack of a deadline.

Care must be taken when converting between clocks to translate a deadline at infinity for one clock to the deadline at infinity for the other clock.

Reviewed By: nbronson

Differential Revision: D6720021

fbshipit-source-id: cfc230dd2d8db55297385a4afcb6d87ae4221840

3 years agoAdd TimedDrivableExecutor to folly.
Lee Howes [Fri, 19 Jan 2018 17:18:41 +0000 (09:18 -0800)]
Add TimedDrivableExecutor to folly.

Summary: Adds a TimedDrivableExecutor implementation of DrivableExecutor that adds a driveUntil method. driveUntil is as drive, except that it takes a timepoint and will stop driving after that time to allow callers to time out more easily.

Reviewed By: yfeldblum

Differential Revision: D6658320

fbshipit-source-id: a75145748e78497ce107ae152f25729547883835

3 years agoFix copyright line in folly/synchronization/test/ParkingLotBenchmark.cpp
Yedidya Feldblum [Fri, 19 Jan 2018 08:43:00 +0000 (00:43 -0800)]
Fix copyright line in folly/synchronization/test/ParkingLotBenchmark.cpp

Summary: [Folly] Fix copyright line in `folly/synchronization/test/ParkingLotBenchmark.cpp`.

Reviewed By: andrewjcg

Differential Revision: D6758502

fbshipit-source-id: cae2a79940c7c9cc58c29977141199ab1e902081

3 years agocmake: remove the check preventing cmake on non-Windows platforms
Adam Simpkins [Fri, 19 Jan 2018 04:43:24 +0000 (20:43 -0800)]
cmake: remove the check preventing cmake on non-Windows platforms

Summary:
I believe the CMake build scripts have a similar level of functionality to the
autoconf-based build scripts even on Linux these days.  This lets users use
CMake on Linux and Mac, rather than directing them to autoconf instead.

Reviewed By: meyering

Differential Revision: D6745366

fbshipit-source-id: 0361eecead55ee06269192eee8d2e7286eb182b8

3 years agocmake: mark the compression tests as slow
Adam Simpkins [Fri, 19 Jan 2018 04:43:21 +0000 (20:43 -0800)]
cmake: mark the compression tests as slow

Summary:
The compression test code has a large number of parameterized tests that run
with a large number of parameter combinations.  These tests take many minutes
to run.

Reviewed By: meyering

Differential Revision: D6745364

fbshipit-source-id: dac5d5eb4a786da7be453742fac5f92a9740e468

3 years agocmake: enable running the tests
Adam Simpkins [Fri, 19 Jan 2018 04:43:19 +0000 (20:43 -0800)]
cmake: enable running the tests

Summary:
CMake 3.9+ includes built-in support for gtest.  This updates the CMake build
scripts to make use of this if the GoogleTest module is available.

Reviewed By: meyering

Differential Revision: D6745369

fbshipit-source-id: 1ef978874b9a0ef2cc5f48ab1c7a0b55d0f1155e

3 years agocmake: build as many source files as possible
Adam Simpkins [Fri, 19 Jan 2018 04:43:18 +0000 (20:43 -0800)]
cmake: build as many source files as possible

Summary:
The CMakeLists.txt file finds the sources and headers for the main folly
library by finding all *.cpp and *.h files, and then excluding specific ones.

The CMakeLists.txt file was originally written for Windows builds, and it was
hard-coded to exclude a number of files that do not build on Windows.   This
updates the file to properly check for the dependencies, and build these files
if their required third-party dependencies are available.

Reviewed By: meyering

Differential Revision: D6745368

fbshipit-source-id: 3ee04d54147a68c482aab50d30bc9fe2a4134eef

3 years agocmake: add more checks for folly-config.h generation
Adam Simpkins [Fri, 19 Jan 2018 04:43:15 +0000 (20:43 -0800)]
cmake: add more checks for folly-config.h generation

Summary:
Update the CMake build files to perform additional checks to set configuration
macros in folly-config.h

I believe this should largely bring the CMake build on-par with (or even better
than) the autoconf build scripts.  I believe that the CMake build scripts now
perform all of the checks necessary to set macros in folly-config.h correctly.

The autoconf-based configure script also appears to have a number of bugs:
in several places it accidentally uses different macro names than the ones
checked in the source code.  Some of it's checks are also broken, and fail to
detect features correctly due to compilation errors in the check.

Reviewed By: yfeldblum

Differential Revision: D6735699

fbshipit-source-id: 5ce48f1deddd63c9d52fcccd5d5ccf6ca35e9a0d

3 years agodemangle: remove an old TODO comment
Adam Simpkins [Fri, 19 Jan 2018 04:42:48 +0000 (20:42 -0800)]
demangle: remove an old TODO comment

Summary:
Both the autoconf and cmake build scripts check for
`cplus_demangle_v3_callback()` and define
`FOLLY_HAVE_CPLUS_DEMANGLE_V3_CALLBACK` appropriately.

Reviewed By: meyering

Differential Revision: D6745365

fbshipit-source-id: 3020593c60a21568781b835490b8d64913366cb9

3 years agoreuse more of Cursor to avoid future issues
Wez Furlong [Fri, 19 Jan 2018 02:39:50 +0000 (18:39 -0800)]
reuse more of Cursor to avoid future issues

Summary:
Following on from D6755842; we don't have to repeat as
much of the internals of `readFixedString`, so... don't!

Reviewed By: yfeldblum

Differential Revision: D6756062

fbshipit-source-id: db3e4fd62e48bf155a656ee57df84274021027f7

3 years agofixup decode logic for fragmented IOBufs
Wez Furlong [Fri, 19 Jan 2018 02:39:48 +0000 (18:39 -0800)]
fixup decode logic for fragmented IOBufs

Summary:
D6635325 exposed a long standing issue with the way
that we were consuming Cursor::length, so let's fix it up!

More details are in the new unit test for this!

Reviewed By: spalamarchuk

Differential Revision: D6755842

fbshipit-source-id: f8b20406c32682892791e7375be577d54d52e0ad

3 years agoImprove SingletonThreadLocal performance
Yedidya Feldblum [Thu, 18 Jan 2018 22:49:00 +0000 (14:49 -0800)]
Improve SingletonThreadLocal performance

Summary:
[Folly] Improve `SingletonThreadLocal` performance.

By explicitly controlling inlining behavior.

The ctor is definitionally cold - once per process - so outline.

`get` is hot so inline. Uncached `get` is cold - once per thread - so outline uncached.

Reviewed By: djwatson

Differential Revision: D6736662

fbshipit-source-id: 4cd77c7772b46e2e3c6b2a3dc071b2b06522979e

3 years agocmake: fix the test builds
Adam Simpkins [Wed, 17 Jan 2018 19:11:01 +0000 (11:11 -0800)]
cmake: fix the test builds

Summary:
- Fix the locations of some tests that have been moved.
- Remove some tests that have been deleted.
- Comment out some tests that depend on parts of folly that are not currently
  built by the CMake build scripts.
- Fix a build error in CompressionTest.cpp if FOLLY_HAVE_LIBZ is not defined.

Reviewed By: yfeldblum

Differential Revision: D6735700

fbshipit-source-id: 89f60751fa7079b2c609d23d85fbed2a0f317b55

3 years agofix a multiline comment warning
Adam Simpkins [Wed, 17 Jan 2018 18:05:24 +0000 (10:05 -0800)]
fix a multiline comment warning

Summary:
DeterministicScheduleTest.cpp contained several single-line C++ comments that
ended in a trailing backslash.  This makes the preprocessor treat the following
line as a comment as well, even if it does not start with `//`.  Newer versions
of gcc emit warnings about this.

This changes the comment in DeterministicScheduleTest.cpp to use `/* */` to
avoid this issue.

Reviewed By: siyengar

Differential Revision: D6735672

fbshipit-source-id: 162c735507a643ce0dbee58f1f054865237e1eba

3 years agofix some bugs in AsyncSSLSocketTest
Adam Simpkins [Wed, 17 Jan 2018 18:05:22 +0000 (10:05 -0800)]
fix some bugs in AsyncSSLSocketTest

Summary:
A couple of the test functions in AsyncSSLSocketTest maintained two EventBase
objects and alternated looping between them.  In some cases it would call
EventBase::loopOnce() even when there was no work to do.  This call normally
blocks until an event is ready.  This happened to work when using libevent1,
but this appears mostly accidental: with libevent1 EVLOOP_ONCE causes the loop
to break out even after an "internal" I/O event; in libevent2 EVLOOP_ONCE only
breaks out after a non-internal event has occurred:
https://github.com/libevent/libevent/commit/0617a818204397790e5e4c9bcb9e91ae5ea7817a

In these tests it turns out that the internal EventBase NotificationQueue
always gets triggered the very first time loopOnce() is called, preventing
these tests from hanging when using libevent1.

This fixes the hang when using libevent2 by removing the initial loopOnce()
calls that potentially have nothing to do.  This also consolidates the 2
EventBase objects into one to avoid having to alternate loopOnce() calls
between them without knowing which one actually has work to do.

This also fixes an issue where the code never checked the return value of
`recv()`

Reviewed By: yfeldblum, siyengar

Differential Revision: D6735669

fbshipit-source-id: 5f36106a08866aa8908e82263f83a606399cdf79

3 years agosuppress warnings in tests for deprecated functions
Adam Simpkins [Wed, 17 Jan 2018 18:05:21 +0000 (10:05 -0800)]
suppress warnings in tests for deprecated functions

Summary:
Update ShellTest and PromiseTest to suppress warnings about using deprecated
functions in the tests for those functions.

Reviewed By: yfeldblum

Differential Revision: D6735670

fbshipit-source-id: 89edcb49d1eff3132398aaef88f5a5cae82e3557

3 years agoAdd DCHECKs for checking that underlying IOBuf wasn't modified
Stepan Palamarchuk [Wed, 17 Jan 2018 17:39:12 +0000 (09:39 -0800)]
Add DCHECKs for checking that underlying IOBuf wasn't modified

Summary: Appending/prepending to IOBuf while iterating over it with Cursor is unsafe. This diff adds DCHECKs to catch such cases.

Reviewed By: yfeldblum

Differential Revision: D6735060

fbshipit-source-id: 7799facc52c53fabd83756ecb26a18c4ebd69677

3 years agoLoop Time
Dave Watson [Wed, 17 Jan 2018 16:17:44 +0000 (08:17 -0800)]
Loop Time

Summary:
Only do the exponential loop smoothing once every 10ms.
If we need it before then, do it linearly.

Also, remove one of the now()s by only calling it once.

Reviewed By: bmaurer, yfeldblum

Differential Revision: D6690047

fbshipit-source-id: 8267c01064aabc17cb8e86eb888e6120c99a129f

3 years agoProperly handle appending to the tail of the chain
Stepan Palamarchuk [Wed, 17 Jan 2018 11:12:41 +0000 (03:12 -0800)]
Properly handle appending to the tail of the chain

Summary: Currently appending to the tail of the chain would cause the cursor advancing to the beginning of the chain, which is not correct, instead we should advance to the tail.

Reviewed By: yfeldblum

Differential Revision: D6734999

fbshipit-source-id: b8b2585e0475b656f7b6bf4ed39686e2ccb2e432

3 years agoadd tryCreateNetwork()
Petr Lapukhov [Wed, 17 Jan 2018 03:01:23 +0000 (19:01 -0800)]
add tryCreateNetwork()

Summary: Add non-throwing version of createNetwork(), and rework existing code to throw exceptions based on error codes returned by non-throwing version.

Reviewed By: yfeldblum

Differential Revision: D6705425

fbshipit-source-id: 268ff64c36e7cceeea3463248d18b7b2cb81390e

3 years agoFix Build: folly/synchronization/test/ParkingLotBenchmark.cpp (sign-compare, unused...
Yedidya Feldblum [Wed, 17 Jan 2018 02:19:38 +0000 (18:19 -0800)]
Fix Build: folly/synchronization/test/ParkingLotBenchmark.cpp (sign-compare, unused-variable)

Summary: [Folly] Fix Build: `folly/synchronization/test/ParkingLotBenchmark.cpp` (`sign-compare`, `unused-variable`).

Reviewed By: djwatson

Differential Revision: D6733586

fbshipit-source-id: 04b82110e8e0b655e6b3994dbca3bd0b4bd57eef

3 years agocmake: fix path to FindGLog.cmake
Adam Simpkins [Wed, 17 Jan 2018 01:59:08 +0000 (17:59 -0800)]
cmake: fix path to FindGLog.cmake

Summary:
The cmake files refer to this package as "FindGLog", but the file name on disk
incorrectly had the 'L' lower cased.  This worked on case-insensitive file
systems, but caused cmake to fail when used on a case-sensitive file system.

This diff fixes the file name to match the name used in the cmake files.  This
is also more consistent with the existing "FindGFlags" and "FindGMock"
packages.

Reviewed By: yfeldblum

Differential Revision: D6710439

fbshipit-source-id: 19f6824ef6793e505b5a0080c0fefe0b145a41c3

3 years agoRevert D6725091: [Folly] Use thread-local in RequestContext::getStaticContext
Yedidya Feldblum [Wed, 17 Jan 2018 01:49:07 +0000 (17:49 -0800)]
Revert D6725091: [Folly] Use thread-local in RequestContext::getStaticContext

Summary:
This reverts commit 9979f39677284b1051cb109b461097495d77ca17

bypass-lint

An infra SEV is better than not reverting this diff.
If you copy this password, see you in SEV Review!
cause_a_sev_many_files

Differential Revision: D6725091

fbshipit-source-id: f1e3c80c869aa47684f5fbe79528e68174dee568

3 years agoparkinglot benchmark
Dave Watson [Tue, 16 Jan 2018 18:44:37 +0000 (10:44 -0800)]
parkinglot benchmark

Summary: Add benchmark vs. futex

Reviewed By: yfeldblum

Differential Revision: D6639280

fbshipit-source-id: 9735444a7f48011f31603159561675d472cc4411

3 years agodefine SKIP_IF
Jim Meyering [Tue, 16 Jan 2018 17:32:45 +0000 (09:32 -0800)]
define SKIP_IF

Summary:
Finding ourselves writing too many identical "if (expr) SKIP << ..." statements,
this change factors out/encapsulates the functionality.

Reviewed By: yfeldblum

Differential Revision: D6727531

fbshipit-source-id: 703abcd5d8c30a6ebab94327a12da4f2d1f7ff74

3 years agoUse thread-local in RequestContext::getStaticContext
Yedidya Feldblum [Tue, 16 Jan 2018 17:32:21 +0000 (09:32 -0800)]
Use thread-local in RequestContext::getStaticContext

Summary:
[Folly] Use thread-local in `RequestContext::getStaticContext`.

`folly::SingletonThreadLocal` uses `folly::ThreadLocal`. However, `static FOLLY_TLS` (`static __thread`) is always faster than `folly::ThreadLocal` for thread-local singletons for which iteration is not required.

Reviewed By: djwatson

Differential Revision: D6725091

fbshipit-source-id: 9979f39677284b1051cb109b461097495d77ca17

3 years agoFix missing WaitOptions symbol in autotools build
Yedidya Feldblum [Tue, 16 Jan 2018 00:49:14 +0000 (16:49 -0800)]
Fix missing WaitOptions symbol in autotools build

Summary:
[Folly] Fix missing `WaitOptions` symbol in autotools build.

Closes #736.

Reviewed By: spalamarchuk

Differential Revision: D6724950

fbshipit-source-id: 54ac0d1a743aa38fe1a7a2bdce585fced18c5a44

3 years agoTrack absolute position of the cursor
Stepan Palamarchuk [Tue, 16 Jan 2018 00:36:45 +0000 (16:36 -0800)]
Track absolute position of the cursor

Summary:
Start tracking the position of the cursor from the head of IOBuf chain. This comes at almost no cost (one arithmetic operation on IOBuf advance).

The main use case for this cursor is Thrift deserialization code. It allows us to stop accumulating `xfer` on every single byte/field/element write and instead get it from Cursor in the end (when we're exiting Thrift code).
This allows achieving ~10% better performance of deserialization.

Reviewed By: yfeldblum

Differential Revision: D6646813

fbshipit-source-id: 8f796854a24a411698e96afe037695e816813022

3 years agoImprove fast path of Cursor
Stepan Palamarchuk [Tue, 16 Jan 2018 00:36:41 +0000 (16:36 -0800)]
Improve fast path of Cursor

Summary:
This change simplifies the fastpath by reducing it to bare minimum (i.e. check length, load data) and removes indirection to IOBuf.
Additionally it adds `skipNoAdvance` method to have 1-instruction skip.

Disassembly of `read<signed char>` is over 35 instructions (just hot path). With this change it's doesn to 8.
Disassembly after:
  Dump of assembler code for function folly::io::detail::CursorBase<folly::io::Cursor, folly::IOBuf const>::read<unsigned char>():
     0x000000000041f0f0 <+0>:     mov    0x18(%rdi),%rax
     0x000000000041f0f4 <+4>:     lea    0x1(%rax),%rcx
     0x000000000041f0f8 <+8>:     cmp    0x10(%rdi),%rcx
     0x000000000041f0fc <+12>:    ja     0x41f105 <folly::io::detail::CursorBase<folly::io::Cursor, folly::IOBuf const>::read<unsigned char>()+21>
     0x000000000041f0fe <+14>:    mov    (%rax),%al
     0x000000000041f100 <+16>:    mov    %rcx,0x18(%rdi)
     0x000000000041f104 <+20>:    retq
     0x000000000041f105 <+21>:    jmpq   0x41f110 <folly::io::detail::CursorBase<folly::io::Cursor, folly::IOBuf const>::readSlow<unsigned char>()>

With this diff Thrift deserialization becomes ~20% faster (with prod workloads).

Thrift benchmark:
Before:
  ============================================================================
  thrift/lib/cpp2/test/ProtocolBench.cpp          relative  time/iter  iters/s
  ============================================================================
  BinaryProtocol_read_Empty                                   12.98ns   77.03M
  BinaryProtocol_read_SmallInt                                20.94ns   47.76M
  BinaryProtocol_read_BigInt                                  20.86ns   47.93M
  BinaryProtocol_read_SmallString                             34.64ns   28.86M
  BinaryProtocol_read_BigString                              185.53ns    5.39M
  BinaryProtocol_read_BigBinary                               67.34ns   14.85M
  BinaryProtocol_read_LargeBinary                             62.23ns   16.07M
  BinaryProtocol_read_Mixed                                   58.74ns   17.03M
  BinaryProtocol_read_SmallListInt                            89.99ns   11.11M
  BinaryProtocol_read_BigListInt                              39.92us   25.05K
  BinaryProtocol_read_BigListMixed                           616.20us    1.62K
  BinaryProtocol_read_LargeListMixed                          83.49ms    11.98
  CompactProtocol_read_Empty                                  11.28ns   88.67M
  CompactProtocol_read_SmallInt                               19.15ns   52.22M
  CompactProtocol_read_BigInt                                 26.14ns   38.25M
  CompactProtocol_read_SmallString                            31.04ns   32.22M
  CompactProtocol_read_BigString                             184.55ns    5.42M
  CompactProtocol_read_BigBinary                              69.73ns   14.34M
  CompactProtocol_read_LargeBinary                            64.39ns   15.53M
  CompactProtocol_read_Mixed                                  58.73ns   17.03M
  CompactProtocol_read_SmallListInt                           76.50ns   13.07M
  CompactProtocol_read_BigListInt                             25.93us   38.56K
  CompactProtocol_read_BigListMixed                          623.15us    1.60K
  CompactProtocol_read_LargeListMixed                         80.57ms    12.41
  ============================================================================

After:
  ============================================================================
  thrift/lib/cpp2/test/ProtocolBench.cpp          relative  time/iter  iters/s
  ============================================================================
  BinaryProtocol_read_Empty                                   10.40ns   96.17M
  BinaryProtocol_read_SmallInt                                15.14ns   66.03M
  BinaryProtocol_read_BigInt                                  15.19ns   65.84M
  BinaryProtocol_read_SmallString                             25.19ns   39.70M
  BinaryProtocol_read_BigString                              172.85ns    5.79M
  BinaryProtocol_read_BigBinary                               56.88ns   17.58M
  BinaryProtocol_read_LargeBinary                             56.77ns   17.61M
  BinaryProtocol_read_Mixed                                   43.98ns   22.74M
  BinaryProtocol_read_SmallListInt                            58.19ns   17.19M
  BinaryProtocol_read_BigListInt                              19.75us   50.63K
  BinaryProtocol_read_BigListMixed                           440.20us    2.27K
  BinaryProtocol_read_LargeListMixed                          56.94ms    17.56
  CompactProtocol_read_Empty                                   9.35ns  106.93M
  CompactProtocol_read_SmallInt                               13.07ns   76.49M
  CompactProtocol_read_BigInt                                 18.23ns   54.87M
  CompactProtocol_read_SmallString                            25.61ns   39.05M
  CompactProtocol_read_BigString                             174.46ns    5.73M
  CompactProtocol_read_BigBinary                              59.77ns   16.73M
  CompactProtocol_read_LargeBinary                            60.81ns   16.44M
  CompactProtocol_read_Mixed                                  42.70ns   23.42M
  CompactProtocol_read_SmallListInt                           66.89ns   14.95M
  CompactProtocol_read_BigListInt                             25.08us   39.87K
  CompactProtocol_read_BigListMixed                          427.93us    2.34K
  CompactProtocol_read_LargeListMixed                         56.11ms    17.82
  ============================================================================

Reviewed By: yfeldblum

Differential Revision: D6635325

fbshipit-source-id: 393fc1005689042977c03f37f5a898ebe7814d44

3 years agoallow command to accept "--" separator
Alvaro Leiva Geisse [Mon, 15 Jan 2018 22:07:55 +0000 (14:07 -0800)]
allow command to accept "--" separator

Summary:
Currently NestedCommandLineApp does not support `--` to indicate that the following arguments should be parsed as arguments, not nested commands or options.
This diff fix that by whitelisting any argument given after "--"

Reviewed By: yfeldblum

Differential Revision: D6721144

fbshipit-source-id: 38a850b6ea803dc758c5fe65a21575e5faeac35b

3 years agoFix copyright lines v2018.01.15.00
Yedidya Feldblum [Sun, 14 Jan 2018 19:28:07 +0000 (11:28 -0800)]
Fix copyright lines

Summary: [Folly] Fix copyright lines based on file histories.

Reviewed By: spalamarchuk

Differential Revision: D6720312

fbshipit-source-id: c70a667a1977e70e2d4451ea624f96163982f681

3 years agoConvert newlines in folly/portability/PThread.cpp
Yedidya Feldblum [Sun, 14 Jan 2018 18:14:13 +0000 (10:14 -0800)]
Convert newlines in folly/portability/PThread.cpp

Summary:
[Folly] Convert newlines in `folly/portability/PThread.cpp`.

```
dos2unix folly/portability/PThread.cpp
```

Reviewed By: meyering

Differential Revision: D6720343

fbshipit-source-id: b92122b4a7012d7f8d73d293af51b4fcc868c582

3 years agoAdd Tearable, for concurrently-modified non-atomic objects.
David Goldblatt [Sat, 13 Jan 2018 07:57:16 +0000 (23:57 -0800)]
Add Tearable, for concurrently-modified non-atomic objects.

Summary:
This adds the Tearable class template, which holds storage for an
arbitrarily-sized object that can be concurrently read or written without any
external synchronization.

Reviewed By: yfeldblum, djwatson

Differential Revision: D6422334

fbshipit-source-id: ee3853bbd393ac8e30dca6439c61606cc5495f92

3 years agoPromote aligned_malloc and aligned_free
Yedidya Feldblum [Sat, 13 Jan 2018 01:59:41 +0000 (17:59 -0800)]
Promote aligned_malloc and aligned_free

Summary:
[Folly] Promote `aligned_malloc` and `aligned_free` from `namespace folly::detail` to `namespace folly`.

And move them from `folly/portability/Memory.h` to `folly/Memory.h`.

Differential Revision: D6153394

fbshipit-source-id: eef314d2bc171910ea3c8403da9e9e1d1858ce15

3 years agocmake: remove DOS-style line endings
Adam Simpkins [Sat, 13 Jan 2018 00:03:02 +0000 (16:03 -0800)]
cmake: remove DOS-style line endings

Summary:
A number of the files in CMake/ had inconsistent line-endings.  This updates
files using DOS-style CRLF line endings to just use CR instead.  On Windows,
git is capable of automatically changing CR to CRLF when checking out the
repository working directory.

Reviewed By: meyering

Differential Revision: D6714717

fbshipit-source-id: 82adccf4e522d38fd1cb420869f62e52dbd6c5f1

3 years agocmake: add checks to generate folly-config.h correctly
Adam Simpkins [Sat, 13 Jan 2018 00:03:00 +0000 (16:03 -0800)]
cmake: add checks to generate folly-config.h correctly

Summary:
Add proper checks to detect and set the values in folly-config.h correctly.
Previously the code simply hard-coded values that were appropriate for Windows.

This does not yet define all of the settings produced by the autoconf build,
but it lets the CMake-based build largely succeed on Linux systems.

Reviewed By: meyering

Differential Revision: D6710437

fbshipit-source-id: 80490080ee6322995b740ac2a15181d220c6874a

3 years agocmake: set compiler flags for non-Windows platforms
Adam Simpkins [Sat, 13 Jan 2018 00:02:58 +0000 (16:02 -0800)]
cmake: set compiler flags for non-Windows platforms

Summary:
Update CMakeLists.txt to check the current platform, and to set compiler flags
correctly.  It now uses flags for Microsoft Visual Studio on Windows, and flags
for gcc or clang on all other platforms.  Previously it unconditionally used
MSVC flags.

Reviewed By: meyering

Differential Revision: D6710435

fbshipit-source-id: dbae3097bcadf1ee4a25879dd7770603387c0e4d

3 years agocmake: support using a separate build directory
Adam Simpkins [Sat, 13 Jan 2018 00:02:57 +0000 (16:02 -0800)]
cmake: support using a separate build directory

Summary:
Fix rules in the CMakeLists.txt file that generate source files to first create
their output directory if necessary.  This allows the build to succeed when
building with a separate build output directory, rather than placing build
artifacts in the source tree itself.

Reviewed By: meyering

Differential Revision: D6710436

fbshipit-source-id: 786a65a37a70833e7e4a5affe4df292626dbb591

3 years agocorrectly handle APIs that accept Poly<T&> as an argument
Eric Niebler [Fri, 12 Jan 2018 21:55:50 +0000 (13:55 -0800)]
correctly handle APIs that accept Poly<T&> as an argument

Summary: Multi-dispatch in Poly was handled by treating arguments of type Poly<I&> as special, unwrapping them. That's a problem if the underlying API actually wants the Poly<I&> unmolested.

Reviewed By: yfeldblum

Differential Revision: D6713975

fbshipit-source-id: 18a90fa701fab14c3d3d46c247efe09ea5903b11

3 years agoRegister singleton's destruction using std::atexit
Sergey Makarenko [Fri, 12 Jan 2018 21:42:05 +0000 (13:42 -0800)]
Register singleton's destruction using std::atexit

Summary:
scheduleDestroyInstances function is called from createInstance function when
new instance of specific singleton type is created thus marking a point in
static objects order  when all singltons will be destructed.
This does not work well for situations when singleton is loaded as part of
python extension which is a shared object. In this case static objects of this
shared object would be constructed first and singleton from this extension will
be created after that. Since destruction order is reversed and all singletons
will be destructed together, static objects of python extension will be
destroyed before singleton from this extension. Which leads to heap-after-free
ASAN exceptions.
In other words, lifetime of all folly singletons is aligned to the lifetime of the
first created folly singleton.
Using std::atexit to register singleton's destruction from singleton
constructor will align  lifetime of singletons to the most recent singleton
which matters for python extensions and does not matter for other use cases.

Reviewed By: andriigrynenko

Differential Revision: D6705644

fbshipit-source-id: 5c933886ceae649e3c75f8e7e7936d5a7ed04539

3 years agoSpell uintptr_t properly in static_assert in `getStackTrace()`
Enji Cooper [Fri, 12 Jan 2018 18:49:13 +0000 (10:49 -0800)]
Spell uintptr_t properly in static_assert in `getStackTrace()`

Summary:
While here, pet the linter with respect to the warning around the indentation with the comment containing the licensing tort.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Reviewed By: yfeldblum

Differential Revision: D6710314

fbshipit-source-id: fc0b971e6300af9c63a690c54c08fc70e0313b70

3 years agoUnsafe pre-sorted construction for sorted-vector containers
Yedidya Feldblum [Fri, 12 Jan 2018 05:56:07 +0000 (21:56 -0800)]
Unsafe pre-sorted construction for sorted-vector containers

Summary:
[Folly] Unsafe pre-sorted construction for sorted-vector containers.

If the backing container type can be constructed directly in sorted order or can be determined in advance to be in sorted order, then a special constructor can help code take advantage of this condition by avoiding an extra invocation of `std::sort`.

Reviewed By: spalamarchuk

Differential Revision: D6708379

fbshipit-source-id: 25d886b0814dc9230c6046ed1e7f199fac47754e

3 years agocmake: fix error message on non-Windows platform
Adam Simpkins [Fri, 12 Jan 2018 02:24:07 +0000 (18:24 -0800)]
cmake: fix error message on non-Windows platform

Summary:
Building folly with cmake is only supported on Windows for now.  This fixes
cmake on non-Windows platforms to fail with a helpful message telling people to
use autoconf.  This message was in place before, but was after an MSVC version
check preventing it from appearing.

Reviewed By: meyering

Differential Revision: D6707328

fbshipit-source-id: a28a07ab0da41d605b11d93bba40f33520c5f57e

3 years agoMemoryIdler::futexWaitUntil
Yedidya Feldblum [Thu, 11 Jan 2018 21:26:45 +0000 (13:26 -0800)]
MemoryIdler::futexWaitUntil

Summary:
[Folly] `MemoryIdler::futexWaitUntil`.

Adds `MemoryIdler::futexWaitUntil` that works like `Futex::futexWaitUntil`, in a similar way that `MemoryIdler::futexWait` works like `Futex::futexWait`.

Removes the ability to customize the idle-timeout clock for `MemoryIdler::futexWait` as a side-effect; the idle-timeout is now a pure duration. Now, the clock used with the idle-timeout is the same as the normal deadline clock, so the idle-timeout clock can be set for `MemoryIdler::futexWaitUntil` by providing a deadline with that clock type. This normally would not matter, but it affects the unit-tests.

Reviewed By: djwatson

Differential Revision: D6681679

fbshipit-source-id: e3cf6e71d7530c5877a834b318b423eb91f71eb9

3 years agoRelax stop_ memory order
Dave Watson [Thu, 11 Jan 2018 16:00:19 +0000 (08:00 -0800)]
Relax stop_ memory order

Summary: stop_ can be relaxed everywhere, it implies only an asynchronous signal, not any sort of memory barrier.

Reviewed By: davidtgoldblatt

Differential Revision: D6690079

fbshipit-source-id: 6f193204e1619f9a8adf81db2d46d05954bfbf85

3 years agoCut the ScopeGuard alias now that we have auto
Yedidya Feldblum [Thu, 11 Jan 2018 01:52:16 +0000 (17:52 -0800)]
Cut the ScopeGuard alias now that we have auto

Summary:
[Folly] Cut the `ScopeGuard` alias now that we have `auto`.

This form works because of hidden lifetime extension:
```lang=c++
folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ });
//  ...
//  guard falls out of scope
```
But this form would not work correctly:
```lang=c++
folly::ScopeGuard guard = folly::makeGuard([] { /*...*/ });
std::async(std::launch::async, [guard = std::move(guard)] {});
```
Because `folly::ScopeGuard` is an rvalue-reference-to-base.
We have `auto`, so just remove `folly::ScopeGuard`. This form works correctly:
```lang=c++
auto guard = folly::makeGuard([] { /*...*/ });
std::async(std::launch::async, [guard = std::move(guard)] {});
```

Reviewed By: igorsugak

Differential Revision: D6690070

fbshipit-source-id: 54e32b300d36fce4eb95a59f1828819afe312ec0

3 years agoMove ScopeGuardImpl and ScopeGuardImplBase into the detail namespace
Yedidya Feldblum [Thu, 11 Jan 2018 01:52:13 +0000 (17:52 -0800)]
Move ScopeGuardImpl and ScopeGuardImplBase into the detail namespace

Summary:
[Folly] Move `ScopeGuardImpl` and `ScopeGuardImplBase` into the `detail` namespace.

Let them be marked as private implementation details.

Reviewed By: andrewjcg

Differential Revision: D6665317

fbshipit-source-id: 03e8fee6a16338395ec92c582613b053bd9f74ec

3 years agoStop using ScopeGuardImpl in DynamicParser
Yedidya Feldblum [Thu, 11 Jan 2018 01:52:11 +0000 (17:52 -0800)]
Stop using ScopeGuardImpl in DynamicParser

Summary:
[Folly] Stop using `ScopeGuardImpl` in `DynamicParser`.

`ScopeGuardImpl` is an impl type that should not be treated as public.

Reviewed By: igorsugak

Differential Revision: D6689835

fbshipit-source-id: aea6c985e40887594c0aeb0c0948fa77c149a89b

3 years agofolly::Init, RAII variant of folly::init
Yedidya Feldblum [Wed, 10 Jan 2018 21:44:14 +0000 (13:44 -0800)]
folly::Init, RAII variant of folly::init

Summary:
[Folly] `folly::Init`, RAII variant of `folly::init`.

Use it in `main` used by unit-tests.

Reviewed By: ot

Differential Revision: D6566358

fbshipit-source-id: fb8e5a18fc43eb65e2cbeb070d97094bd413bb96

3 years agoUnboundedQueue: Use hazptr_obj_batch
Maged Michael [Wed, 10 Jan 2018 20:43:40 +0000 (12:43 -0800)]
UnboundedQueue: Use hazptr_obj_batch

Summary: Manage retirement of removed segments using hazptr_obj_batch in order to reduce the chances of fragmenting related segments across thread local lists of retired objects of many threads, which could lead to unnecessarily high memory usage.

Reviewed By: djwatson

Differential Revision: D6686697

fbshipit-source-id: 0d786c0f9e0bac2c44183ed3da21619e1feb3d52

3 years agologging: fix build error when using gcc with -Wmissing-braces
Adam Simpkins [Wed, 10 Jan 2018 20:29:05 +0000 (12:29 -0800)]
logging: fix build error when using gcc with -Wmissing-braces

Summary:
Since std::array is actually a struct containing an array it technically
requires double braces around its initializer.  The language allows eliding
these braces, and clang doesn't complain about only using a single brace, but
gcc does when using `-Wmissing-braces`.

Reviewed By: yfeldblum

Differential Revision: D6695289

fbshipit-source-id: 913fcfbea4164a02d001bd2344e340c0b6ee62aa

3 years agoLet Futex import base-class ctors
Yedidya Feldblum [Wed, 10 Jan 2018 20:05:34 +0000 (12:05 -0800)]
Let Futex import base-class ctors

Summary:
[Folly] Let `Futex` import base-class ctors.

Rather than needing to define ctors and inherit `boost::noncopyable`.

Reviewed By: WillerZ

Differential Revision: D6674054

fbshipit-source-id: 59e0a4815682b227346954fe47c6eda49e3ad62f

3 years agoAdd hazptr_obj_batch
Maged Michael [Wed, 10 Jan 2018 16:40:46 +0000 (08:40 -0800)]
Add hazptr_obj_batch

Summary: Provide capability for custom batching retirement of objects, for example object that belong to the same data structure, to avoid the risk fragmenting related objects across thread local lists of retired objects of many threads, which could lead to unnecessarily high memory usage.

Reviewed By: djwatson

Differential Revision: D6686603

fbshipit-source-id: fadcade73e71170ef1bcec221c4da6f4ddeecff5

3 years agoTweak FutexResult comments
Yedidya Feldblum [Wed, 10 Jan 2018 06:39:16 +0000 (22:39 -0800)]
Tweak FutexResult comments

Summary: [Folly] Tweak `FutexResult` comments.

Reviewed By: nbronson

Differential Revision: D6673979

fbshipit-source-id: 1777311cd93d5a83432c4ebb48a8432a1c504ca9

3 years agoFutex::futexWait returns FutexResult
Yedidya Feldblum [Wed, 10 Jan 2018 06:39:13 +0000 (22:39 -0800)]
Futex::futexWait returns FutexResult

Summary: [Folly] `Futex::futexWait` returns `FutexResult`.

Reviewed By: nbronson

Differential Revision: D6673871

fbshipit-source-id: 378c69d8362970e985da31e31d8e9b0179d2917f

3 years agoSupport for all clock types in Futex
Yedidya Feldblum [Wed, 10 Jan 2018 06:39:11 +0000 (22:39 -0800)]
Support for all clock types in Futex

Summary:
[Folly] Support for all clock types in `Futex`.

Only `system_clock` and `steady_clock` remain optimal as before, but at least let `Futex` work, even if non-optimally, for all clock types.

Reviewed By: nbronson

Differential Revision: D6673741

fbshipit-source-id: 0a0f778f61b71bea76e12b7fab478e33ce3bbaae

3 years agoUse ptr-to-const in Futex
Yedidya Feldblum [Wed, 10 Jan 2018 06:39:10 +0000 (22:39 -0800)]
Use ptr-to-const in Futex

Summary: [Folly] Use ptr-to-`const` in `Futex`.

Reviewed By: igorsugak

Differential Revision: D6673723

fbshipit-source-id: b828c2284b40ec8166e823eca7725beccd330f87

3 years agoFix some copyright lines in folly/detail/ and folly/test/
Yedidya Feldblum [Wed, 10 Jan 2018 06:39:08 +0000 (22:39 -0800)]
Fix some copyright lines in folly/detail/ and folly/test/

Summary: [Folly] Fix some copyright lines in `folly/detail/` and `folly/test/`.

Differential Revision: D6673878

fbshipit-source-id: 6c060a974bb4d40d0f24a44ebddddf892805c65e

3 years agoBaton support for wait-options
Yedidya Feldblum [Wed, 10 Jan 2018 04:11:18 +0000 (20:11 -0800)]
Baton support for wait-options

Summary: [Folly] Baton support for wait-options

Reviewed By: nbronson

Differential Revision: D6591168

fbshipit-source-id: beca8422ac0daa572fb43c371923a86f199999f9

3 years agoTimed wait operations for spin-only Baton
Yedidya Feldblum [Wed, 10 Jan 2018 04:11:16 +0000 (20:11 -0800)]
Timed wait operations for spin-only Baton

Summary:
[Folly] Timed wait operations for spin-only `Baton`.

Enables `try_wait_for` and `try_wait_until` for `Baton</* MayBlock = */ false, /*...*/>`.

Reviewed By: nbronson

Differential Revision: D6672153

fbshipit-source-id: 95da07260b21c2b88b8f7bf81cbfcbe5f5099ac0

3 years agologging: include file name suffixes in XLOG() category names
Adam Simpkins [Wed, 10 Jan 2018 04:08:38 +0000 (20:08 -0800)]
logging: include file name suffixes in XLOG() category names

Summary:
Update `getXlogCategoryNameForFile()` to keep the file name suffix (e.g., `.h`
or `.cpp`) in the category name.  Previously the code had stripped this out.
However it seems worth leaving it in:
- This makes it possible to independently control log levels for messages from
  the header file vs the cpp file.
- This makes the category name logic slightly easier to explain to users.

The documents I added in D6525997 already describe this new category name
selection behavior.  This change updates the code to match the documented
behavior.

Reviewed By: yfeldblum

Differential Revision: D6690464

fbshipit-source-id: 9af6b549d084bd900f788a08e9213e82579b664a

3 years agologging: add numbered INFO* log level values
Adam Simpkins [Wed, 10 Jan 2018 04:08:37 +0000 (20:08 -0800)]
logging: add numbered INFO* log level values

Summary:
Define INFO0 through INFO9 levels for users that want to have finer-grained
control over info log messages.

This also renumbers the DBG log levels slightly so that there are exactly 1000
levels between each major log level step.  This renumbering change should not
affect any code behavior, since these level values are primarily used in memory
and aren't saved persistently anywhere.

Reviewed By: yfeldblum

Differential Revision: D6690466

fbshipit-source-id: acd499cff6830a1d1b579f295bd4b2bac93b5ada

3 years agologging: rename the `DEBUG` log level to `DBG`
Adam Simpkins [Wed, 10 Jan 2018 04:08:35 +0000 (20:08 -0800)]
logging: rename the `DEBUG` log level to `DBG`

Summary:
I ran into some open source projects that define `DEBUG` as a preprocessor
macro on the compiler command line.  (They effectively defined it as the
opposite of `NDEBUG`.)  Doing some Google searches revealed that there are a
number of projects that appear to use this as a macro.

Therefore this diff renames the `DEBUG` log level enum value to `DBG` to avoid
potentially conflicting with projects that do use `DEBUG` as a macro name.

I did keep the behavior that `logLevelToString()` returns "DEBUG" for an input
of `LogLevel::DBG`.

Reviewed By: yfeldblum

Differential Revision: D6690465

fbshipit-source-id: 35bb1698afb45eb670e60c192f21390cbf09331d

3 years agoChange the enumerate() example to bind the proxy by reference
Giuseppe Ottaviano [Wed, 10 Jan 2018 02:44:44 +0000 (18:44 -0800)]
Change the enumerate() example to bind the proxy by reference

Summary:
When compiling without optimizations binding the proxy by
reference is slightly faster (no differences in opt mode), so change
the documentation to recommend this syntax.

The proxy can still be bound by `auto`, `const auto`, and `const
auto&`, in all case behaving as expected and with no overhead in opt
mode. Added a test to make sure these all work.

Reviewed By: yfeldblum, luciang

Differential Revision: D6688958

fbshipit-source-id: 7c6b460a01708786bda7614546fa2e1667f27299

3 years agoImprove performance of enumerate() with optimization disabled
Giuseppe Ottaviano [Wed, 10 Jan 2018 02:44:43 +0000 (18:44 -0800)]
Improve performance of enumerate() with optimization disabled

Reviewed By: yfeldblum, WillerZ

Differential Revision: D6682606

fbshipit-source-id: 5a203a849e96d3020cf9ad2669451122954c2199

3 years agoFixing typo in sorted_vector_types.h
Adriana Libório [Wed, 10 Jan 2018 00:13:22 +0000 (16:13 -0800)]
Fixing typo in sorted_vector_types.h

Summary:
title

Created from Diffusion's 'Open in Editor' feature.

(Note: this ignores all push blocking failures!)

Reviewed By: Sushisugre

Differential Revision: D6688367

fbshipit-source-id: 6e2f2d3fcb897fe78c1caef841515856b1f2bd42

3 years agoReturn if we handle any error messages to avoid unnecessarily calling recv/send
Dan Melnic [Tue, 9 Jan 2018 19:36:55 +0000 (11:36 -0800)]
Return if we handle any error messages to avoid unnecessarily calling recv/send

Summary: Return if we handle any error messages to avoid unnecessarily calling recv/send

Reviewed By: yfeldblum

Differential Revision: D6677314

fbshipit-source-id: 21f724bb2c92b954888ba97bf7820d72decd2775

3 years agouse in futex
Dave Watson [Tue, 9 Jan 2018 15:32:57 +0000 (07:32 -0800)]
use in futex

Summary: Use new ParkingLot API in futex.

Reviewed By: yfeldblum

Differential Revision: D6595853

fbshipit-source-id: 7024ac1d3e0c5958a651a3e33c1427038bbe7808

3 years agoAdd a check if max atomic_shared_ptrs is reached.
Dave Watson [Tue, 9 Jan 2018 15:30:49 +0000 (07:30 -0800)]
Add a check if max atomic_shared_ptrs is reached.

Summary:
Batching reference counts reduces the maximum number of atomic_shared_ptrs
available to the system (and also shared_ptrs).

Add a check, test, and some comments about it.

Reviewed By: yfeldblum

Differential Revision: D5916291

fbshipit-source-id: 0bbf7b43284d94a304201219883c82b3654c1585

3 years agoUnboundedBlockingQueue: Adjust segment size
Maged Michael [Tue, 9 Jan 2018 00:29:24 +0000 (16:29 -0800)]
UnboundedBlockingQueue: Adjust segment size

Summary: Adjust the segment size of the `UnboundedQueue` to 64 instead of 256, a size more suitable for CPUThreadPoolExecutor::CPUTask elements.

Reviewed By: djwatson

Differential Revision: D6665918

fbshipit-source-id: c34c4fa936ee5c6d6a3dd4489129c936369f3980

3 years agogive all folly exception types default visibility
Eric Niebler [Mon, 8 Jan 2018 23:21:57 +0000 (15:21 -0800)]
give all folly exception types default visibility

Summary: This makes sure that whether folly is statically or dynamically linked, all folly exception types will have exactly one definition, and one set of type information.

Reviewed By: mzlee

Differential Revision: D6671431

fbshipit-source-id: 1c06826a05f87cbf9af747c9abdb5f524744d054

3 years agoUpdate cpuid test to expect failure on non intel cpu
Keith Daigle [Mon, 8 Jan 2018 19:31:12 +0000 (11:31 -0800)]
Update cpuid test to expect failure on non intel cpu

Summary: Found that testing would fail on aarch64 since mmx is an Intel thing.  Changed it to just check for x64.

Reviewed By: yfeldblum

Differential Revision: D6670050

fbshipit-source-id: 6ce4b45bb5ef02d65305636d6ac28be7631ddf1b

3 years agotest that _sp includes nul bytes
Chad Austin [Mon, 8 Jan 2018 19:12:18 +0000 (11:12 -0800)]
test that _sp includes nul bytes

Summary:
D6617812 wants to build a StringPiece from a literal with an
embedded nul. Add a test to verify that _sp is suitable for this use
case.

Reviewed By: yfeldblum

Differential Revision: D6651024

fbshipit-source-id: be4fb875762829fdb61c57fa72954fef286e9df0

3 years agoUse local error buffer in readStoreFromBuffer
Neel Goyal [Mon, 8 Jan 2018 16:49:37 +0000 (08:49 -0800)]
Use local error buffer in readStoreFromBuffer

Summary: ERR_error_string will use a static buffer if none is provided.  This is unsafe in threaded envs when we build a string out of it later.  Switch this to use ERR_error_string_n

Reviewed By: yfeldblum, knekritz

Differential Revision: D6664958

fbshipit-source-id: 2071347373ac61ebc28296fa66845cd718172b5e

3 years agoRemove gcc-v4.7 support from MemoryIdler v2018.01.08.00
Yedidya Feldblum [Mon, 8 Jan 2018 05:40:55 +0000 (21:40 -0800)]
Remove gcc-v4.7 support from MemoryIdler

Summary:
[Folly] Remove gcc-v4.7 support from `MemoryIdler`.

As of gcc-v4.8, `std::is_trivial<std::chrono::duration<Rep, Period>>::value` holds. We no longer need any extra support.

Reviewed By: meyering

Differential Revision: D6673517

fbshipit-source-id: f28b2d126f113547ebf36c85f9fa37a5d944d65b

3 years agoTerminal comma for FutexResult enumerators
Yedidya Feldblum [Sun, 7 Jan 2018 22:19:17 +0000 (14:19 -0800)]
Terminal comma for FutexResult enumerators

Summary: [Folly] Terminal comma for `FutexResult` enumerators. Style nit.

Reviewed By: meyering

Differential Revision: D6673523

fbshipit-source-id: abf9f4d3e99bf9a6d3042a49252b1b1190e69b9f

3 years agoUse auto for scope-guard locals v.s. folly::ScopeGuard
Yedidya Feldblum [Sat, 6 Jan 2018 06:45:21 +0000 (22:45 -0800)]
Use auto for scope-guard locals v.s. folly::ScopeGuard

Summary: Use `auto` for scope-guard locals v.s. `folly::ScopeGuard`.

Reviewed By: igorsugak, meyering

Differential Revision: D6664915

fbshipit-source-id: ea239b712f3f9dc7ef81105aaf82f4b36bc07db5

3 years agogive EventBase a non-explicit default constructor
Eric Niebler [Sat, 6 Jan 2018 01:31:41 +0000 (17:31 -0800)]
give EventBase a non-explicit default constructor

Summary: Default constructors are strange and often unexpected. Refactor.

Reviewed By: yfeldblum

Differential Revision: D6667480

fbshipit-source-id: 24c456c46c846c61e28f1a88806d7c36d9192493

3 years agoAdd threshold for thread local retired objects
Maged Michael [Sat, 6 Jan 2018 00:10:46 +0000 (16:10 -0800)]
Add threshold for thread local retired objects

Summary: Change the threshold for pushing privately held retired object to the domain to a moderate constant instead of using the threshold for bulk reclamation which is too high for this purpose.

Reviewed By: djwatson

Differential Revision: D6665904

fbshipit-source-id: 0b090884843b0296a93af7994f7183f41c00000e

3 years agoSynchronized::exchange
Yedidya Feldblum [Fri, 5 Jan 2018 22:23:31 +0000 (14:23 -0800)]
Synchronized::exchange

Summary:
[Folly] `Synchronized::exchange`, for assigning a new value and returning the old value.

(Note: this ignores all push blocking failures!)

Differential Revision: D6653482

fbshipit-source-id: 68f4bd330bc2cf37bb92aff98b8ce3221334112e

3 years agoFix copyright lines in folly/synchronization/Baton.h
Yedidya Feldblum [Fri, 5 Jan 2018 21:29:57 +0000 (13:29 -0800)]
Fix copyright lines in folly/synchronization/Baton.h

Summary: [Folly] Fix copyright lines in `folly/synchronization/Baton.h`.

Reviewed By: meyering

Differential Revision: D6665595

fbshipit-source-id: 84aa0c475f01c858d543a047103437c083b3a4ed

3 years agoClarify folly::ssl::init documentation
Mingtao Yang [Fri, 5 Jan 2018 20:54:46 +0000 (12:54 -0800)]
Clarify folly::ssl::init documentation

Summary: Adds wording indicating that it is safe to call this function multiple times.

Reviewed By: yfeldblum

Differential Revision: D6625530

fbshipit-source-id: 2305f7b8e3451a6663003d23230b22c6f65a3729

3 years agoCut glog include from folly/synchronization/RWSpinLock.h
Yedidya Feldblum [Fri, 5 Jan 2018 07:08:09 +0000 (23:08 -0800)]
Cut glog include from folly/synchronization/RWSpinLock.h

Summary: [Folly] Cut `glog` include from `folly/synchronization/RWSpinLock.h`.

Reviewed By: meyering

Differential Revision: D6659300

fbshipit-source-id: 0f1b79d98be0656694f57667252a16acd54e2414

3 years agoMove folly/RWSpinLock.h to folly/synchronization/
Yedidya Feldblum [Fri, 5 Jan 2018 07:08:03 +0000 (23:08 -0800)]
Move folly/RWSpinLock.h to folly/synchronization/

Summary: [Folly] Move `folly/RWSpinLock.h` to `folly/synchronization/`.

Reviewed By: elsteveogrande

Differential Revision: D6659265

fbshipit-source-id: 307723e22f42ceb104f26657aed8b34f7e183afb

3 years agoExtract WaitOptions
Yedidya Feldblum [Fri, 5 Jan 2018 07:02:09 +0000 (23:02 -0800)]
Extract WaitOptions

Summary:
[Folly] Extract `WaitOptions` from `SaturatingSemaphore`.

This type may prove useful in the future for a variety of similar cases, and so does not need to be locked up inside `SaturatingSemaphore`.

Additionally:
* Extract and redraft a comment from `Baton`.
* Rename `pre_block` to `spin_max`.

Reviewed By: djwatson, aary

Differential Revision: D6632875

fbshipit-source-id: 6b7faeeb6e1ac2011a037c2b560def0ee2e9f3d4

3 years agoMove folly/BitIterator.h to folly/container/
Yedidya Feldblum [Fri, 5 Jan 2018 03:44:07 +0000 (19:44 -0800)]
Move folly/BitIterator.h to folly/container/

Summary: [Folly] Move `folly/BitIterator.h` to `folly/container/`.

Reviewed By: djwatson

Differential Revision: D6648357

fbshipit-source-id: 5617e3210f58435fcbf3ef07fa745da47dbce475

3 years agoMove InPlaceConstruction test in folly/test/SynchronizedTest.cpp
Yedidya Feldblum [Fri, 5 Jan 2018 03:29:27 +0000 (19:29 -0800)]
Move InPlaceConstruction test in folly/test/SynchronizedTest.cpp

Summary: [Folly] Move `InPlaceConstruction` test in `folly/test/SynchronizedTest.cpp`.

Differential Revision: D6653481

fbshipit-source-id: f0eadfd6c2f41e9f597a666d01e40d5553447c70

3 years agoFix copyright lines for folly/Synchronized.h
Yedidya Feldblum [Fri, 5 Jan 2018 03:29:25 +0000 (19:29 -0800)]
Fix copyright lines for folly/Synchronized.h

Summary: [Folly] Fix copyright lines for `folly/Synchronized.h`.

Reviewed By: meyering

Differential Revision: D6664326

fbshipit-source-id: 71a0fc17358e41dfc751b8bcb0736c288975a4a0

3 years agoAdd utility to create stores
Neel Goyal [Fri, 5 Jan 2018 01:56:20 +0000 (17:56 -0800)]
Add utility to create stores

Summary: Add methods to create a X509StoreUniquePtr from a ca file or buffer.

Reviewed By: yfeldblum

Differential Revision: D6662538

fbshipit-source-id: 646f61596f2787756b2fa5998a43f36d75a91d90

3 years agoMake FOLLY_HAS_COROUTINES dependent on header
Keith Daigle [Thu, 4 Jan 2018 14:37:27 +0000 (06:37 -0800)]
Make FOLLY_HAS_COROUTINES dependent on header

Summary:
This breaks while building on aarch64 each time because the headers aren't
in the repo. I did a quick grep and I don't see anything in folly that
uses OptionalAwaitable or OptionalPromise so perhaps it's possible to
remove instead, can do that if preferred.  Depends on D6611609 to complete
build of tests cleanly.

Reviewed By: yfeldblum

Differential Revision: D6643759

fbshipit-source-id: f480d50383f85fbe905daaad74198b6557609347

3 years agoAvoid allocs in dtors in futures collect
Yedidya Feldblum [Wed, 3 Jan 2018 21:41:22 +0000 (13:41 -0800)]
Avoid allocs in dtors in futures collect

Summary:
[Folly] Avoid allocs in dtors in futures `collect`.

`CollectContext`, a detail helper type, allocates storage for a results vector in its dtor. This is an awkward situation and should be avoided.

Reviewed By: ericniebler

Differential Revision: D6649299

fbshipit-source-id: 87746fcc78fa080f63505d7bb864aca6c4a3d7cb

3 years agoFix to build SharedMutexTest on aarch64
Keith Daigle [Wed, 3 Jan 2018 14:58:45 +0000 (06:58 -0800)]
Fix to build SharedMutexTest on aarch64

Summary:
While trying to build folly on aarch64 found that the SharedMutexTest
wouldn't build because it uses RWTicketSpinLock which was only available
on x86 platforms.  Updated to allow build on aarch64 after suggestion by Orvid

Reviewed By: yfeldblum

Differential Revision: D6611609

fbshipit-source-id: 8ec477cdedac0f0a705608bbac42dd63b3efb919

3 years agoMake consistent set of get and getTry methods on SemiFuture.
Lee Howes [Wed, 3 Jan 2018 04:29:49 +0000 (20:29 -0800)]
Make consistent set of get and getTry methods on SemiFuture.

Summary: Complete set of get and getVia methods including addition of a result operation on FutureBase that provides functionality of the old getTry on Future by returning a Try by reference.

Reviewed By: yfeldblum

Differential Revision: D6640056

fbshipit-source-id: 3ac01f7bc4b128e641f08d9a99280a18ffce82f9

3 years agoRemove SingletonVault C bindings
Yedidya Feldblum [Tue, 2 Jan 2018 03:08:45 +0000 (19:08 -0800)]
Remove SingletonVault C bindings

Summary: [Folly] Remove `SingletonVault` C bindings. They are not generally needed.

Reviewed By: spalamarchuk

Differential Revision: D6632104

fbshipit-source-id: 3aecb35277bc76a2171487404d6994a5ea296afc

3 years agoUse member-invoke traits in LockTraits
Yedidya Feldblum [Tue, 2 Jan 2018 01:05:02 +0000 (17:05 -0800)]
Use member-invoke traits in LockTraits

Summary:
[Folly] Use member-invoke traits in `LockTraits`.

V.s. spelling out the SFINAE manually.

Reviewed By: Orvid

Differential Revision: D6637380

fbshipit-source-id: 212e0cc5e54503b31e458b6bda93b2a3b24e6c59