folly.git
7 years agoUse the socket portability layer when needed. v2016.08.08.00
Christopher Dykes [Fri, 5 Aug 2016 22:16:29 +0000 (15:16 -0700)]
Use the socket portability layer when needed.

Summary: This switches the places in Folly that need to explicitly reference the socket portability implementation to do exactly that.

Reviewed By: yfeldblum

Differential Revision: D3299984

fbshipit-source-id: 57cd8ebe66c9055aba66581a8c0fcf6c125d96f9

7 years agoUpper level tests
Dave Watson [Fri, 5 Aug 2016 19:45:58 +0000 (12:45 -0700)]
Upper level tests

Summary:
Add some tests to test the other levels of the timer wheel.

They are slow by necessity.

Reviewed By: yfeldblum

Differential Revision: D3637132

fbshipit-source-id: badf8d37d726dbeb5a8220d50c60b8efdaee7989

7 years agoremove catchupEveryN
Dave Watson [Fri, 5 Aug 2016 19:15:19 +0000 (12:15 -0700)]
remove catchupEveryN

Summary: This feature doesn't make sense when wheeltimer doesn't constantly tick - we always have to get the current clock time.  On the plus side, we'll only be grabbing the clock on timer schedule or timeout, never for individual ticks.

Reviewed By: yfeldblum

Differential Revision: D3637088

fbshipit-source-id: ed8fe52419259332a14b6dc1d357979dcf258a20

7 years agoHandle creating the default crypto context if it doesn't already exist
Christopher Dykes [Fri, 5 Aug 2016 16:49:03 +0000 (09:49 -0700)]
Handle creating the default crypto context if it doesn't already exist

Summary: It's perfectly possible that the default crypto context simply hasn't been created yet, so try to create it if the initial acquisition fails.

Reviewed By: yfeldblum

Differential Revision: D3673138

fbshipit-source-id: 122955df04055ff4f99513b182375d4388dd0305

7 years agoDon't throw in the Watchdog destructor
Christopher Dykes [Fri, 5 Aug 2016 16:48:30 +0000 (09:48 -0700)]
Don't throw in the Watchdog destructor

Summary: As-of C++11, destructors are assumed to be `noexcept` unless explicitly marked otherwise. `Watchdog`'s destructor throws, so switch it to a `LOG(FATAL)` instead.

Reviewed By: andriigrynenko

Differential Revision: D3672621

fbshipit-source-id: 5224ecf85d101462e02e12da257e033bab4db1a1

7 years agoAdding policies for all the upgrade and downgrade mutex transitions that are going...
Aaryaman Sagar [Fri, 5 Aug 2016 03:05:35 +0000 (20:05 -0700)]
Adding policies for all the upgrade and downgrade mutex transitions that are going to be supported by Synchronized

Summary:
This diff contains the lock policies that will be used by Synchronized to
implement mutex transitions by means of heterogenous RAII mutex wrappers

Reviewed By: yfeldblum

Differential Revision: D3665020

fbshipit-source-id: a5509dfd58a1dd6cd60a7d3afe929d0da860926d

7 years agoAdding support for upgradable mutexes to LockTraits
Aaryaman Sagar [Fri, 5 Aug 2016 00:14:45 +0000 (17:14 -0700)]
Adding support for upgradable mutexes to LockTraits

Summary:
This diff adds support for upgradable mutexes to the LockTraits
abstraction used by folly::Synchronized

Reviewed By: yfeldblum

Differential Revision: D3645453

fbshipit-source-id: 30f16eb3fbebc687a4136256f1103962c0e4c465

7 years agoUse std::max_align_t rather than __attribute__((__aligned__)) to get max alignment
Christopher Dykes [Thu, 4 Aug 2016 23:32:18 +0000 (16:32 -0700)]
Use std::max_align_t rather than __attribute__((__aligned__)) to get max alignment

Summary: Because the former is standardized, and the latter is a syntax error under MSVC.

Reviewed By: yfeldblum

Differential Revision: D3672667

fbshipit-source-id: c0149b11367e36ba5574625240c41a167348199f

7 years agoCreate trace points for thread events
Melanie Subbiah [Thu, 4 Aug 2016 23:09:23 +0000 (16:09 -0700)]
Create trace points for thread events

Summary: RequestContext update.

Reviewed By: mibpl

Differential Revision: D3604937

fbshipit-source-id: 07b315fe22a6dba40f0bab53c8092f35c172ae85

7 years agoDon't attempt to mmap an anonymous shared piece of memory
Christopher Dykes [Thu, 4 Aug 2016 23:00:55 +0000 (16:00 -0700)]
Don't attempt to mmap an anonymous shared piece of memory

Summary: The portability implementation of `mmap` for Windows doesn't currently support anonymous shared allocations, as they are non-trivial to manage, and the places this is being used doesn't actually need the memory to be allocated as shared, so allocate it as private instead.

Reviewed By: yfeldblum

Differential Revision: D3671495

fbshipit-source-id: e74d4fd925363fef16c1bf8445da1ff32bf8266d

7 years agoUse std::thread rather than pthreads in AtomicHashMapTest
Christopher Dykes [Thu, 4 Aug 2016 23:00:27 +0000 (16:00 -0700)]
Use std::thread rather than pthreads in AtomicHashMapTest

Summary: The tests aren't dependent on it being pthread, so use standardized stuff instead.

Reviewed By: yfeldblum

Differential Revision: D3665698

fbshipit-source-id: ad91facb75a9c5d7a90bfa294cc98bb07629de1b

7 years agoFix compilation errors when attempting to compile Folly without WIN32_LEAN_AND_MEAN...
Christopher Dykes [Thu, 4 Aug 2016 22:49:36 +0000 (15:49 -0700)]
Fix compilation errors when attempting to compile Folly without WIN32_LEAN_AND_MEAN defined

Summary: Without `WIN32_LEAN_AND_MEAN` defined, including `Windows.h` includes a massive number of extra headers. There are situations that need things that are defined in those headers, so keep folly working even when it isn't defined.

Reviewed By: yfeldblum

Differential Revision: D3671350

fbshipit-source-id: 0de986e17cdd4be386be8a9eeb0075b4af44024d

7 years agoAdd a couple more things to the socket portability layer
Christopher Dykes [Thu, 4 Aug 2016 22:44:27 +0000 (15:44 -0700)]
Add a couple more things to the socket portability layer

Summary: To make it possible for things to actually compile, this adds `socketpair` and the `sockaddr_un` struct, and also removes the `FOLLY_HAVE_UNIX_SOCKETS` define, as it is no longer needed.

Reviewed By: yfeldblum

Differential Revision: D3671158

fbshipit-source-id: 7333470f2e85c24edb935be5e1b94b4edc6e7267

7 years agoDisable the use of direct TLS in ThreadLocalDetail under MSVC
Christopher Dykes [Thu, 4 Aug 2016 22:40:29 +0000 (15:40 -0700)]
Disable the use of direct TLS in ThreadLocalDetail under MSVC

