folly.git
8 years agoMake folly's T_CHECK_TIMEOUT/T_CHECK_TIME_LT use SKIP() on failure
Mark Isaacson [Wed, 25 Nov 2015 19:38:54 +0000 (11:38 -0800)]
Make folly's T_CHECK_TIMEOUT/T_CHECK_TIME_LT use SKIP() on failure

Summary: Make these more spurious failure-aware/tolerant.

Reviewed By: yfeldblum

Differential Revision: D2689775

fb-gh-sync-id: 1a9b247b97cc3529b12f6f7b76a4af2e32822d45

8 years agofolly/detail/ThreadLocalDetail.h: avoid UBSAN-detected memcpy abuse
Jim Meyering [Wed, 25 Nov 2015 19:06:24 +0000 (11:06 -0800)]
folly/detail/ThreadLocalDetail.h: avoid UBSAN-detected memcpy abuse

Summary: [technically, the existing code is probably a no-op on
all systems we care about, but since it is officially UB, switching
to a more strict platform could cause trouble, so it's worth fixing]

Calling memcpy with "nullptr" as 2nd argument is undefined, even when
the third argument is zero, and causes a failure when testing with an
UBSAN-enabled binary (-fsanitize=undefined).
Before this change, the buck-run test below would evoke this failure:

  [ RUN      ] ThreadLocalPtr.BasicDestructor
  folly/detail/ThreadLocalDetail.h:533:29: runtime error: null pointer passed as argument 2, which is declared to never be null
  third-party-buck/build/glibc/include/string.h:47:45: note: nonnull attribute specified here

Ironically, the failure of the target-determinator-buck_push_blocking test (due to an unrelated proxygen dep problem) would block me from landing this, so I am adding this line to override it.

Reviewed By: luciang, alexshap

Differential Revision: D2692625

fb-gh-sync-id: 8bdc5cd2899705f39c9565d640921de1f363807d

8 years agoRemove undefined behavior in goodMallocSize()
Adrien Conrath [Wed, 25 Nov 2015 16:34:09 +0000 (08:34 -0800)]
Remove undefined behavior in goodMallocSize()

Reviewed By: ot

Differential Revision: D2695741

fb-gh-sync-id: d33263c1ffa5651d66f37992ce365dae157ed449

8 years agoMake goodMallocSize always use nallocx
Giuseppe Ottaviano [Wed, 25 Nov 2015 08:26:31 +0000 (00:26 -0800)]
Make goodMallocSize always use nallocx

Summary: `goodMallocSize` is used extensively in `folly` data structures,
especially for containers optimized for small contents, such as
`fbstring` and `small_vector`.

However, it makes the design decision to align the allocation size to
a x86 cache line, forcing a minimum allocation size of `64` bytes,
despite jemalloc can provide smaller size classes (8, 16, 32,
48). This causes a large discontinuity between small contents that can
be inlined and heap-allocated contents:

- For `fbstring`, a string of 23 bytes (including terminator) occupies
  24 bytes (`sizeof(fbstring)`), a string of 24 bytes occupies 24 + 64
  + allocation overhead when it could be 24 + 32 + allocation
  overhead. The waste is more than 50%.

- For `small_vector<uint32_t, 1, uint32_t>`, for instance, a vector
  with 1 element occupies 12 bytes, a vector with 2 elements occupies
  12 + 64 + allocation overhead when it could be 12 + 8 + allocation
  overhead. The waste is more than 250%.

With this diff we just trust jemalloc and always use `nallocx`. If a
data structure need cache-line alignment it should be implemented at
its level.

Reviewed By: elsteveogrande

Differential Revision: D2688156

fb-gh-sync-id: 46548d4a91952e7c673d4f0997c4c067e03c190d

8 years agoA well-known instance of folly::Unit
Yedidya Feldblum [Wed, 25 Nov 2015 04:26:15 +0000 (20:26 -0800)]
A well-known instance of folly::Unit

Summary: [Folly] A well-known instance of `folly::Unit`.

Reviewed By: jsedgwick

Differential Revision: D2693426

fb-gh-sync-id: fe595abc852500275a827b4f400cfda7091a55f7

8 years agoExceptionWrapper::with_exception variant, deducing exception type from functor type
Yedidya Feldblum [Wed, 25 Nov 2015 02:27:46 +0000 (18:27 -0800)]
ExceptionWrapper::with_exception variant, deducing exception type from functor type

Summary: [Folly] `ExceptionWrapper::with_exception` variant deducing exception type from functor type.

From the `README.md`:

    // TODO(jsedgwick) infer exception type from the type of the function

Reviewed By: Gownta

Differential Revision: D2685579

fb-gh-sync-id: 158bcd030019f28b4f392d17167ab0bd67cc1edb

8 years agoAdd sdallocx for jemalloc
Qinfan Wu [Tue, 24 Nov 2015 18:02:25 +0000 (10:02 -0800)]
Add sdallocx for jemalloc

Summary: Make jemalloc's sdallocx function available in folly and allow future code to
use sized deallocation.

Reviewed By: elsteveogrande, ot

Differential Revision: D2687746

fb-gh-sync-id: 9ef8a16d2c63c4eb8cecab7639add423ef093c2d

8 years agoFix Build: folly/test/ThreadLocalTest
Yedidya Feldblum [Tue, 24 Nov 2015 02:45:15 +0000 (18:45 -0800)]
Fix Build: folly/test/ThreadLocalTest

Summary: [Folly] Fix Build: `folly/test/ThreadLocalTest`.

The problem is that the to the shared lib used in the test is hardcoded. It's a relative path, so that's nice, but it has too many assumptions about where the build system deposits test binaries.

Instead, let the code simply look for the shared lib in the same directory as the test binary. This makes fewer assumptions on the build system.

Reviewed By: andriigrynenko

Differential Revision: D2689047

fb-gh-sync-id: 648da079b7af5bc9893709d009e577347dd4a463

8 years agoFix HHWheelTimerTest.AtMostEveryN
Haijun Zhu [Mon, 23 Nov 2015 22:25:47 +0000 (14:25 -0800)]
Fix HHWheelTimerTest.AtMostEveryN

Summary: If it takes too long to finish it is probably heavily loaded. Skip if
so.

Reviewed By: mmcduff

Differential Revision: D2687346

fb-gh-sync-id: 282cac7e4df361f714de1089f11b098af79b1512

8 years agoSimplify an exception handler
Chad Parry [Mon, 23 Nov 2015 20:00:54 +0000 (12:00 -0800)]
Simplify an exception handler

Summary: It looks like there is no reason to catch a `std::exception` and then `dynamic_cast` to a derived exception. We can just catch the derived exception directly.

whatcouldgowrong4

Reviewed By: yfeldblum

Differential Revision: D2677284

fb-gh-sync-id: 0149e4d4aecc96257376d410f592620205441f66

8 years agoBenchmark std::to_string vs. folly::to<std::string>
Michael Oliver [Mon, 23 Nov 2015 19:50:20 +0000 (11:50 -0800)]
Benchmark std::to_string vs. folly::to<std::string>

Summary: We wanted to compare the benefits of using folly::to<std::string> directly, and decided this benchmarking might as well be contributed back to folly.  Here are the results:

```
  ============================================================================
  folly/test/ConvTest.cpp                         relative  time/iter  iters/s
  ============================================================================
  ...
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1)                                  157.88ns    6.33M
  u64ToStringFollyMeasure(1)                       212.52%    74.29ns   13.46M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12)                                 158.14ns    6.32M
  u64ToStringFollyMeasure(12)                      212.55%    74.40ns   13.44M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123)                                152.26ns    6.57M
  u64ToStringFollyMeasure(123)                     210.95%    72.18ns   13.85M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234)                               152.40ns    6.56M
  u64ToStringFollyMeasure(1234)                    204.82%    74.41ns   13.44M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345)                              156.01ns    6.41M
  u64ToStringFollyMeasure(12345)                   208.90%    74.68ns   13.39M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123456)                             178.21ns    5.61M
  u64ToStringFollyMeasure(123456)                  238.77%    74.63ns   13.40M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234567)                            161.38ns    6.20M
  u64ToStringFollyMeasure(1234567)                 203.09%    79.46ns   12.58M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345678)                           159.01ns    6.29M
  u64ToStringFollyMeasure(12345678)                192.42%    82.64ns   12.10M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123456789)                          169.07ns    5.91M
  u64ToStringFollyMeasure(123456789)               203.70%    83.00ns   12.05M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234567890)                         166.56ns    6.00M
  u64ToStringFollyMeasure(1234567890)              187.21%    88.97ns   11.24M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345678901)                        176.22ns    5.67M
  u64ToStringFollyMeasure(12345678901)             197.57%    89.20ns   11.21M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123456789012)                       174.74ns    5.72M
  u64ToStringFollyMeasure(123456789012)            182.52%    95.74ns   10.45M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234567890123)                      178.47ns    5.60M
  u64ToStringFollyMeasure(1234567890123)           186.81%    95.54ns   10.47M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345678901234)                     187.33ns    5.34M
  u64ToStringFollyMeasure(12345678901234)          184.05%   101.78ns    9.82M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123456789012345)                    198.16ns    5.05M
  u64ToStringFollyMeasure(123456789012345)         182.48%   108.59ns    9.21M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234567890123456)                   182.56ns    5.48M
  u64ToStringFollyMeasure(1234567890123456)        164.19%   111.19ns    8.99M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345678901234567)                  186.80ns    5.35M
  u64ToStringFollyMeasure(12345678901234567)       162.33%   115.07ns    8.69M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(123456789012345678)                 195.08ns    5.13M
  u64ToStringFollyMeasure(123456789012345678)      165.51%   117.87ns    8.48M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(1234567890123456789)                200.27ns    4.99M
  u64ToStringFollyMeasure(1234567890123456789)     164.62%   121.65ns    8.22M
  ----------------------------------------------------------------------------
  u64ToStringClibMeasure(12345678901234567890U)              203.18ns    4.92M
  u64ToStringFollyMeasure(12345678901234567890U)   162.38%   125.13ns    7.99M
  ----------------------------------------------------------------------------
  ...
  ============================================================================
```

Reviewed By: yfeldblum

Differential Revision: D2680998

fb-gh-sync-id: 179fbd756c714c92b7230d3750af024865ecbb0a

8 years agoAdd missing header files to folly-automake
Sara Golemon [Mon, 23 Nov 2015 19:40:18 +0000 (11:40 -0800)]
Add missing header files to folly-automake

Summary: Closes https://github.com/facebook/folly/issues/304

Reviewed By: yfeldblum

Differential Revision: D2685289

fb-gh-sync-id: 563697fb01ee358472b9080058848d2b557ba466

8 years agoFix minor typo in folly/Conv.h
Sara Golemon [Mon, 23 Nov 2015 19:39:26 +0000 (11:39 -0800)]
Fix minor typo in folly/Conv.h

Summary: 'flating point' => 'floating point'

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

Reviewed By: yfeldblum

Differential Revision: D2685280

fb-gh-sync-id: 2e9c2b5419d0c631af4a32c5ab6b7366033ca34c

8 years agoFix folly/ThreadLocal with clang after PthreadKeyUnregister change
Andrii Grynenko [Sat, 21 Nov 2015 05:25:11 +0000 (21:25 -0800)]
Fix folly/ThreadLocal with clang after PthreadKeyUnregister change

Summary: Make PthreadKeyUnregister a global singleton for all StaticMeta instances.

Reviewed By: luciang

Differential Revision: D2678401

fb-gh-sync-id: c0d58b483fa6f096b29aeb7df71897a75ea8c892

8 years agoRevert "Fix folly::ThreadLocal to work in a shared library"
Lucian Grijincu [Fri, 20 Nov 2015 20:03:52 +0000 (12:03 -0800)]
Revert "Fix folly::ThreadLocal to work in a shared library"

Summary: This reverts commit 9d355f96c4fe073c889f28070d5952fa4eb007a0.

build-break

Reviewed By: sctaylor

Differential Revision: D2680784

fb-gh-sync-id: a2df233bcd3721ffbfcd6fd71ea3cabbebebd4c4

8 years agoget back AsyncServerSocket's setMaxNumMessagesInQueue
Haijun Zhu [Fri, 20 Nov 2015 18:20:54 +0000 (10:20 -0800)]
get back AsyncServerSocket's setMaxNumMessagesInQueue

Summary: D2613681 codemod'ed a thrift server api but it also renamed that api
in AsyncServerSocket, which is a mistake. Fix that in AsyncServerSocket, and
all other places that calls this api.

Reviewed By: alandau, JoelMarcey

Differential Revision: D2677837

fb-gh-sync-id: 0d91f1a623229e99be59ca9dcd27f1330a9a1b64

8 years agoRemove unnecessary resetClientHelloParsing callback in AsyncSSLSocket
Anirudh Ramachandran [Fri, 20 Nov 2015 16:35:40 +0000 (08:35 -0800)]
Remove unnecessary resetClientHelloParsing callback in AsyncSSLSocket

Summary: Remove unnecessary resetClientHelloParsing callback which causes problems wiht
Openssl 1.0.2

Reviewed By: knekritz

Differential Revision: D2664730

fb-gh-sync-id: d1b55ae493b4c92627ad41e7bf85f1e1a777bd2b

8 years agoRemove busy wait and support multiple wait
Alexander Shaposhnikov [Fri, 20 Nov 2015 04:12:41 +0000 (20:12 -0800)]
Remove busy wait and support multiple wait

Summary: Remove busy wait from Future::wait.
If future.wait(timeout) has succeded we should
return a ready future, otherwise we should return a future
for the final result (not necessarily ready).

Reviewed By: yfeldblum

Differential Revision: D2646860

fb-gh-sync-id: 62671d09073ad86e84df8c9257e961d2a8c2a339

8 years agoExpose move result from LockFreeRingBuffer::Cursor
Delyan Kratunov [Fri, 20 Nov 2015 00:25:09 +0000 (16:25 -0800)]
Expose move result from LockFreeRingBuffer::Cursor

Summary: Without feedback that a `moveForward` or `moveBackward` did nothing, a user
cannot implement this idiom safely:

```
while(rb.tryRead(entry, cursor)) {
  doSomething(entry);
  cursor.moveBackward();
}
```

In the case where the ring buffer has not overflowed and slot 0 is still
available, the reader will get stuck at it (read it continuously) until
the buffer overflows.

This diff allows the above example to become:

```
while(rb.tryRead(entry, cursor)) {
  doSomething(etnry);
  if (!cursor.moveBackward()) {
    break;
  }
}
```

Reviewed By: bryceredd

Differential Revision: D2674975

fb-gh-sync-id: a0c5857daf186ef19e203f90acc2145590f85c3b

8 years agoFix usingJEMalloc with Clang
Giuseppe Ottaviano [Thu, 19 Nov 2015 19:39:27 +0000 (11:39 -0800)]
Fix usingJEMalloc with Clang

Summary: Clang is too clever and in some contexts optimizes away the `malloc`, but we rely on a side-effect. Declaring the variable as static forces it to call `malloc`. We could free the pointer relying on the fact that the lambda is guaranteed to be called only once, but I feel more comfortable just leaking it (LSan won't complain).

Reviewed By: philippv

Differential Revision: D2674769

fb-gh-sync-id: 1153a3ca226c6b7aa64c453bd61b036dcbf3ffcc

8 years agoFix invalid DCHECK
Anton Likhtarov [Thu, 19 Nov 2015 19:32:26 +0000 (11:32 -0800)]
Fix invalid DCHECK

Summary: There's a race between insert() and erase(): as soon as insert()
releases the lock (swaps kLockedKey_ with the actual key), an erase() might
jump in and invalidate the key.

As far as I can tell, this bug existed since the beginning.

Reviewed By: nbronson

Differential Revision: D2673099

fb-gh-sync-id: 4721893d2ad4836e11acc0fb4ecb0dd7b2b69be1

8 years agoFix folly::ThreadLocal to work in a shared library
Andrii Grynenko [Thu, 19 Nov 2015 19:30:20 +0000 (11:30 -0800)]
Fix folly::ThreadLocal to work in a shared library

Reviewed By: bmaurer

Differential Revision: D2667499

fb-gh-sync-id: 463f86752240bd88761910de934ba25d6e62fafe

8 years agoAdd getUnderlyingTransport to AsyncTransportWrapper.
Kyle Nekritz [Wed, 18 Nov 2015 18:20:14 +0000 (10:20 -0800)]
Add getUnderlyingTransport to AsyncTransportWrapper.

Summary: Inspired by getSocketFromTransport from proxygen.

Reviewed By: siyengar

Differential Revision: D2663937

fb-gh-sync-id: f076215907cd06d6da3de033c57eec8a6a6ce320

8 years agoUTF8StringPiece, wrapping boost::u8_to_u32
Tom Jackson [Tue, 17 Nov 2015 19:01:28 +0000 (11:01 -0800)]
UTF8StringPiece, wrapping boost::u8_to_u32

Summary: For handling UTF8 strings better.

Reviewed By: yfeldblum

Differential Revision: D1956771

fb-gh-sync-id: e074f9f2c9b472f5e619fef25d8e17296847773c

8 years agoSimplify some checks by using __CLANG_PREREQ
Yedidya Feldblum [Mon, 16 Nov 2015 10:07:19 +0000 (02:07 -0800)]
Simplify some checks by using __CLANG_PREREQ

Summary: [Folly] Simplify some checks by using `__CLANG_PREREQ`.

Reviewed By: meyering

Differential Revision: D2657979

fb-gh-sync-id: 80ff56bbab0e78465d71315b729ad14a09706ed5

8 years agoSimplify some checks by using __CLANG_PREREQ
Yedidya Feldblum [Sun, 15 Nov 2015 19:52:43 +0000 (11:52 -0800)]
Simplify some checks by using __CLANG_PREREQ

Summary: [Folly] Simplify some checks by using `__CLANG_PREREQ`.

Reviewed By: meyering

Differential Revision: D2656842

fb-gh-sync-id: e762fba423fb7cc08907d10dc10f8f46d93a9fe4

8 years agoMake collect work for types with no default constructors
Andrii Grynenko [Fri, 13 Nov 2015 21:47:27 +0000 (13:47 -0800)]
Make collect work for types with no default constructors

Summary: This doesn't make the code less efficient, because RVO can't be used for CollectVariadicContext. Thus moving existing tuple vs constructing new tuple by moving all values from other tuple (where each value is wrapped in folly::Optional) should be pretty much the same.

Reviewed By: hannesr

Differential Revision: D2650293

fb-gh-sync-id: 648a358bf093a0bb9d058a997af9bf59014ad77c

8 years agoAllow a AsyncSocket to be corked the whole time
Yang Chi [Thu, 12 Nov 2015 23:34:45 +0000 (15:34 -0800)]
Allow a AsyncSocket to be corked the whole time

Summary: Add a new method to cork a socket in a persistent manner, instead of the current on-off manner. This is default to false. The liger part of turning this on will be in a separate diff.

I thought about whether I need to turn cork off based on some criteria to alleviate the perf degradation. The obvious things I can think off is just amount of data written as a threshold, or a timeout. But TCP is doing this already for us, unless we want the data threshold to be less than MSS, or we want the timeout to be less than 200ms. THoughts?

Reviewed By: shikong

Differential Revision: D2639260

fb-gh-sync-id: 2821f669c9f72d5ac4c33195bb192fc4110ffe9d

8 years agoMake Malloc.h self-contained
Giuseppe Ottaviano [Thu, 12 Nov 2015 16:37:48 +0000 (08:37 -0800)]
Make Malloc.h self-contained

Reviewed By: philippv

Differential Revision: D2643313

fb-gh-sync-id: 10b9f735725ce47fab4bbfaa5972b3863357365f

8 years agoDisable assertions in FBString when used as std::string
Giuseppe Ottaviano [Thu, 12 Nov 2015 16:37:14 +0000 (08:37 -0800)]
Disable assertions in FBString when used as std::string

Reviewed By: Gownta

Differential Revision: D2643850

fb-gh-sync-id: 2c4bb844ea2006215b0637cb1ba08c636faefe05

8 years agoRestore the definition of HHWheelTimer::UniquePtr
Chad Parry [Thu, 12 Nov 2015 00:02:35 +0000 (16:02 -0800)]
Restore the definition of HHWheelTimer::UniquePtr

Summary: Changing the definition of `HHWheelTimer::UniquePtr` wasn't safe, because some clients were using that type outside of the `HHWheelTimer::newTimer` helper. I'm changing that part back. We'll still be able to proceed with my other codemod to `HHWheelTimer`, but we'll always have two different smart pointer types to manage: `UniquePtr` and `IntrusivePtr`.

Reviewed By: djwatson

Differential Revision: D2644721

fb-gh-sync-id: 14685be62355f09d39c4139ef7186d60b5f48dcd

8 years agoMake Optional nothrow_default_constructible
Stepan Palamarchuk [Wed, 11 Nov 2015 22:22:01 +0000 (14:22 -0800)]
Make Optional nothrow_default_constructible

Summary: It never throws.

Reviewed By: pavlo-fb

Differential Revision: D2640886

fb-gh-sync-id: cd643f8847f4bf5619415731484f91fb07116784

8 years agoAdd a buffer callback to AsyncSocket
Yang Chi [Wed, 11 Nov 2015 21:32:04 +0000 (13:32 -0800)]
Add a buffer callback to AsyncSocket

Summary: This is probably easier than D2612490. The idea is just to add a callback to write, writev and writeChain in AsyncSocket, so upper layer can know when data starts to buffer up

Reviewed By: mzlee

Differential Revision: D2623385

fb-gh-sync-id: 98d32ca83871aaa4f6c75a769b5f1bf0b5d62c3e

8 years agoImprove the DelayedDestruction smart pointer
Chad Parry [Wed, 11 Nov 2015 19:29:28 +0000 (11:29 -0800)]
Improve the DelayedDestruction smart pointer

Summary: There have been several ASAN bugs cropping up because the lifetime of an `HHWheelTimer` is not being manager properly. I think that people are too comfortable passing around a raw `HHWheelTimer*` even when it is difficult to prove correctness. The recommended solution used to be to create a `DestructorGuard` every time it was needed. There is enough friction there that not everyone is doing that like they should. We should make resource management easier---as easy as using raw pointers, in fact.

I've fixed the broken copy semantics of `DestructorGuard` and added the operators that allow it to be used as a smart pointer. I added the `IntrusivePtr` helper that can manage an arbitrary derived class of `DelayedDestructionBase`. Now, clients can all safely pass around an `IntrusivePtr` everywhere they used to use a raw pointer. They will get automatic resource management for free.

If you are not convinced that `DestructorGuard` should be changed, then note that the existing behavior is dangerously buggy. Consider the following innocent code that accidentally uses the implicitly-defined copy constructor:
  auto d = DestructorGuard(p);
This results in undefined behavior, because `p` can be accessed after it is destroyed! The bug happens because the default copy constructor copies the raw pointer but doesn't increment the count.

In a separate diff, I'll change all clients who pass around a raw `HHWheelTimer*` to use an `IntrusivePtr<HHWheelTimer>` instead. Then we can even entertain a long-term plan of switching from intrusive pointers to the standard `shared_ptr`.

Reviewed By: djwatson

Differential Revision: D2627941

fb-gh-sync-id: 58a934d64540d0bbab334adc4f23d31d507692da

8 years agoUNSYNCHRONIZED does NOT unlock the mutex
Shaft Wu [Wed, 11 Nov 2015 04:40:17 +0000 (20:40 -0800)]
UNSYNCHRONIZED does NOT unlock the mutex

Summary: My colleague tuomaspelkonen discovered a weird UNSYNCHRONIZED issue a few weeks ago and we ever since stopped using it. Now I finally have some time to root cause it. It turns out UNSYNCHRONIZED unlock the mutex then lock the mutex again, because it copy constructs LockedPtr for overriding the name within the scope, and copy construct locks the mutex again. A one character fix here is to take a reference of LockedPtr instead of copy construct it. However since this is my first time look at the code here, please advise if this is horribly wrong or propose better fix. Also added a test to reproduce the issue without the fix as well as verify the fix.

Reviewed By: yfeldblum

Differential Revision: D2633028

fb-gh-sync-id: a9e8d39b08d4d1265979f8bdaae83619566d10a0

8 years agoRevert my change (which broke down the cont build)
Alexander Shaposhnikov [Wed, 11 Nov 2015 03:11:56 +0000 (19:11 -0800)]
Revert my change (which broke down the cont build)

Summary: hg backout -r c9f7b5f3185a
Revert my change (which broke down the cont build t9048692)

Reviewed By: djwatson

Differential Revision: D2640797

fb-gh-sync-id: 51f196ac5a3560fde4dc8fe7bb6ef278d74136e5

8 years agoRemove busy wait
Alexander Shaposhnikov [Tue, 10 Nov 2015 23:42:18 +0000 (15:42 -0800)]
Remove busy wait

Summary: Wait uses baton & callback running baton.post
when the original future is ready. However wrapping baton.post
with a funciton call (preparing a new value) adds the following race: baton.wait wakes up
before that function has call actually finished.
The explanation is the following: to prepare the value of the new future it's necessary
1. baton.post() 2. set the value (move constructor, memory operations, ...)
and this code is executed in a separate thread.
The main idea of this fix is to avoid creating a new future
(whose value is calculated using that 2-step procedure)
and set a callback instead. This callback will be executed when the future is ready and actually
it either will be the last step of promise.setValue or it will run immediately if the future
we are waiting for already contains a value.

Reviewed By: fugalh

Differential Revision: D2636409

fb-gh-sync-id: df3e9bbcc56a5fac5834ffecc63f1bcb94ace02c

8 years agochange log error back to check when pipe read fail in notification queue
Shijin Kong [Tue, 10 Nov 2015 23:06:52 +0000 (15:06 -0800)]
change log error back to check when pipe read fail in notification queue

Summary: Revert D2632752

Reviewed By: afrind

Differential Revision: D2638974

fb-gh-sync-id: 43d8135421510db7840a99f3c197119a0fd26c09

8 years agoFBString: fix constructors so it compiles with newer Clang's
Steve O'Brien [Tue, 10 Nov 2015 14:28:14 +0000 (06:28 -0800)]
FBString: fix constructors so it compiles with newer Clang's

Summary: Using Clang 3.7, this minimal test program:

  #include <folly/FBString.h>
  struct S { folly::basic_fbstring<char> x; };
  int main(int argc, char *argv[]) {
    S s {};
    return 0;
  }

... breaks with the following error output:

  FBStringTest.cpp:5:8: error: chosen constructor is explicit in copy-initialization
    S s {};
         ^
  ./folly/FBString.h:1009:12: note: constructor declared here
    explicit basic_fbstring(const A& = A()) noexcept {
             ^
  FBStringTest.cpp:3:40: note: in implicit initialization of field 'x' with omitted initializer
  struct S { folly::basic_fbstring<char> x; };

... because this `basic_fbstring` is used in a struct and the struct is being default-constructed.

This patch splits the (nevertheless-correct) one-default-arg constructor into two, to deconfuse clang and have it select the correct constructor to avoid this issue.

Reviewed By: matbd

Differential Revision: D2632953

fb-gh-sync-id: 2c75ae85732678c31543f5cccc73d58317982f07

8 years agochange CHECK to LOG(ERROR) when pipe read error on NotificationQueue
Shijin Kong [Mon, 9 Nov 2015 21:09:58 +0000 (13:09 -0800)]
change CHECK to LOG(ERROR) when pipe read error on NotificationQueue

Summary: The check was originally added to track down cpu pinning issue. In reality the check did get triggered, so change to soft error to calm the crazy nag bot. what's wrong with you.
We need to see the soft error log to find out what the error is.

Reviewed By: mzlee

Differential Revision: D2632752

fb-gh-sync-id: 87c11b186f97f0eb4a6c5ac13a1117b280198673

8 years agoAdd a tag type for in-place construction
Alexey Spiridonov [Mon, 9 Nov 2015 19:16:11 +0000 (11:16 -0800)]
Add a tag type for in-place construction

Summary: Without this tag type, it's impossible to use `Synchronized` with types like:

```
struct A {
  A(int, const char*);
  A(const A&) = delete;
  A& operator=(const A&) = delete;
  A(A&&) = delete;
  A& operator=(A&&) = delete;
};
```

In-place construction solves this problem. Usage:

```
Synchronized a(construct_in_place, 5, "c");
```

Reviewed By: nbronson

Differential Revision: D2610071

fb-gh-sync-id: 251fe8f8f6a2d7484dda64cf04dcacb998145230

8 years agoMake sure there are no outstanding timers in the destructor
Chad Parry [Mon, 9 Nov 2015 18:39:22 +0000 (10:39 -0800)]
Make sure there are no outstanding timers in the destructor

Summary: This is the solution for our `HHWheelTimer` crashes, as suggested in D2617966#25.

djwatson also mentioned that maybe there should be some logging in the destructor if there are outstanding callbacks. I couldn't think of anything that would add to the `assert` that already exists in `destroy`. I'm open to suggestions though.

Reviewed By: djwatson

Differential Revision: D2628154

fb-gh-sync-id: f3db6e9384517c9bf3cbb60af8c1e711703a07fa

8 years agofolly/portability: add clang version check
Igor Sugak [Sun, 8 Nov 2015 08:32:52 +0000 (00:32 -0800)]
folly/portability: add clang version check

Summary: Define `__CLANG_PREREQ` macro to check version of clang.

Reviewed By: yfeldblum

Differential Revision: D2630325

fb-gh-sync-id: 3d666e554e8ddfc2c1fecd439aaf93f015829025

8 years agoCallbacks should ref the HHWheelTimer
Chad Parry [Fri, 6 Nov 2015 19:52:10 +0000 (11:52 -0800)]
Callbacks should ref the HHWheelTimer

Summary: Callbacks sometimes outlive the `HHWheelTimer` that they reference. Then the `Callback` tries to reference the dead `HHWheelTimer` and it could either misbehave or crash. This was caught reliably by ASAN tests.

Since `HHWheelTimer` already supports intrusive ref counting, the solution is to acquire a reference within the `Callback`.

Reviewed By: djwatson

Differential Revision: D2617966

fb-gh-sync-id: 02be9ffc5851c269d5933288a17ad394b33ac2dd

8 years agoCancel timeout only if not run
Jon Maltiel Swenson [Fri, 6 Nov 2015 02:54:38 +0000 (18:54 -0800)]
Cancel timeout only if not run

Summary: Do not cancel TimeoutHandler timeout if the timeout has already run.

Reviewed By: spalamarchuk

Differential Revision: D2622280

fb-gh-sync-id: 27d83b44ab225e2859695f4e5f21cef934824a35

8 years agocodemod setMaxNumMessagesInQueue to setMaxNumPendingConnectionsPerWorker
Haijun Zhu [Thu, 5 Nov 2015 18:36:46 +0000 (10:36 -0800)]
codemod setMaxNumMessagesInQueue to setMaxNumPendingConnectionsPerWorker

Summary: This name's meaning is very obscure, this method actually sets the
queue size of each acceptor and if all acceptor's queues are full the
connection will be dropped. Change it to a more meaningful name.

Reviewed By: alandau

Differential Revision: D2613681

fb-gh-sync-id: baa374cdf0a87c460df3dd5687e3d755b55f4b4f

8 years agoActivate server timeout after write success
Jon Maltiel Swenson [Thu, 5 Nov 2015 15:24:16 +0000 (07:24 -0800)]
Activate server timeout after write success

Summary: Start server timeout after socket write succeeds in mcrouter.  Add neceessary Fibers logic to enable this behavior.

Reviewed By: pavlo-fb

Differential Revision: D2613344

fb-gh-sync-id: 1bc0fbe8b325a3e91cd010f89104b83ebf183679

8 years agoSet interrupt handler correctly on SharedPromise
Viswanath Sivakumar [Thu, 5 Nov 2015 11:48:26 +0000 (03:48 -0800)]
Set interrupt handler correctly on SharedPromise

Summary: If SharedPromise::getFuture() is invoked after a call to setInterruptHandler,
then the interrupt handler isn't set on the newly created promise. This diff
fixes that.

Reviewed By: yfeldblum

Differential Revision: D2610289

fb-gh-sync-id: bf8fce9e881b83ccac17d13c6788ec2afd0b0153

8 years agoAdd ability to get application protocol from AsyncTransportWrapper
Subodh Iyengar [Wed, 4 Nov 2015 05:38:07 +0000 (21:38 -0800)]
Add ability to get application protocol from AsyncTransportWrapper

Summary: Allows AsyncTransportWrapper's to supply the underlying application
protocol being used, for example using NPN for SSL or some other
generic protocol indication mechanism.

Reviewed By: ranjeeth

Differential Revision: D2614179

fb-gh-sync-id: 2079782bb7d44f898fb14c7df15077209b022424

8 years agoswitch the IndexType and Allocator in AtomicUnorderedInsertMap template
Zhen (Growth) Li [Wed, 4 Nov 2015 01:31:55 +0000 (17:31 -0800)]
switch the IndexType and Allocator in AtomicUnorderedInsertMap template

Summary: Our use case need to have the IndexType Configurable, but in this diff D2583752, lint error shows
  Code from folly::detail is logically private, please avoid use outside of folly.
In order to fix this lint error, I switch the IndexType and Allocator in the AtomicUnorderedInsertMap template.

Reviewed By: nbronson

Differential Revision: D2610921

fb-gh-sync-id: ae81b41e7c8c971f26c61b8c67dabeadff379584

8 years agoAllow underlying transport to be accessible from AsyncTransportWrapper
Subodh Iyengar [Wed, 4 Nov 2015 01:19:40 +0000 (17:19 -0800)]
Allow underlying transport to be accessible from AsyncTransportWrapper

Summary: Allow underlying transport to be accessible from AsyncTransportWrapper.
There are some code paths where we need access to the real transport from
the AsyncTransportWrapper. This allows us to retrieve the underlying transport
and have clients like HTTPSession use it.

Reviewed By: afrind

Differential Revision: D2609200

fb-gh-sync-id: 2b317d1825a005bb64468f83c64bc3f1c9bdfe2c

8 years agomake folly slightly more c++-modules friendly
Louis Brandy [Wed, 4 Nov 2015 01:13:54 +0000 (17:13 -0800)]
make folly slightly more c++-modules friendly

Summary: .. by including what you use.

These are a handful of headers that are depended on via viral inclusion. Include them directly.

Reviewed By: yfeldblum

Differential Revision: D2601172

fb-gh-sync-id: 215e87263325d085fbcb651f83f429f47d14fc1b

8 years agoqualify std::move in StringKeyedTest
Louis Brandy [Tue, 3 Nov 2015 20:30:27 +0000 (12:30 -0800)]
qualify std::move in StringKeyedTest

Summary: Prefer `std::move` to `move` for clarity's sake.

Reviewed By: yfeldblum

Differential Revision: D2601138

fb-gh-sync-id: 64a9e58a83da9c8416a0be5c45a292c6b1342664

8 years agoDisallow nullptr literal in StringPiece constructor
Anton Likhtarov [Tue, 3 Nov 2015 18:45:21 +0000 (10:45 -0800)]
Disallow nullptr literal in StringPiece constructor

Summary: This disallows implicitly constructing a StringPiece from a literal nullptr at compile time
(without this change, nullptr would cause a segfault in strlen()).

Reviewed By: meyering, andriigrynenko

Differential Revision: D2603597

fb-gh-sync-id: cafbc45945bacc72a7c89310b99aa62d19a3ff9f

8 years agoFix multi-line comment warnings
Andrew Gallagher [Sat, 31 Oct 2015 21:42:53 +0000 (14:42 -0700)]
Fix multi-line comment warnings

Summary: Fix warnings triggered by `-Wcomment`.

Reviewed By: ajtulloch

Differential Revision: D2603992

fb-gh-sync-id: aae721f7c236d7d8b8bff2c077a481fc2affcf71

8 years agoAdd writeAndGetCursor to LockFreeRingBuffer
Delyan Kratunov [Fri, 30 Oct 2015 21:59:54 +0000 (14:59 -0700)]
Add writeAndGetCursor to LockFreeRingBuffer

Summary: New API - write an entry and advance a cursor to the just-written slot.

Reviewed By: ritzau, yfeldblum

Differential Revision: D2599388

fb-gh-sync-id: f3ebfae97de0341f01ffc80ab10221313d02087c

8 years agoPeriodically reclaim unnecessary fibers from free pool
Jon Maltiel Swenson [Fri, 30 Oct 2015 00:16:08 +0000 (17:16 -0700)]
Periodically reclaim unnecessary fibers from free pool

Summary: Reclaim unnecessary fibers from the free pool periodically.  Turn this behavior
on in mcrouter/proxy.cpp

Reviewed By: pavlo-fb

Differential Revision: D2584825

fb-gh-sync-id: eabc58eefe6fd38972c9e23ca3cbe79eb8316a3e

8 years agoPrefer template aliases to classes in IntrusiveList
Justin Gibbs [Thu, 29 Oct 2015 21:35:22 +0000 (14:35 -0700)]
Prefer template aliases to classes in IntrusiveList

Summary: Convert helper classes to using statements now that GCC has caught up
with c++11.

Reviewed By: simpkins

Differential Revision: D2561364

fb-gh-sync-id: 712591549aba9450d159468dc3b26a987ffe9b82

8 years agoRemove DFATAL from folly::Singleton::try_get()
Andrii Grynenko [Thu, 29 Oct 2015 21:33:02 +0000 (14:33 -0700)]
Remove DFATAL from folly::Singleton::try_get()

Summary: try_get() API is confusing right now, because it returns nullptr in release, but crashes in debug build. Users end up handling nullptr returns, yet their code crashes in debug builds for no reason. See https://www.facebook.com/groups/fbthrift/permalink/1222120054481561/ for an example.

If we want to keep the crashing API we should probably name it differently and make it crash both in debug and release.

Reviewed By: dhruvbird

Differential Revision: D2587818

fb-gh-sync-id: 5834bfa08eb5d9bc6db1c5edf4a048a5b1d3212c

8 years agoadd config to allow using quadratic probing
Xiaofan Yang [Thu, 29 Oct 2015 19:27:58 +0000 (12:27 -0700)]
add config to allow using quadratic probing

Summary: In my use case, 1.5 billion keys with loadFactor 0.8, the linear probing performs really bad.

Reviewed By: nbronson

Differential Revision: D2579243

fb-gh-sync-id: 5081356de55f770823a4afad55bf7e2114b4e313

8 years agoDo not set startWork_ in EventBase if time measurement is disabled
Pavlo Kushnir [Thu, 29 Oct 2015 00:15:19 +0000 (17:15 -0700)]
Do not set startWork_ in EventBase if time measurement is disabled

Summary: startWork_ is used only if enableTimeMeasurement is set. It gives ~0.5% performance win for mcrouter.

Reviewed By: yfeldblum

Differential Revision: D2590176

fb-gh-sync-id: 07f2189ebdec751cd0d91d191d8f595780d2808a

8 years agoSuppress -Wshadow for SYNCHRONIZED
Blake Matheny [Wed, 28 Oct 2015 18:07:40 +0000 (11:07 -0700)]
Suppress -Wshadow for SYNCHRONIZED

Summary: SYNCHRONIZED warns with -Wshadow due to `for (auto&
FB_ARG_1(__VA_ARGS__) =`. This diff just suppresses that warning.

Reviewed By: djwatson

Differential Revision: D2587348

fb-gh-sync-id: 3a2e39fb6ce28da014950ca94e4b62ea80deb65f

8 years agoFix clang issue on NotificationQueue::size
Beny Luo [Wed, 28 Oct 2015 00:41:18 +0000 (17:41 -0700)]
Fix clang issue on NotificationQueue::size

Summary: The implicit conversion loses integer precision: 'size_type' (aka 'unsigned
long') to 'int'.

Reviewed By: mzlee

Differential Revision: D2585883

fb-gh-sync-id: 1fc7c84b66c8f19cc36b798dd198730764e19b28

8 years agoTrack callback life cycle for HHWheelTimer and EventBase
Shaft Wu [Tue, 27 Oct 2015 04:14:10 +0000 (21:14 -0700)]
Track callback life cycle for HHWheelTimer and EventBase

Summary: Further race is presented in HHWheelTimer and EventBase, since changing them to track callback life cycle is more involving, I am hacking around it to prove the concept. With the *fix*, no reproduce of the segmentation fault anymore.

This is for proving the concept, code will be cleaned up if we agree this is reasonable direction to pursue.

Reviewed By: fugalh

Differential Revision: D2577715

fb-gh-sync-id: e0bb0317268e6f02a54fc70454e63959fba70c10

8 years agoExpose pending messages in queue stats in AsyncServerSocket
Jun Li [Tue, 27 Oct 2015 00:40:17 +0000 (17:40 -0700)]
Expose pending messages in queue stats in AsyncServerSocket

Summary: Expose pending messages in accept queue in AsyncServerSocket.

Set default accept message queue size to 1024.

Reviewed By: djwatson

Differential Revision: D2525161

fb-gh-sync-id: a69ea0ee77729e4a8300bde3e3c07840f2d5d3cb

8 years agofolly: hash: specialize hash_combine_generic by size_t size
Lucian Grijincu [Mon, 26 Oct 2015 22:50:26 +0000 (15:50 -0700)]
folly: hash: specialize hash_combine_generic by size_t size

Reviewed By: yangliu

Differential Revision: D2578043

fb-gh-sync-id: cec8f21219655a495b99d0b6b99f0925615bc068

8 years agoAdd new toBinary() function to IPAddress.
Florent Thoumie [Mon, 26 Oct 2015 21:53:03 +0000 (14:53 -0700)]
Add new toBinary() function to IPAddress.

Summary: This is pretty much the reverse operation from the fromBinary() constructor.

Reviewed By: yfeldblum

Differential Revision: D2578680

fb-gh-sync-id: d8c4e53fe8bc0f5373ebb0b4f7ee498659c1b003

8 years agoStyle nits for folly/test/FingerprintBenchmark.cpp
Yedidya Feldblum [Mon, 26 Oct 2015 19:09:38 +0000 (12:09 -0700)]
Style nits for folly/test/FingerprintBenchmark.cpp

Summary: [Folly] Style nits for `folly/test/FingerprintBenchmark.cpp`.

Reviewed By: Gownta

Differential Revision: D2579463

fb-gh-sync-id: 135bc3ef43708cb024f78c59672811159d2163e0

8 years agoRename two callback function names of ConnectionEventCallback
Mohammad Husain [Mon, 26 Oct 2015 18:56:02 +0000 (11:56 -0700)]
Rename two callback function names of ConnectionEventCallback

Summary: Renaming `EnqueuedForAccept` and `DequeuedByAccept` to
`EnqueuedForAcceptor` and `DequeuedByAcceptor` respectively to make it clear
that the connection is queued for the Acceptor not to call `accept` on.

Reviewed By: yfeldblum

Differential Revision: D2554578

fb-gh-sync-id: 072a9ff122658827d1e89f2bef79ad565dad7974

8 years agoreturn read error on non EAGAIN errno
Shijin Kong [Mon, 26 Oct 2015 17:15:45 +0000 (10:15 -0700)]
return read error on non EAGAIN errno

Summary: Tested over weekend with D2571554. There was no EXC_RESOURCE/CPU crash when read errrors were returned on ENOTCONN. EAGAIN seems innocent as the spin detector was disabled on testing group.

Patch folly. I can add #ifdef __APPLE__ around the errno checking code but this should be good practice for non apple code as well.

I will remove debugging code in fbios master in another diff.

Reviewed By: djwatson

Differential Revision: D2580819

fb-gh-sync-id: 9162a3deba01af8b07cd2b336d7da3da040c67a9

8 years agofix AtomicUnorderedInsertMap load factor computation
Nathan Bronson [Sat, 24 Oct 2015 02:48:25 +0000 (19:48 -0700)]
fix AtomicUnorderedInsertMap load factor computation

Summary: AtomicUnorderedInsertMap's constructor takes a maxLoadFactor argument,
which is given its default argument of 0.8f in all of our code.
The clipping function that was supposed to prevent load factors
greater than one was inverted, resulting in all of our code using a
maxLoadFactor of 1 instead of 0.8.  This diff fixes the computation,
as well as changing all of the use sites so that the actual memory
allocated by existing clients does not change.

Reviewed By: yfeldblum

Differential Revision: D2575238

fb-gh-sync-id: bb9dd8de53114236b259631d175d62af098391cf

8 years agoFibers allocation/deallocation benchmarks
Jon Maltiel Swenson [Fri, 23 Oct 2015 21:44:22 +0000 (14:44 -0700)]
Fibers allocation/deallocation benchmarks

Summary: Add a couple benchmarks measuring allocation/deallocation latency.  One benchmark measures an allocate-deallocate repeated pattern, the other measures the allocation of a large chunk of fibers.

We'll use these benchmarks later on after we modify the allocation/deallocation behavior of fibers.

Reviewed By: pavlo-fb

Differential Revision: D2573064

fb-gh-sync-id: 414eb93d6223e42c187c03214a47dfb533491bab

8 years agoOption to fallback to double when int precision is not enough.
Bartosz Nitka [Fri, 23 Oct 2015 18:42:05 +0000 (11:42 -0700)]
Option to fallback to double when int precision is not enough.

Summary: Some libraries like Haskell's `Data.Aeson` can produce arbitrarily
big numbers with arbitrary precision.
The json standard doesn't specify the ranges for numeric types.
For interoperability, we should allow the user to parse the numbers with
some loss of precision.

Reviewed By: luciang

Differential Revision: D2565140

fb-gh-sync-id: b1a9a46e298bf13cc89d7e79ce28705e9e251a7f

8 years agotemplatize AtomicUnorderedInsertMap's internals to allow big maps
Nathan Bronson [Fri, 23 Oct 2015 14:23:37 +0000 (07:23 -0700)]
templatize AtomicUnorderedInsertMap's internals to allow big maps

Summary: AtomicUnorderedInsertMap used 32 bit index values internally.  2 bits
were stolen, limiting the capacity to 2^30.  This diff makes the internal
index type a template parameter, so you can make really big maps if you
want (at the expense of bigger map overhead).  The easiest way is to
substitute AtomicUnorderedInsertMap64.

Reviewed By: yfeldblum

Differential Revision: D2574338

fb-gh-sync-id: a74994b6da1046a149c2e7763c3dc19e35d9840b

8 years agoFix infinite loop in Cursor::readTerminatedString
Alan Frindell [Thu, 22 Oct 2015 20:12:58 +0000 (13:12 -0700)]
Fix infinite loop in Cursor::readTerminatedString

Summary: readTerminatedString could infinite loop if the terminator does not appear in the contained IOBuf chain and maxLength > chain.computeChainLength.  I'm throwing out_of_range here because that more closely mirrors what the other read() functions do.

Reviewed By: siyengar

Differential Revision: D2571039

fb-gh-sync-id: 1db22089562d8767920d66a0a1b091b02de6571f

8 years agoClang support for constexpr StringPiece constructor
Giuseppe Ottaviano [Thu, 22 Oct 2015 19:11:59 +0000 (12:11 -0700)]
Clang support for constexpr StringPiece constructor

Summary: Clang's `strlen` is not `constexpr`, but `__builtin_strlen` is, so we can have an unconditional `constexpr` `StringPiece` constructor.

Reviewed By: luciang, yfeldblum

Differential Revision: D2561782

fb-gh-sync-id: 51e76a0d50355cc5ead1148ba2389b640a6888de

8 years agoFix gcc 5.2 compilation when _GLIBCXX_USE_CXX11_ABI is not 0
Yaacov Akiba Slama [Thu, 22 Oct 2015 05:30:22 +0000 (22:30 -0700)]
Fix gcc 5.2 compilation when _GLIBCXX_USE_CXX11_ABI is not 0

Summary: Tested in debian stretch when used in hhvm which can now run drupal 7.
The compilation error is also fixed by #214 but this fix maintains
 forward declarations of basic_string and list.
Closes https://github.com/facebook/folly/pull/329

Reviewed By: yfeldblum

Differential Revision: D2533880

fb-gh-sync-id: 85e18eeeba9efa1b4150217ba526b32b5573e15e

8 years agofix "iocb" reporting in AsyncIO
Philip Pronin [Wed, 21 Oct 2015 19:02:38 +0000 (12:02 -0700)]
fix "iocb" reporting in AsyncIO

Summary: A few fields were swapped, and we had unintentionall fallthrough in
switch.

Reviewed By: luciang

Differential Revision: D2565884

fb-gh-sync-id: 8ad71c090c5120e99c672f785aaefdef03469ee2

8 years agoMove FingerprintBenchmark to Folly
Rameshkumar Shihora [Wed, 21 Oct 2015 18:31:52 +0000 (11:31 -0700)]
Move FingerprintBenchmark to Folly

Summary: FingerprintBenchmark was in an internal directory before, but it belongs alongside the Fingerprint code.

Reviewed By: yfeldblum

Differential Revision: D2534646

fb-gh-sync-id: d8ded3a5a9d33f60e9674ea71dc87a2d8d19a51b

8 years agoImprove folly::Singleton try_get perf and bring back raw get benchmark
Andrii Grynenko [Wed, 21 Oct 2015 02:34:57 +0000 (19:34 -0700)]
Improve folly::Singleton try_get perf and bring back raw get benchmark

Reviewed By: elsteveogrande

Differential Revision: D2517522

fb-gh-sync-id: eab11d17ce5db94e09aa733b6067e44d36be6345

8 years agoAdd support for in-place creation of NotificationQueue::Consumer
Petr Lapukhov [Tue, 20 Oct 2015 22:30:55 +0000 (15:30 -0700)]
Add support for in-place creation of NotificationQueue::Consumer

Summary: as title, this comes handy when multiple consumers are needed
within the same class.

Reviewed By: has

Differential Revision: D2530249

fb-gh-sync-id: 942761782a100b2d3fe54d94a7c1b0e03b95a847

8 years agoAdd getIPv6For6To4 to IPAddressV4
Emil Hesslow [Tue, 20 Oct 2015 21:52:07 +0000 (14:52 -0700)]
Add getIPv6For6To4 to IPAddressV4

Summary: - I added this in PHP ( D2534138 ) so add it here too
- This is my first folly diff so I probably done something wrong :)

Reviewed By: yfeldblum

Differential Revision: D2549168

fb-gh-sync-id: 5e6a80097be01fb54342e0c9da5b69465f695f80

8 years agoBring zstd support into folly/io/Compression.h
Jon Maltiel Swenson [Tue, 20 Oct 2015 03:18:30 +0000 (20:18 -0700)]
Bring zstd support into folly/io/Compression.h

Summary: Bring zstd support into folly/io/Compression.h

Reviewed By: chipturner

Differential Revision: D2551026

fb-gh-sync-id: 7c13338d45efb0fc19f0b44015c7e62d945a483b

8 years agoRemove boost dependency from folly/ProducerConsumerQueue.h
Bruno Goncalves [Sat, 17 Oct 2015 02:03:22 +0000 (19:03 -0700)]
Remove boost dependency from folly/ProducerConsumerQueue.h

Summary: Boost is great, but c++11 incorporate some of their stuffs, and classes like ProducerConsumerQueue don't need it anymore.
Closes https://github.com/facebook/folly/pull/321

Reviewed By: fredemmott, yfeldblum

Differential Revision: D2519081

fb-gh-sync-id: b138a5af4662d1e7ef5e0823cf4001880ee02456

8 years agoChange NotificationQueue assert -> CHECK
Ranjeeth Dasineni [Sat, 17 Oct 2015 00:22:49 +0000 (17:22 -0700)]
Change NotificationQueue assert -> CHECK

Summary: If the eventFd goes bad, NotificationQueue consumers can cause their event loop to spin indefinitely.  If libevent gets POLLERR on the fd, it calls handlerReady, which triggers a read.  The read will fail, but the callback is never uninstalled.  I'm not sure it would be easy to recover gracefully from this, so crash hard instead.

Reviewed By: yfeldblum, pgriess

Differential Revision: D2550270

fb-gh-sync-id: c9575fbda778b3625da6d9db6b0542b8263f230a

8 years agoCommiting missing header file change from D2408773
Kyle Nekritz [Fri, 16 Oct 2015 22:57:07 +0000 (15:57 -0700)]
Commiting missing header file change from D2408773

Summary: AsyncSSLSocket.h change was not synced from D2408773 /
f7176051f816980a985beeb9b8a907dddd0dc0e3.

Test Plan: file matches D2408773

Reviewers:

CC:

Task ID: #

Blame Rev:

8 years agofix initializer order bug in MemoryIdler
Nathan Bronson [Fri, 16 Oct 2015 21:27:11 +0000 (14:27 -0700)]
fix initializer order bug in MemoryIdler

Summary: Make sure page size has been fetched from the operating system
before it is used in asserts.

Reviewed By: meyering

Differential Revision: D2551368

fb-gh-sync-id: d3735571e2a45f613bbbd7e0f158a755d36b376c

8 years agoAvoid the ODR issue with ThreadLocalDetail's kInvalid
Yedidya Feldblum [Fri, 16 Oct 2015 19:46:00 +0000 (12:46 -0700)]
Avoid the ODR issue with ThreadLocalDetail's kInvalid

Summary: [Folly] Avoid the ODR issue with `ThreadLocalDetail`'s `kInvalid`.

The problem is that it is a `static constexpr` class member, so pull it out of the class.

Reviewed By: bmaurer

Differential Revision: D2549272

fb-gh-sync-id: 28a73e73b9cf9f21bee2bba2125513c02ef56ce2

8 years agoReverting D2503151 to unbreak buck build
Madhu Ramanathan [Fri, 16 Oct 2015 18:07:24 +0000 (11:07 -0700)]
Reverting D2503151 to unbreak buck build

Summary: This breaks buck build. Reverting till the fix is in to unblock build pipeline.

Reviewed By: jmswen

Differential Revision: D2550685

fb-gh-sync-id: 7623e6c7fcaad70d7d207ec10a59f7381c72cebc

8 years agoBring ZSTD support into folly/io/Compression.h
Jon Maltiel Swenson [Fri, 16 Oct 2015 16:42:43 +0000 (09:42 -0700)]
Bring ZSTD support into folly/io/Compression.h

Summary: Bring ZSTD support into folly/io/Compression.h

Reviewed By: chipturner

Differential Revision: D2503151

fb-gh-sync-id: c1450cecc8197db654b7a080a63753caa666f686

8 years agoMissed some derivation from boost::noncopyable after deleting the .hpp header.
Aaron Roth [Fri, 16 Oct 2015 14:54:02 +0000 (07:54 -0700)]
Missed some derivation from boost::noncopyable after deleting the .hpp header.

Summary: There remained some derivations from boost::noncopyable in inner classes after boost/noncopyable.hpp was deleted in D2459355. Get rid of these two.

Reviewed By: meyering

Differential Revision: D2485930

fb-gh-sync-id: 89546490b15fa4279debf4b9cabcf48d3dc336bb

8 years agoAdd connection event callback to AsyncServerSocket
Mohammad Husain [Fri, 16 Oct 2015 04:13:25 +0000 (21:13 -0700)]
Add connection event callback to AsyncServerSocket

Summary: Adding a callback to AsyncServerSocket to get notified of client connection events. This can be used for example to record stats about these events.

Reviewed By: @afrind

Differential Revision: D2544776

fb-gh-sync-id: 20d22cfc939c5b937abec2b600c10b7228923ff3

8 years agofolly: Symbolizer: don't colorize TERM="dumb" or TERM="" or TERM-undefined TTYs
Lucian Grijincu [Fri, 16 Oct 2015 03:04:34 +0000 (20:04 -0700)]
folly: Symbolizer: don't colorize TERM="dumb" or TERM="" or TERM-undefined TTYs

Reviewed By: @dcolascione

Differential Revision: D2548486

fb-gh-sync-id: 6e2d7e84598eb5b05aba7a262b7c53532337dbe3

8 years agofolly: Symbolizer: don't allocate from function which is supposed to be signal safe
Lucian Grijincu [Fri, 16 Oct 2015 02:17:30 +0000 (19:17 -0700)]
folly: Symbolizer: don't allocate from function which is supposed to be signal safe

Reviewed By: @philippv, @dcolascione

Differential Revision: D2548023

fb-gh-sync-id: d2b0571d5db03e38ed17a5de6a13d2194a05b2b9

8 years agoSpecialize and implement setThreadName only on some platforms
Yedidya Feldblum [Fri, 16 Oct 2015 01:55:27 +0000 (18:55 -0700)]
Specialize and implement setThreadName only on some platforms

Summary: [Folly] Specialize and implement `setThreadName` only on some platforms.

With this technique, we can compile setThreadName and programs that call it on MSVC/Windows and on other platforms that don't have the underlying pthread call.

This is an alternative to: https://reviews.facebook.net/D46317.

Reviewed By: @nbronson

Differential Revision: D2535593

fb-gh-sync-id: 09d26f53e3fe69b49326b5b6492a7d59f86db2e8

8 years agoundefined reference to 'folly::threadlocal_detail::StaticMeta<void>::EntryID::kInvalid'
Jody Ho [Fri, 16 Oct 2015 01:51:01 +0000 (18:51 -0700)]
undefined reference to 'folly::threadlocal_detail::StaticMeta<void>::EntryID::kInvalid'

Summary: In some cases, folly::threadlocal_detail::StaticMeta<void>::EntryID::kInvalid
is odr-used, a definition at the namespace scope is required even though it has
been initialized with a brace-or-equal initializer.

See http://en.cppreference.com/w/cpp/language/static

Reviewed By: @yfeldblum

Differential Revision: D2548668

fb-gh-sync-id: 9cd6d7b2f37d1481d1adbf4f0a2d9e66631efd15

8 years agoAdd framework for switching certs based on signature_algorithms TLS extension.
Kyle Nekritz [Thu, 15 Oct 2015 15:19:48 +0000 (08:19 -0700)]
Add framework for switching certs based on signature_algorithms TLS extension.

Summary: Added support for switching SSLContexts based on the signature_algorithms
extension.
This diff does not currently include any logic for determining which certs use
SHA1 or not.

Some thoughts:
- This is a little scary since it defaults to SHA1 (assuming the client can't support
SHA256 if we don't see SHA256 specifically in the hello extension). We need to
be 100% sure that all clients that are going to reject SHA1 are sending this,
and that we identify it correctly.
- We should add logging to see when we think a client needs SHA1, when we
actually give SHA1, etc. I'm not sure what the best way to do this is with our
logging infrastructure.
- This is not setup to serve any SHA1 certs to SHA256 supporting clients.

Reviewed By: @siyengar

Differential Revision: D2408773

fb-gh-sync-id: 48ad9cdfaae25e144c0964b9bfb1c342b137ffca

8 years agoFix Build: under GCC 4.9 + ASAN, RangeSse42.cpp fails to build
Yedidya Feldblum [Thu, 15 Oct 2015 05:39:59 +0000 (22:39 -0700)]
Fix Build: under GCC 4.9 + ASAN, RangeSse42.cpp fails to build

Summary: [Folly] Fix Build: under GCC 4.9 + ASAN, `RangeSse42.cpp` fails to build.

Reviewed By: @ldemailly, @meyering

Differential Revision: D2544284

fb-gh-sync-id: fd50f8b326252291ad3a5d9fe956e7e647ad0133

8 years agoAdd handshake and connect times
Subodh Iyengar [Thu, 15 Oct 2015 05:03:26 +0000 (22:03 -0700)]
Add handshake and connect times

Summary: Add api to get time taken to establish
connections and to complete handshake
for clients using AsyncSocket directly.

Reviewed By: @afrind

Differential Revision: D2435074

fb-gh-sync-id: f44c336e62c426736eb5b3d88dd57a18572382e8

8 years agoEphemeral ciphers in false start list
Subodh Iyengar [Thu, 15 Oct 2015 05:01:55 +0000 (22:01 -0700)]
Ephemeral ciphers in false start list

Summary: Only include ephemeral ciphers in false start list.

Reviewed By: @​mzlee

Differential Revision: D2429447

fb-gh-sync-id: 430d287a93249ff72b9ebe7db3bc283bb0712600