Summary: The comment tells the truth: StaticMeta doesn't mix well with MSVC's TLS implementation.

Reviewed By: yfeldblum

Differential Revision: D3671274

fbshipit-source-id: 293eb32699ad5cee59965f24f985ec7099c90136

7 years agoFix a pair of non-ascii quotes that made their way into AsyncSocket
Christopher Dykes [Thu, 4 Aug 2016 22:40:16 +0000 (15:40 -0700)]
Fix a pair of non-ascii quotes that made their way into AsyncSocket

Summary: Because the lint error was annoying me.

Reviewed By: yfeldblum

Differential Revision: D3671252

fbshipit-source-id: 2962db7616077f531e64c6f2b26ad708c7adf6ed

7 years agoEliminate the atomic porability header's dependence on Windows.h
Christopher Dykes [Thu, 4 Aug 2016 22:38:29 +0000 (15:38 -0700)]
Eliminate the atomic porability header's dependence on Windows.h

Summary:
This is done by using the intrinsic directly instead.
This also marks the input parameter as `volatile`, to make it more clear that that's how it is handled by `_InterlockedExchangeAdd64`.

Reviewed By: yfeldblum

Differential Revision: D3671320

fbshipit-source-id: 6010085ec3b6952a3eb1e952965ec6ad87566db2

7 years agoDon't assume boost::path contains narrow characters
Christopher Dykes [Thu, 4 Aug 2016 22:38:00 +0000 (15:38 -0700)]
Don't assume boost::path contains narrow characters

Summary: Because it contains `wchar_t`'s on Windows.

Reviewed By: yfeldblum

Differential Revision: D3672098

fbshipit-source-id: b49db642dedf48bf7379cf339130c93f52a22f9a

7 years agoDon't try to ignore the SIGPIPE signal if it isn't defined
Christopher Dykes [Thu, 4 Aug 2016 22:37:49 +0000 (15:37 -0700)]
Don't try to ignore the SIGPIPE signal if it isn't defined

Summary: Which is the case when compiling under MSVC.

Reviewed By: pixelb

Differential Revision: D3671357

fbshipit-source-id: b7e51479cae44933c3f1caa21d45775a32f294a3

7 years agoAssume p is not nullptr in storeUnaligned
Christopher Dykes [Thu, 4 Aug 2016 22:05:50 +0000 (15:05 -0700)]
Assume p is not nullptr in storeUnaligned

Summary:
Because we're constructing the value with a placement new, which has some of C++'s most unhelpful behavior ever put into the spec: If `p` is `nullptr` and we are not compiling in C++14 mode, where the restriction was changed, then the placement new will do absolutely nothing at all. By adding the assumption that `p` is not `nullptr`, we'll trip a segfault in release mode rather than failing silently.
Note that MSVC would generate the nullptr check regardless of which mode it's in, so this assume forces the removal of the check.

Reviewed By: yfeldblum

Differential Revision: D3651116

fbshipit-source-id: ee15a38f85ce4e3cb3186fda0b7bcca39acda27a

7 years agoRequestContext::create should call onUnset callback
Mirek Klimos [Thu, 4 Aug 2016 19:09:50 +0000 (12:09 -0700)]
RequestContext::create should call onUnset callback

Summary: melaniesubbiah introduced onSet / onUnset callbacks on RequestData in D3604948; we need unset() to be called when an RC is overriden with RequestContext::create() so that things work as expected. Also, change the order of calling onSet / onUnset - from RequestData perspective, it shouldn't look like there are two contexts set at the same time

Reviewed By: palmtenor

Differential Revision: D3667017

fbshipit-source-id: b9bfb858fe65ffb11de8e6d6f13b8f4cf6266bc9

7 years agoInclude the fcntl.h portability header where it's needed
Christopher Dykes [Thu, 4 Aug 2016 17:50:19 +0000 (10:50 -0700)]
Include the fcntl.h portability header where it's needed

Summary: There are a few places that need this, so make it so.

Reviewed By: yfeldblum

Differential Revision: D3667234

fbshipit-source-id: 84c16e1b036d9c2afddf03aa84c43210c5672f0a

7 years agoSupport TimeUtil under MSVC
Christopher Dykes [Thu, 4 Aug 2016 17:49:23 +0000 (10:49 -0700)]
Support TimeUtil under MSVC

Summary: Well, make it compile anyways. There's no simple equivelant for Windows, so just return 0 instead.

Reviewed By: yfeldblum

Differential Revision: D3667474

fbshipit-source-id: 02224c6666dfcfdec237bfbbd4714170407a952a

7 years agoFix the Windows portability implementations of mmap and munmap
Christopher Dykes [Thu, 4 Aug 2016 17:48:08 +0000 (10:48 -0700)]
Fix the Windows portability implementations of mmap and munmap

Summary: Because they simply didn't work before.

Reviewed By: yfeldblum

Differential Revision: D3666894

fbshipit-source-id: 7a34073b2bbc43c489ad963c28fac24dcbb187f2

7 years agoFix Enumerate C++17 Support
Nick Terrell [Thu, 4 Aug 2016 00:53:52 +0000 (17:53 -0700)]
Fix Enumerate C++17 Support

Summary: `RangeEnumerator`s `begin()` and `end()` could return different values, but `Enumerator`s `operator ==` didn't support comparision with different types.

Reviewed By: yfeldblum

Differential Revision: D3662576

fbshipit-source-id: cfd10fffd220c70191ce0ac2ed78edd35daf5538

7 years agoDon't use a macro for no reason
Christopher Dykes [Thu, 4 Aug 2016 00:45:28 +0000 (17:45 -0700)]
Don't use a macro for no reason

Summary: There is no reason at all for this to be a macro, so get rid of the macro.

Reviewed By: igorsugak, yfeldblum

Differential Revision: D3666339

fbshipit-source-id: cf131fd4182fe89c5ce0c981edf9bd7fb46158a9

7 years agoDon't name a member small
Christopher Dykes [Thu, 4 Aug 2016 00:22:57 +0000 (17:22 -0700)]
Don't name a member small

Summary:
Because, if you aren't compiling with `WIN32_LEAN_AND_MEAN`, including `WinSock2.h` will result in `small` being `#define`'d as `char`. The best way to work around the issue is to simply change the name of the member to something else.
It would also have been possible to solve the problem by adding a section to `folly/portability/Windows.h`, but that would have required including that header in `folly/Function.h`, which there really is no reason to do.

Reviewed By: yfeldblum

Differential Revision: D3666417

fbshipit-source-id: 21c0363a4b77bb01e4ec20b2fc625c40729879c3

7 years agoFix the mode being used in the implementation of open in the Fcntl portability header
Christopher Dykes [Wed, 3 Aug 2016 22:09:29 +0000 (15:09 -0700)]
Fix the mode being used in the implementation of open in the Fcntl portability header

Summary: The mode parameter to `open` under MSVC is not the same as the mode parameter everywhere else, so we need to do a bit of translation.

Reviewed By: yfeldblum

Differential Revision: D3651218

fbshipit-source-id: 80df1e15f34b8d66533256107d8c9218f757fde2

7 years agoForce the overflow in BitVectorCoding::skipTo to be 64-bit
Christopher Dykes [Wed, 3 Aug 2016 22:09:04 +0000 (15:09 -0700)]
Force the overflow in BitVectorCoding::skipTo to be 64-bit

Summary: This code was relying on the `- 1` overflowing as a 64-bit value, but MSVC (correctly in my opinion) was overflowing this as a 32-bit value, resulting in a segfault when trying to run the bitvector and eliasfano tests on MSVC.

Reviewed By: yfeldblum

Differential Revision: D3652343

fbshipit-source-id: 38a22abfc0d05ab2f070c450eebfa69af07d26af

7 years agoUnset RequestContext properly in EventBase::runLoopCallbacks
Mirek Klimos [Wed, 3 Aug 2016 21:40:28 +0000 (14:40 -0700)]
Unset RequestContext properly in EventBase::runLoopCallbacks

Summary: We need to make sure RequestContext is unset properly for correct attribution of events to requests in BPF. djwatson, is there a reason not to set RequestContext when running runLoopCallbacks() from EventBase destructor?

Reviewed By: yfeldblum

Differential Revision: D3640289

fbshipit-source-id: bc48e936618adb1a1619de004b8479f58d3b683d

7 years agoAdded DiscriminatedPtr support to arm64
lpathy [Wed, 3 Aug 2016 21:13:44 +0000 (14:13 -0700)]
Added DiscriminatedPtr support to arm64

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

Reviewed By: mzlee

Differential Revision: D3649806

Pulled By: Orvid

fbshipit-source-id: 77288e0a1aedf15a18f558e18fbc1dc3a56e5fd6

7 years agoFix a typo in PicoSpinLock
Christopher Dykes [Wed, 3 Aug 2016 21:04:35 +0000 (14:04 -0700)]
Fix a typo in PicoSpinLock

Summary:
Because I fail at typing underscores apparently.
This also switches the shifts over to using `kLockBitMask_` instead, which was already defined for us.

Reviewed By: yfeldblum

Differential Revision: D3652483

fbshipit-source-id: 6bd527beeb90bea8ee7632c0a3bfbbb9e0a7e2e7

7 years agoAdd libfollytestmain.la to mallctl's LDADD
Alexander Stocko [Wed, 3 Aug 2016 20:16:12 +0000 (13:16 -0700)]
Add libfollytestmain.la to mallctl's LDADD

Summary:
Fixes make check problem for MallctlHelperTest.

Previous make check output:

MallctlHelperTest.o: In function `MallctlHelperTest_valid_read_Test::TestBody()':
MallctlHelperTest.cpp:(.text+0x25): undefined reference to `testing::internal::AlwaysTrue()'
MallctlHelperTest.cpp:(.text+0x2e): undefined reference to `testing::internal::AlwaysTrue()'
MallctlHelperTest.cpp:(.text+0x51): undefined reference to `testing::Message::Message()'
MallctlHelperTest.cpp:(.text+0x72): undefined reference to `testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)'
MallctlHelperTest.cpp:(.text+0x85): undefined reference to `testing::internal::AssertHelper::operator=(testing::Message const&) const'
MallctlHelperTest.cpp:(.text+0x91): undefined reference to `testing::internal::AssertHelper::~AssertHelper()'
MallctlHelperTest.cpp:(.text+0xe4): undefined reference to `testing::Message::Message()'
MallctlHelperTest.cpp:(.text+0x111): undefined reference to `testing::inte
Closes https://github.com/facebook/folly/pull/448

Reviewed By: yfeldblum

Differential Revision: D3659427

Pulled By: Orvid

fbshipit-source-id: c1445b881bbebdace4defc02024a5184fd821ed6

7 years agofolly AsyncPipeReader supports IOBuf
Yuri Putivsky [Wed, 3 Aug 2016 19:02:26 +0000 (12:02 -0700)]
folly AsyncPipeReader supports IOBuf

Summary: folly AsyncPipeReader takes a callback of type AsyncReader::ReadCallback. Now AsyncReader::ReadCallback class supports IOBuf as a buffer for transfer read bytes. Need to extend AsyncPipeReader class to support IOBuf as well

Reviewed By: yfeldblum

Differential Revision: D3650893

fbshipit-source-id: e2142341c8b8b0b2ef248c1f13a8caba9d50ba67

7 years agoTest of DeterministicSchedule support for global invariants and auxiliary vari
Maged Michael [Wed, 3 Aug 2016 00:23:18 +0000 (17:23 -0700)]
Test of DeterministicSchedule support for global invariants and auxiliary vari

Summary:
Depends on D3648146

Atomic counter test with:
- Buggy path triggered by an env var
- Auxiliary data
- A global invariant
- A function to be called with shared accesses to update auxiliary data and check the global invariant.

Reviewed By: djwatson

Differential Revision: D3648195

fbshipit-source-id: 18620a887f114abf31ba1261c38287139a1591a7

7 years agoFix compiler warnings
Gustavo Serra Scalet [Wed, 3 Aug 2016 00:04:52 +0000 (17:04 -0700)]
Fix compiler warnings

Summary:
- unused variables
- suppressing "warning: variable length array ‘vec’ is used [-Wvla]"
Closes https://github.com/facebook/folly/pull/443

Reviewed By: djwatson

Differential Revision: D3641928

Pulled By: Orvid

fbshipit-source-id: 0bd58a75f8948f28cc2d232c03bd443734d9657d

7 years agoDeterministicSchedule support for global invariants and auxiliary variables
Maged Michael [Tue, 2 Aug 2016 23:29:54 +0000 (16:29 -0700)]
DeterministicSchedule support for global invariants and auxiliary variables

Summary:
Support for user-defined auxiliary variables and global invariants.
- Add two fields to DSched:
  -- tls_aux: static FOLLY_TLS std::function<void(uint64_t, bool)>*. User-defined auxiliary function with parameters: count of synchronization steps, and boolean indicator of the success of the current step.
  -- step_: uint64_t. Count of shared accesses that correspond to user synchronization steps (atomic accesses for now).
- Add two static functions to DSched:
  -- void setAux(std::function<void(uint64_t, bool)>*).
  -- void callAux(bool success). Calls the aux function with the step count and the bool success argument.
- Add a version of afterSharedAccess(bool) that takes a bool success parameter and calls callAux(success). This version is used in every atomic operation of DeterministicAtomic.
- Add direct load interface to  DeterministicAtomic for use by auxiliary functions.

Note: This the base of a stacked diff with:
- Test the new capabilities in DeterministicScheduleTest.h
Next steps:
- Use the new capabilities to test dynamic MPMCQueue
Other possible additions:
- Change the implementation of DeterministicMutex to allow inspecting its internal state.
- Test the new capabilities for mutexes and semaphores in DeterministicScheduleTest.h
- Performance optimization: e.g., user-space context switching, using regular variables to implements atomics.

Reviewed By: djwatson

Differential Revision: D3648146

fbshipit-source-id: 4f838ff7cfd41ab71cfdf22bb67def3221948311

7 years agoUpdate folly/futures README
Sahil Jain [Tue, 2 Aug 2016 21:55:16 +0000 (14:55 -0700)]
Update folly/futures README

Summary: Regenerate README after updating dex_export.php

Reviewed By: fugalh

Differential Revision: D3654216

fbshipit-source-id: aaae04803c480e2ecaf9b3cb8794c8d8f7df560b

7 years agoEnsure getVia(eventbase) does not busy wait
Dave Watson [Tue, 2 Aug 2016 21:05:35 +0000 (14:05 -0700)]
Ensure getVia(eventbase) does not busy wait

Summary:
Currently, getVia(eventbase) will busy wait if no work is scheduled on the event base.

Tweak the DrivableExecutor API a bit to support sleeping/wakeups.
There was already a similar fix for the only other existing DrivableExecutor, the ManualExecutor, in
D2906858.

Reviewed By: andriigrynenko

Differential Revision: D3613954

fbshipit-source-id: 9ff9f2e010040d9886fdf51a665e3afabbff57c0

7 years agoreadFile to take in fd
Aravind Anbudurai [Tue, 2 Aug 2016 16:55:15 +0000 (09:55 -0700)]
readFile to take in fd

Summary:
I want to be able to read from an fd into an std::string and this diffs helps
with that.

Reviewed By: yfeldblum

Differential Revision: D3654709

fbshipit-source-id: d48e8001a50f90c66cbe5b4a3b536c7b0074c39d

7 years agofolly: remove template argument to std::abs to fix build with libc++
Igor Sugak [Tue, 2 Aug 2016 01:06:41 +0000 (18:06 -0700)]
folly: remove template argument to std::abs to fix build with libc++

Summary:
libc++ doesn't implement `std::abs` as template.

```lang=bash
./../folly/fibers/Fiber.h:68:34: error: unexpected type name 'intptr_t': expected
      expression
    const size_t size = std::abs<intptr_t>(
                                 ^
```

Reviewed By: markisaa

Differential Revision: D3645584

fbshipit-source-id: a2d672137f110b975412a94ae4c6d00da0bd0d43

7 years agoRemove the glog header include from Assume.h
Yedidya Feldblum [Mon, 1 Aug 2016 23:46:59 +0000 (16:46 -0700)]
Remove the glog header include from Assume.h

Summary:
[Folly] Remove the glog header include from `Assume.h`.

Better to avoid unnecessary includes.

Reviewed By: Orvid

Differential Revision: D3652651

fbshipit-source-id: 3fa6256e9571539c692b9c50c1c215b31eef394a

7 years agoFix the ffs builtins under MSVC
Christopher Dykes [Mon, 1 Aug 2016 22:26:51 +0000 (15:26 -0700)]
Fix the ffs builtins under MSVC

Summary: I was off by one in my implementation.

Reviewed By: yfeldblum

Differential Revision: D3651183

fbshipit-source-id: 4d6a6d08c06bce332a00088920bf604a10c942e7

7 years agoDon't disable the shadowing warning just for a parameter name
Christopher Dykes [Mon, 1 Aug 2016 22:13:39 +0000 (15:13 -0700)]
Don't disable the shadowing warning just for a parameter name

Summary: Just rename the parameter instead, it's not worth it.

Reviewed By: yfeldblum

Differential Revision: D3651065

fbshipit-source-id: ce11c35a7923ab7e10868cedb49c47c0b427fd0c

7 years agoFix nextPowTwo for 64-bit values under MSVC
Christopher Dykes [Mon, 1 Aug 2016 22:09:57 +0000 (15:09 -0700)]
Fix nextPowTwo for 64-bit values under MSVC

Summary: A `long` is only 32-bits on MSVC, so this is simply wrong. Shift a `T` left instead.

Reviewed By: yfeldblum

Differential Revision: D3651139

fbshipit-source-id: 3bbfd18ed0c372287c4ec6cbcc543f6f1fcc4139

7 years agoSwitch some assertions to std::thread rather than pthread
Christopher Dykes [Mon, 1 Aug 2016 20:17:30 +0000 (13:17 -0700)]
Switch some assertions to std::thread rather than pthread

Summary: Because the check macros attempt to pipe the values to the error stream, but we can't do that with the Windows implementation. Switch to `std::this_thread::get_id()` instead because it's standard and can be piped.

Reviewed By: djwatson

Differential Revision: D3650362

fbshipit-source-id: 8af65448a33949f310abc818d95bac843214b685

7 years agofix HHWheelTimer comment typo v2016.08.01.00
David Wilemski [Mon, 1 Aug 2016 15:47:36 +0000 (08:47 -0700)]
fix HHWheelTimer comment typo

Summary: Noticed this while reading the code.

Reviewed By: yfeldblum

Differential Revision: D3648565

fbshipit-source-id: c00940e5ce91fbc7e5cc6c42e35c5deee3e0bf65

7 years agoAdded initlist_construct_t tag for explicit initializer list
Aaryaman Sagar [Sat, 30 Jul 2016 03:30:00 +0000 (20:30 -0700)]
Added initlist_construct_t tag for explicit initializer list

Summary:
Initializer list construction can often have conflictingly similar
syntax as uniform initialization.  As a result APIs and classes often either
avoid using `std::initializer_list`s or deprecate construction with
`std::initializer_list`s.  This change provides a tag similar to
`std::piecewise_construct_t` to help out.

Reviewed By: simpkins

Differential Revision: D3617276

fbshipit-source-id: 3c74802f946a22e1a4ee52eca0f89df4a028eb22

7 years agoMore tests
Dave Watson [Fri, 29 Jul 2016 21:28:53 +0000 (14:28 -0700)]
More tests

Summary:
Test timers where we need to reschedule the wheel timer next tick.

This wasn't tested before, since we were always ticking, and never needed to reschedule.

Differential Revision: D3637103

fbshipit-source-id: cb80e7b790bb6aac68bdb5f60f8aa00caa2e5b69

7 years agoLimit symbol length in demangle()
Giuseppe Ottaviano [Fri, 29 Jul 2016 21:24:41 +0000 (14:24 -0700)]
Limit symbol length in demangle()

Summary:
GCC's `__cxa_demangle()` uses on-stack data structures for the parser
state which are linear in the number of components of the symbol. For
extremely long symbols, this can cause a stack overflow.

This diff introduces an arbitrary symbol length limit above which we
just return the mangled name.

Reviewed By: philippv

Differential Revision: D3641115

fbshipit-source-id: ec360bb20ca499fd0eaf3a06c5bbcbd1e936d845

7 years agoAdd a const getter for X509 used in handshake (server-side) v2016.07.29.00
Anirudh Ramachandran [Fri, 29 Jul 2016 19:20:33 +0000 (12:20 -0700)]
Add a const getter for X509 used in handshake (server-side)

Summary:
Similar to other getters such as getSSLCertSize, but returns a const X509*.
This may be useful to get cert parameters after handshake is complete
(or in error).

Reviewed By: yfeldblum

Differential Revision: D3636598

fbshipit-source-id: 98f0e2987de53d6343541ef0ed588f9ad18390cd

7 years agofix hhwheeltimertest
Dave Watson [Fri, 29 Jul 2016 18:28:50 +0000 (11:28 -0700)]
fix hhwheeltimertest

Summary:
Test doesn't match comments.  Remove extranous commented code.

I think there was actually a subtle bug in the test: since 25 doesn't evenly divide in to 6, we could end up farther away than we were expecting.  The same is true of 10/3, but it remains within the threshold.

Reviewed By: yfeldblum

Differential Revision: D3637078

fbshipit-source-id: d9881143c33c9b4f203f839e2e5106183301b530

7 years agofutures: fix behaviour when executors don't exec callback
Sven Over [Fri, 29 Jul 2016 11:45:35 +0000 (04:45 -0700)]
futures: fix behaviour when executors don't exec callback

Summary:
When future callbacks are to be executed by an executor (via `via`)
and the executor does not actually execute the callback function
(for whatever reason), then waiting for the final future (the one
returned by `via`) block forever. In case the callback function
that got passed to the executor gets destroyed without being executed,
the future should be set to a folly::BrokenPromise exception instead
of remaining unset forever.

This diff modifies the reference counting in folly::detail::Core
to make sure the reference held by the callback function is
properly removed not only after the callback gets executed, but
also when the callback is destroyed without having been executed.

Reviewed By: yfeldblum

Differential Revision: D3455931

fbshipit-source-id: debb6f3563384a658d1e0149a4aadbbcb268938c

7 years agofolly/experimental/test/FutureDAGTest.cpp: fix ASAN-detected heap use-after-free
Jim Meyering [Fri, 29 Jul 2016 03:01:21 +0000 (20:01 -0700)]
folly/experimental/test/FutureDAGTest.cpp: fix ASAN-detected heap use-after-free

Summary: Building/testing with ASAN would elicit a heap use-after-free.

Differential Revision: D3639117

fbshipit-source-id: 30b5fa7d3fe1d804c4fba5bada8197a3a05a8333

7 years agotakeOwnershipOfPipes method releases memory
Yuri Putivsky [Fri, 29 Jul 2016 02:19:25 +0000 (19:19 -0700)]
takeOwnershipOfPipes method releases memory

Summary: takeOwnershipOfPipes should left zero heap memory allocated in folly:Subprocess class instance.

Reviewed By: snarkmaster

Differential Revision: D3638503

fbshipit-source-id: aac7b10bd7399c44868f32c01164f4123892598f

7 years agoadd an unlock() method to Synchronized<T>::LockedPtr
Adam Simpkins [Wed, 27 Jul 2016 19:32:20 +0000 (12:32 -0700)]
add an unlock() method to Synchronized<T>::LockedPtr

Summary:
Add an unlock() method to Synchronized LockedPtr objects.  This will make it
easier to replace current users of the UNSYNCHRONIZED macro.

Of the handful of places currently using UNSYNCHRONIZED, many of them want to
simply release the lock before logging a message and returning.  However,
UNSYNCHRONIZED is a poor choice for this, since it will re-acquire the lock on
scope exit.  In these situations where the function returns from inside an
UNSYNCHRONIZED block the code unnecessarily re-acquires the lock just to
immediately release it.  The unlock() method will provide a cleaner mechanism
for these call sites to simply drop the lock early before returning.

Reviewed By: yfeldblum

Differential Revision: D3547652

fbshipit-source-id: 4d28fe9f3aad0d7348e918d1a3d6c705bfec242b

7 years agoDon't shift an int left while assigning it to a size_t
Christopher Dykes [Wed, 27 Jul 2016 19:21:19 +0000 (12:21 -0700)]
Don't shift an int left while assigning it to a size_t

Summary:
MSVC gives warnings if you shift a 32-bit value left but then assign it to a 64-bit variable. This just makes it a 64-bit shift instead.
If we really wanted, this doesn't need to be a size_t to begin with, but it already is, so just leave it alone.

Reviewed By: yfeldblum

Differential Revision: D3622935

fbshipit-source-id: 25931e6df644df8a2160aa80fd5de21cd9c06159

7 years agofolly: fix AtomicUnorderedMap compilation on macOS
Wez Furlong [Wed, 27 Jul 2016 04:07:55 +0000 (21:07 -0700)]
folly: fix AtomicUnorderedMap compilation on macOS

Summary:
MAP_POPULATE is not defined on this system.  Instead we will `madvise` the kernel
that we will need it so that it will populate the mapping.

Reviewed By: yfeldblum

Differential Revision: D3584325

fbshipit-source-id: ece52f3d55c475bcd41367f4e9744d6f41001cd5

7 years agoSupport PicoSpinLock on MSVC
Christopher Dykes [Tue, 26 Jul 2016 23:17:39 +0000 (16:17 -0700)]
Support PicoSpinLock on MSVC

Summary:
It was using inline assembly in order to get atomic single-bit operations, so add a variant for MSVC that uses intrinsics.
MSVC is also weird in-that it doesn't have a 16-bit variant of these, so use an atomic OR and AND to achieve the required effect.

Reviewed By: yfeldblum

Differential Revision: D3623220

fbshipit-source-id: b4ff985ef2ed7787115f4d20de6f244123410dc8

7 years agoConsistently reference an internal struct as a struct
Christopher Dykes [Tue, 26 Jul 2016 22:54:14 +0000 (15:54 -0700)]
Consistently reference an internal struct as a struct

Summary: That way the mismatch warning can stay as an error.

Reviewed By: yfeldblum

Differential Revision: D3613761

fbshipit-source-id: 6e0ee42c658d95786f578f6500aba113c00d8f77

7 years agoFix the weak linking of JEMalloc under MSVC
Christopher Dykes [Tue, 26 Jul 2016 22:53:34 +0000 (15:53 -0700)]
Fix the weak linking of JEMalloc under MSVC

Summary: While the previous version did compile, it wouldn't actually work at link time.

Reviewed By: meyering

Differential Revision: D3614424

fbshipit-source-id: 578677b65edca720330319594e1163d214e1400d

7 years agoDon't run the thread local tests requiring dlopen on Windows
Christopher Dykes [Tue, 26 Jul 2016 22:53:04 +0000 (15:53 -0700)]
Don't run the thread local tests requiring dlopen on Windows

Summary: When I initially added the surrounding `#ifdef` I failed at where I put my `#endif`, as I left the shared library test enabled. This disables it for Windows.

Reviewed By: yfeldblum

Differential Revision: D3622769

fbshipit-source-id: f263201239095bbef076300d5f40649ebee1173c

7 years agoGet MSVC able to construct an Indestructible
Christopher Dykes [Tue, 26 Jul 2016 22:52:25 +0000 (15:52 -0700)]
Get MSVC able to construct an Indestructible

Summary: It didn't like using `decltype(args)`, which wasn't really necessary as we already have it's type.

Reviewed By: yfeldblum

Differential Revision: D3623424

fbshipit-source-id: 994c23cbf486d427c6dd0fe4c6f768e51ea15ad1

7 years agoOnly try to use the membarrier on Linux
Christopher Dykes [Tue, 26 Jul 2016 22:52:13 +0000 (15:52 -0700)]
Only try to use the membarrier on Linux

Summary: It doesn't exist anywhere else, and `syscall` isn't even defined on Windows, so this completely failed to compile before.

Reviewed By: yfeldblum

Differential Revision: D3623382

fbshipit-source-id: 302093ddc96d6465e0dcc1883747229a7fb25a84

7 years agoAdd folly::assume_unreachable
Christopher Dykes [Tue, 26 Jul 2016 22:50:47 +0000 (15:50 -0700)]
Add folly::assume_unreachable

Summary: So that the `[[noreturn]]` attribute can be applied.

Reviewed By: yfeldblum

Differential Revision: D3614122

fbshipit-source-id: 4b95cb553e85c85c277c00b8165671dcc75afac8

7 years agoMake RangeEnumerator C++17 compliant (Generalizing the Range-Based For Loop)
Christopher Dykes [Tue, 26 Jul 2016 22:48:54 +0000 (15:48 -0700)]
Make RangeEnumerator C++17 compliant (Generalizing the Range-Based For Loop)

Summary:
Specifically the loosening of the definition of a range where-by the end of an iterator may be represented by a different type than the beginning of the range.
Oh, and it also fixes compilation on MSVC, which didn't like the decltype being used to determine the iterator type.

Reviewed By: yfeldblum

Differential Revision: D3613993

fbshipit-source-id: 2940a15d0f93c5b6310d0b1896f5d12ca9aec639

7 years agoAdd a dummy FlagSaver class.
Michael Lee [Tue, 26 Jul 2016 22:43:00 +0000 (15:43 -0700)]
Add a dummy FlagSaver class.

Summary: Add a declaration to mock out FlagSaver on platforms that don't support gflags.

Reviewed By: ivmaykov, yfeldblum

Differential Revision: D3620421

fbshipit-source-id: c1047f34f384f34276b18f53e966a65cdd5c8075

7 years agoSupport custom loop runner for EventBaseLoopController
Andrii Grynenko [Tue, 26 Jul 2016 21:45:42 +0000 (14:45 -0700)]
Support custom loop runner for EventBaseLoopController

Summary: This allows having some logic executed before and after FiberManager loop (e.g. grabbing a Python GIL).

Reviewed By: A5he

Differential Revision: D3616752

fbshipit-source-id: 3be35d54ced458328816d583133457a44a863acd

7 years agoA BufferCallback was created but never deleted in AsyncSocketTest2
Yang Chi [Tue, 26 Jul 2016 20:49:40 +0000 (13:49 -0700)]
A BufferCallback was created but never deleted in AsyncSocketTest2

Summary: This crashes unit test with asan, since we never deletes it.

Reviewed By: djwatson

Differential Revision: D3622847

fbshipit-source-id: f7ea7c4f464843353b24a59adefd5d66b95bc169

7 years agoNo need to go through the list when you just want the size
Yang Chi [Tue, 26 Jul 2016 20:45:01 +0000 (13:45 -0700)]
No need to go through the list when you just want the size

Summary: cb is an unused variable, and i got error in android. It seems like we don't need to go through the list to increase count.

Differential Revision: D3622772

fbshipit-source-id: fe1f81a1fcad5bacad052e14b7b0b370beb3f3e5

7 years agoHandle MSVC's preprocessor oddities in the SharedMutex test 2016.07.26
Christopher Dykes [Tue, 26 Jul 2016 15:37:22 +0000 (08:37 -0700)]
Handle MSVC's preprocessor oddities in the SharedMutex test

Summary: MSVC needs a bit more glue to expand the varargs.

Reviewed By: yfeldblum

Differential Revision: D3614681

fbshipit-source-id: 901d8c5138b1d2d28434c51bdff31f6d21f26681

7 years agoInclude sys/types.h portability header in Enumerate
Christopher Dykes [Tue, 26 Jul 2016 15:36:28 +0000 (08:36 -0700)]
Include sys/types.h portability header in Enumerate

Summary: Because it's using `ssize_t`, which MSVC defines weirdly.

Reviewed By: yfeldblum

Differential Revision: D3614050

fbshipit-source-id: 422621ea0dc92b374fa6dfc32a5391c1093d039e

7 years agoRefactor socket peeker
Neel Goyal [Tue, 26 Jul 2016 15:09:18 +0000 (08:09 -0700)]
Refactor socket peeker

Summary:
Refactor the socket peeker into its
own class so that it can be used in
other places as well, for example
for peeking at plaintext traffic.

Reviewed By: knekritz

Differential Revision: D3521899

fbshipit-source-id: fcd5615dd5d7cd1ddece4c624efbdecfbbc88a09

7 years agoFix gcpu regression associated with 1ms tick in HHWheelTimer
Misha Shneerson [Tue, 26 Jul 2016 05:14:37 +0000 (22:14 -0700)]
Fix gcpu regression associated with 1ms tick in HHWheelTimer

Summary:
We should go back to 10ms granularity.
Because regressions -
https://www.facebook.com/groups/wfi/permalink/1107102889338325/

Reviewed By: haijunz

Differential Revision: D3616784

fbshipit-source-id: dc1d7ff5195ae836df4a334a9ac5c41164c0627b

7 years agoFix typo in SharedMutex comment
Giuseppe Ottaviano [Sun, 24 Jul 2016 18:48:49 +0000 (11:48 -0700)]
Fix typo in SharedMutex comment

Reviewed By: yfeldblum

Differential Revision: D3611881

fbshipit-source-id: 3991c18cc2956e9d0b50a20e6daf913ec58ee501

7 years agoFix a namespace issue
Giuseppe Ottaviano [Sun, 24 Jul 2016 17:21:07 +0000 (10:21 -0700)]
Fix a namespace issue

Reviewed By: dkgi

Differential Revision: D3586189

fbshipit-source-id: ce817233a0293e19400b5689c283531be6302c10

7 years agoAdd helper functions for mallctl
Qinfan Wu [Sun, 24 Jul 2016 04:34:49 +0000 (21:34 -0700)]
Add helper functions for mallctl

Summary: As more code is using mallctl, it's worth making these helper functions available everywhere.

Reviewed By: yfeldblum

Differential Revision: D3576190

fbshipit-source-id: 968e80e00f2ed93542e117c24861c21745b63f20

7 years agoMove RequestContext definitions to source files
Yedidya Feldblum [Sat, 23 Jul 2016 22:44:57 +0000 (15:44 -0700)]
Move RequestContext definitions to source files

Summary:
[Folly] Move `RequestContext` definitions to source files.

Keeping headers lightweight can help with build times.

Reviewed By: djwatson

Differential Revision: D3609809

fbshipit-source-id: 20608e3ff764c86c24355a328da1dcca9a08fce4

7 years agoRequestContext changes to facilitate thread tracing
Melanie Subbiah [Fri, 22 Jul 2016 22:01:39 +0000 (15:01 -0700)]
RequestContext changes to facilitate thread tracing

Summary: In order to trigger trace points when a new thread begins/finishes executing, I added functionality to call onSet and onUnset methods on all RequestData objects whenever setContext is called. The main question: will this approach cost us too much overhead?

Reviewed By: djwatson

Differential Revision: D3604948

fbshipit-source-id: 3b704ca0f2b713458427aa49be12f776939057f8

7 years agoFix ASAN exposed heap-use-after-free
Mark Isaacson [Fri, 22 Jul 2016 17:47:38 +0000 (10:47 -0700)]
Fix ASAN exposed heap-use-after-free

Summary: This code very obviously wrote past the end of the buffer when the length was 1. Furthermore, it was just downright broken for all values. The author obviously meant to type * instead of +. I took the time to verify that the algorithm is actually correct, while I was working on this. My proof is in the test plan.

Reviewed By: yfeldblum, meyering

Differential Revision: D3603255

fbshipit-source-id: 5f2a0011ff5401a70ba03993eab6e53e29d87c1c

7 years agoRename GetTickCount to GetClockTickCount
Christopher Dykes [Fri, 22 Jul 2016 17:16:18 +0000 (10:16 -0700)]
Rename GetTickCount to GetClockTickCount

Summary: Because Windows already defines a funtion named `GetTickCount` with a different signature.

Reviewed By: yfeldblum

Differential Revision: D3601877

fbshipit-source-id: fa0fb422156a3dc71e149e02a000ccdf3479eea5

7 years agoUpdate FB_ONE_OR_NONE in Preproc.h to work with MSVC
Christopher Dykes [Fri, 22 Jul 2016 17:15:29 +0000 (10:15 -0700)]
Update FB_ONE_OR_NONE in Preproc.h to work with MSVC

Summary: There was an MSVC section, but it's much simpler to just use the glue to solve the issue instead.

Reviewed By: yfeldblum

Differential Revision: D3601184

fbshipit-source-id: f95bd3dfc4b244e1bce21997f44de2970575ad7f

7 years agoAlways use the 64-bit conversion function in ConvBenchmark.cpp
Christopher Dykes [Fri, 22 Jul 2016 17:15:00 +0000 (10:15 -0700)]
Always use the 64-bit conversion function in ConvBenchmark.cpp

Summary: A `long` on MSVC is only 4 bytes, so the `static_assert` will fail. Remove the static assert and use the `long long` version instead. Do the same for the unsigned version.

Reviewed By: yfeldblum

Differential Revision: D3601064

fbshipit-source-id: 70c5f4bca597ba05c3729f5d15feeea3cc8fde57

7 years agoInclude the Builtins portability header in Bits.h
Christopher Dykes [Fri, 22 Jul 2016 17:14:46 +0000 (10:14 -0700)]
Include the Builtins portability header in Bits.h

Summary: Because we need it for MSVC.

Reviewed By: yfeldblum

Differential Revision: D3601138

fbshipit-source-id: 4d2ba3f9c972717745289686b025d2763f9ef30d

7 years agoInclude the sys/types.h portability header
Christopher Dykes [Fri, 22 Jul 2016 17:14:15 +0000 (10:14 -0700)]
Include the sys/types.h portability header

Summary: As the comment in the file says, this has to be included in a weird order due to issues on Windows.

Reviewed By: yfeldblum

Differential Revision: D3601008

fbshipit-source-id: fca4b6d906eb0d1f001c28197987165cd075752d

7 years agoUse decltype to get the type of a non-static local
Christopher Dykes [Fri, 22 Jul 2016 17:13:42 +0000 (10:13 -0700)]
Use decltype to get the type of a non-static local

Summary: As the `sizeof()` is being evaluated in a static context, MSVC doesn't let you reference non-static locals. Solve the issue by getting the type of the local via `decltype` instead.

Reviewed By: yfeldblum

Differential Revision: D3600845

fbshipit-source-id: 825d93ced8f09d9f4bf0dcf02142f47a0ec32605

7 years agoDon't typedef types to the same name in different namespaces
Christopher Dykes [Fri, 22 Jul 2016 17:13:30 +0000 (10:13 -0700)]
Don't typedef types to the same name in different namespaces

Summary:
This was causing MSVC to complain due to `DSched` already being declared in `BatonTestHelpers.h` as `::folly::DSched`, but it's then typedef'd again in `BatonTest.cpp`, this time as `::DSched`. MSVC complains about the duplicate definitions even though they resolve to the same type, so kill the one in the source file and keep the one in the header.
The same is the case with `GroupVarint32Decoder` and `GroupVarint64Decoder`, which are both declared in `GroupVarint.h` and then again, this time in an anon namespace, in `GroupVarintTest.cpp`.

Reviewed By: yfeldblum

Differential Revision: D3600948

fbshipit-source-id: 401790aa918289fe4a34dd5af683f8c6ca50d847

7 years agofolly: fixup folly::Random FixedSeed test expectations on macOS
Wez Furlong [Fri, 22 Jul 2016 00:51:38 +0000 (17:51 -0700)]
folly: fixup folly::Random FixedSeed test expectations on macOS

Summary:
uniform_int_distribution is implemented differently on this system and
always returns the generated number from our constant random number generator.

Reviewed By: yfeldblum

Differential Revision: D3585418

fbshipit-source-id: 754076599ba77b49c17f03bb0c92264a3bed4ab0

7 years agoDon't use ?:
Christopher Dykes [Thu, 21 Jul 2016 23:56:32 +0000 (16:56 -0700)]
Don't use ?:

Summary:
Because it doesn't exist in the C++ standard.

This switches them to the explicitly expanded form, which is in the spec.
It also removes a few that were doing absolutely nothing. (MSVC still complained about the division by zero)

Reviewed By: yfeldblum

Differential Revision: D3479260

fbshipit-source-id: 5386e27057beeb4b228f5d6be4e1cf9941cf3176

7 years agoSupport StlVectorTest for MSVC
Christopher Dykes [Thu, 21 Jul 2016 23:16:12 +0000 (16:16 -0700)]
Support StlVectorTest for MSVC

Summary:
Sure, it's big, but it compiles.

There are a few different changes to make this happen, the first is to deal with quite a few places where MSVC was complaining about the implicit coersion of template and noexcept parameters to bool.
Next, the gating that disabled this for 4.7 is now gone.
MSVC's runtime expected `difference_type` to be defined on our custom allocator, so it now is.
`ReadTSC()` was changed to use MSVC's intrinsic for this.
And finally, the named variadic parameters to macros were switched to normal variadic macro params, as MSVC doesn't support named ones.

Reviewed By: yfeldblum

Differential Revision: D3479761

fbshipit-source-id: 703a5ef942ffc9b63381d13fc3960ac6f2780aa0

7 years agoMark a couple of local constants as static constexpr
Christopher Dykes [Thu, 21 Jul 2016 23:12:57 +0000 (16:12 -0700)]
Mark a couple of local constants as static constexpr

Summary: Because they aren't captured, and thus aren't accessible, in the callback used further on in the function.

Reviewed By: yfeldblum

Differential Revision: D3600874

fbshipit-source-id: 699b3d4caa0a310b1ccc7810d670671850f4366b

7 years agoDisable a test of ThreadLocal across forks for Windows
Christopher Dykes [Thu, 21 Jul 2016 23:09:26 +0000 (16:09 -0700)]
Disable a test of ThreadLocal across forks for Windows

Summary: We don't have `fork()` to begin with, so disable the test and the includes it required if we're compiling on Windows.

Reviewed By: yfeldblum

Differential Revision: D3600600

fbshipit-source-id: 5399705753b456139105f4ac757190e1ba1765f2

7 years agoallocate_sys_buffer
Yedidya Feldblum [Wed, 20 Jul 2016 22:07:31 +0000 (15:07 -0700)]
allocate_sys_buffer

Summary:
[Folly] `allocate_sys_buffer`.

For when a `malloc`'d buffer is required, with an associated deleter that calls `free`.

Reviewed By: JonCoens

Differential Revision: D3590516

fbshipit-source-id: 644f4b5d5e8f19dbc8f29efe3e93517fba0ad72f

7 years agoRecord whether cached certificate was used
Mingtian Yin [Wed, 20 Jul 2016 18:43:19 +0000 (11:43 -0700)]
Record whether cached certificate was used

Summary: Record whether cached certificate was used

Reviewed By: anirudhvr

Differential Revision: D3582807

fbshipit-source-id: 246107ce383ff31718ee7dcccf8bbea459b559a8

7 years agofolly: allow folly::init to build on systems without the symbolizer (macOS)
Wez Furlong [Wed, 20 Jul 2016 17:58:54 +0000 (10:58 -0700)]
folly: allow folly::init to build on systems without the symbolizer (macOS)

Summary:
This makes folly/init/Init.cpp compile on macOS by leveraging
equivalent functionality in the glog library when the folly symbolizer is not
available.  This is true for macOS and also for Windows.  I haven't done
anything to handle Windows in this diff.

Reviewed By: yfeldblum

Differential Revision: D3585509

fbshipit-source-id: 2e0c29520a53826acbf656a7a02659b4e905802f

7 years agoWrappers folly::chrono::clock_gettime and clock_gettime_ns
Christopher Dykes [Tue, 19 Jul 2016 22:58:01 +0000 (15:58 -0700)]
Wrappers folly::chrono::clock_gettime and clock_gettime_ns

Summary:
On Linux hosts, the fast path to get the current time in
nanoseconds without doing a syscall to the kernel is available via the
VDSO kernel-runtime interface.

In this diff, I:

1. Expose portability wrappers `folly::chrono::clock_gettime()` and
`folly::chrono::clock_gettime_ns()`
2. Implement a VDSO wrapper on Linux hosts to implement those without
a round-trip to the kernel

Depends On D3418054

Reviewed By: bmaurer

Differential Revision: D3418087

fbshipit-source-id: 3fb99f0dd946f19ba29d0d52a1038dad3556bafd

7 years agoGenerate a pkg-config file for Folly
Steve Muir [Tue, 19 Jul 2016 22:48:41 +0000 (15:48 -0700)]
Generate a pkg-config file for Folly

Summary: First cut at autoconf rules for generating a pkg-config file for Folly. The only interesting part is that we want to handle packages that provide their own .pc files as dependencies rather than just stuffing them into the list of libraries required from packages that don't provide .pc.

Reviewed By: simpkins

Differential Revision: D3556611

fbshipit-source-id: d1c5f89416d1d96d2cdf5ccdc5bd7117fb822a82

7 years agoHandle small_vectors with 0 inline capacity correctly
Christopher Dykes [Tue, 19 Jul 2016 22:44:31 +0000 (15:44 -0700)]
Handle small_vectors with 0 inline capacity correctly

Summary: It is an error to attempt to get the size of a zero length array, such as `unsigned char[0]`, which is what you get if `MaxInline` has been passed in as 0. We can work around this by simply defining `InlineStorageType` to be `void*` if the size is exactly 0, which will result in the capacity correctly being stored out of line.

Reviewed By: yfeldblum

Differential Revision: D3572898

fbshipit-source-id: c96bb7cc6a890044bb74b0f6d5238c503552ee25

7 years agoCorrectly use iters_ in ProducerConsumerQueueBenchmark
Elliott Clark [Tue, 19 Jul 2016 22:30:08 +0000 (15:30 -0700)]
Correctly use iters_ in ProducerConsumerQueueBenchmark

Summary: iters was only being used on one side of the producer/consumer.

Reviewed By: yfeldblum

Differential Revision: D3588593

fbshipit-source-id: 5e9a8a02bb9addbd6f936b8cc411d58cdf82b6e2

7 years agoMake the mprotect variant of asymmetricHeavyBarrier work when mlock fails
Yedidya Feldblum [Tue, 19 Jul 2016 21:38:12 +0000 (14:38 -0700)]
Make the mprotect variant of asymmetricHeavyBarrier work when mlock fails

Summary: [Folly] Make the `mprotect` variant of `asymmetricHeavyBarrier` work when `mlock` fails.

Reviewed By: djwatson

Differential Revision: D3585948

fbshipit-source-id: c3a46884434b7f9da9caa9cf203573f9e3ce7444

7 years agoFix macro check in SysMembarrier
Michael Lee [Tue, 19 Jul 2016 20:26:37 +0000 (13:26 -0700)]
Fix macro check in SysMembarrier

Summary:
FOLLY_X64 is usually defined, so check whehter it is defined
to 0 or 1.  In addition, memory barriers are not necessarily widely
available on the mobile platforms. What leads me to believe this is
that, at least for older ndk's, atomics are not guaranteed to work for
multicore platforms.

Reviewed By: andriigrynenko

Differential Revision: D3586806

fbshipit-source-id: 3ac8c4b74cac09e41bc3cb65c8adc2732b8b2256