folly.git
8 years agoDon't attempt to escape % in SparseByteSetBench
Christopher Dykes [Thu, 11 Aug 2016 22:58:04 +0000 (15:58 -0700)]
Don't attempt to escape % in SparseByteSetBench

Summary: Because it doesn't need to be escaped, and MSVC will warn about invalid escape sequences. If being built with HHVM's settings for MSVC, it's actually an error, as the same warning is produced for multi-byte escape sequences in narrow strings.

Reviewed By: yfeldblum

Differential Revision: D3704596

fbshipit-source-id: 603e57a35f8b7433d1f6e47f4c2882244536b14f

8 years agoConstruct TestObject in AtomicLinkedListTest via a const reference
Christopher Dykes [Thu, 11 Aug 2016 22:38:49 +0000 (15:38 -0700)]
Construct TestObject in AtomicLinkedListTest via a const reference

Summary:
MSVC doesn't currently guarantee left-to-right argument evaluation order for values constructed via braced initializers, and produces a warning if you try to pass an argument with a non-trivial copy constructor by-value in a constructor used by the braced initializer.
This prevents the warning by simply accepting a const reference instead.

Reviewed By: yfeldblum

Differential Revision: D3705073

fbshipit-source-id: 917ec1bb776d6ec4bfefe50907d4c5ac2f2379b1

8 years agoInclude intrin.h in CpuId for the cpuid builtins
Christopher Dykes [Thu, 11 Aug 2016 21:35:16 +0000 (14:35 -0700)]
Include intrin.h in CpuId for the cpuid builtins

Summary: Some shuffling and elmination of other includes exposed the fact that this was calling the cpuid builtins, but hadn't included the header they were defined in.

Reviewed By: yfeldblum

Differential Revision: D3704321

fbshipit-source-id: 332c2d22714abaa74090abe7e7a5b28aec6b905a

8 years agoAdjust the AsyncSocket TestServer to work with Winsock
Christopher Dykes [Thu, 11 Aug 2016 21:26:41 +0000 (14:26 -0700)]
Adjust the AsyncSocket TestServer to work with Winsock

Summary:
Winsock doesn't let you listen to a socket if it hasn't been bound to anything, so bind it to the port first.
TestServer was also never closing the file descriptor, causing the socket to leak.

Reviewed By: yfeldblum

Differential Revision: D3698467

fbshipit-source-id: cca415143009fbee99ebf94d7f46aedc9c59191d

8 years agoDisable the constexpr tests for findFirstSet, findLastSet and nextPowTwo under MSVC
Christopher Dykes [Thu, 11 Aug 2016 21:25:18 +0000 (14:25 -0700)]
Disable the constexpr tests for findFirstSet, findLastSet and nextPowTwo under MSVC

Summary: Because they aren't currently constexpr under MSVC.

Reviewed By: yfeldblum

Differential Revision: D3705095

fbshipit-source-id: ea266ebd9677fb2ba232476160f7c10a23954db9

8 years agoUse explicitly sized integers in the Conv test
Christopher Dykes [Thu, 11 Aug 2016 21:17:31 +0000 (14:17 -0700)]
Use explicitly sized integers in the Conv test

Summary: Because the tests are explicitly dependent on the size of these types, and `long` is a different size on Windows.

Reviewed By: yfeldblum

Differential Revision: D3704488

fbshipit-source-id: e15e95242c5e9c84165a50cfd2c3bc6e0d2e0c49

8 years agoEliminate accidental trigraph in FBString
Christopher Dykes [Thu, 11 Aug 2016 19:43:44 +0000 (12:43 -0700)]
Eliminate accidental trigraph in FBString

Summary: `<::` is a trigraph, which, although removed in C++17, MSVC still warns about the sequences (although it doesn't actually intepret them as trigraphs)

Reviewed By: yfeldblum

Differential Revision: D3704382

fbshipit-source-id: b093f854343db01bc166b1cc44763676fdd97a51

8 years agoUse _r_debug instead of /proc/<pid>/maps for folly::symbolizer
Max Wang [Thu, 11 Aug 2016 18:22:46 +0000 (11:22 -0700)]
Use _r_debug instead of /proc/<pid>/maps for folly::symbolizer

Summary:
Using _r_debug offers a number of benefits:
- It allows us to symbolize addresses in data segments like .bss that
  are marked "[heap]" in /proc/<pid>/maps.
- It requires a lot less code.

It also fixes a preexisting bug where we would fail to symbolize
addresses that fell in any section past the first in any position-
independent objects.  Since `elfFile->getBaseAddress()` should always
return 0 for any PIEs, we wouldn't correctly adjust the address to be
ELF-relative when performing symbol lookup.  (For the first section,
we just used the start of the range we found in /perf/<pid>/maps.)

There is a minor downside:
- We have to open an ELF header for each object in order to check if a
  given address is in the range of some segment.  Before, we used
  /proc/<pid>/maps to make the range check, and only opened the header
  once we knew it was the one we wanted.  In the common case, however,
  where the addresses are from our own executable, we don't open any
  more files than before (and, in fact, one fewer).

Reviewed By: luciang

Differential Revision: D3695872

fbshipit-source-id: 9bdcc77da4d658ffad5c671f9b8ea65a471ed64f

8 years agoRemove ConditionallyExistent, because it violates the C++ spec
Yedidya Feldblum [Thu, 11 Aug 2016 18:08:33 +0000 (11:08 -0700)]
Remove ConditionallyExistent, because it violates the C++ spec

Summary:
[Folly] Remove `ConditionallyExistent`, because it violates the C++ spec.

The spec says that struct and class types occupy at least one byte. But the point of this class is to occupy zero bytes when the condition is false. That can't be made to work.

GCC and Clang support an extension allowing, in some cases, structs to occupy no space at all. But it violates the spec, and MSVC does not support the extension.

There is, sort of, the possibility of empty-base-class-optimization. But it will be very painful to use, and it will only work in some cases.

Since this is broken now, and fixing it would violate the C++ spec and break this under MSVC, it's better just to remove it.

Reviewed By: nbronson, Orvid

Differential Revision: D3696371

fbshipit-source-id: c475c6e15d9ff1bc4c44dc7e336ce74e6db640ef

8 years agoLet applyTuple accept any number of tuples
Sven Over [Thu, 11 Aug 2016 08:40:38 +0000 (01:40 -0700)]
Let applyTuple accept any number of tuples

Summary:
Instead of passing exactly one tuple of arguments to applyTuple,
this diff allows to pass any number (zero or more) of tuples.

This can be very handy when piecing together arguments for
a function call.

Reviewed By: yfeldblum

Differential Revision: D3681499

fbshipit-source-id: a75a448636759f71db8d303e9dccada5b559af54

8 years ago__google_stl_debug_vector: erase() at invalid position: folly/experimental/test:futur...
Lucian Grijincu [Thu, 11 Aug 2016 07:50:06 +0000 (00:50 -0700)]
__google_stl_debug_vector: erase() at invalid position: folly/experimental/test:future_dag_test - FutureDAGTest.RemoveNodeComplex

Summary:
```
[ RUN      ] FutureDAGTest.RemoveNodeComplex
terminate called after throwing an instance of 'std::out_of_range'
  what():  erase() at invalid position
*** Aborted at 1470867850 (Unix time, try 'date -d 1470867850') ***
*** Signal 6 (SIGABRT) (0x133c001ed107) received by PID 2019591 (pthread TID 0x7ff1e6df5980) (linux TID 2019591) (maybe from PID 2019591, UID 4924), stack trace: ***
    @ 00007ff1e702020f folly::symbolizer::(anonymous namespace)::innerSignalHandler(int, siginfo_t*, void*)
    @ 00007ff1e701faf1 folly::symbolizer::(anonymous namespace)::signalHandler(int, siginfo_t*, void*)
    @ 00007ff1e87c714f (unknown)
    @ 00007ff1e7cf6d02 gsignal
    @ 00007ff1e7cf8af5 abort
    @ 00007ff1e73880e4 __gnu_cxx::__verbose_terminate_handler()
    @ 00007ff1e7385ee5 __cxxabiv1::__terminate(void (*)())
    @ 00007ff1e7385f30 std::terminate()
    @ 00007ff1e73861c0 __cxa_throw
    @ 00007ff1e740ae00 std::__throw_out_of_range(char const*)
    @ 00000000004483db std::vector<folly::FutureDAG::Node, std::allocator<folly::FutureDAG::Node> >::_M_erase(__gnu_cxx::__normal_iterator<folly::FutureDAG::Node*, std::vector<folly::FutureDAG::Node, std::allocator<folly::FutureDAG::Node> > >)
    @ 00000000004478fa std::vector<folly::FutureDAG::Node, std::allocator<folly::FutureDAG::Node> >::erase(__gnu_cxx::__normal_iterator<folly::FutureDAG::Node const*, std::vector<folly::FutureDAG::Node, std::allocator<folly::FutureDAG::Node> > >)
    @ 000000000044770a folly::FutureDAG::remove(unsigned long)
    @ 0000000000424bc2 FutureDAGTest::remove(unsigned long)
    @ 000000000041f7ed FutureDAGTest_RemoveNodeComplex_Test::TestBody()
    @ 00007ff1e9b19361 void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*)
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:2420
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1e9b029de testing::Test::Run()
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:2437
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1e9b02aca testing::TestInfo::Run()
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:2612
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1e9b02cfc testing::TestCase::Run()
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:2730
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1e9b0d2a7 testing::internal::UnitTestImpl::RunAllTests()
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:4602
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1e9b0d60c testing::UnitTest::Run()
                       /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest.cc:2420
                       -> /home/engshare/third-party2/gtest/1.7.0/src/gtest-1.7.0/src/gtest-all.cc
    @ 00007ff1eb64ec70 RUN_ALL_TESTS()
    @ 00007ff1eb64ec3c main
    @ 00007ff1e7ce10f5 __libc_start_main
    @ 000000000041f2d2 (unknown)
Summary (total time 0.07s):
  PASS: 0
  FAIL: 0
  SKIP: 0
  FATAL: 1
    folly/experimental/test:future_dag_test - FutureDAGTest.RemoveNodeComplex
  TIMEOUT: 0
````

Reviewed By: yfeldblum

Differential Revision: D3700956

fbshipit-source-id: dffca9460ccca1d8069218c5b7310e4d6e061697

8 years agoPolymorphic Functor implementation in Folly::FutureDAG
Shayan Mohanty [Thu, 11 Aug 2016 02:15:36 +0000 (19:15 -0700)]
Polymorphic Functor implementation in Folly::FutureDAG

Summary:
Implements a polymorphic functor for FutureDAGs. In order for FutureDAGs to be stateful they must be wrapped by a class of some sort. This is a really common pattern which we've been using in Gossit (and further - across the RedWood stack) in order to maintain state, and we feel it's generalized enough to be useful elsewhere.

`state` is an instance of the type declared in the template, and the exec* methods wrap go().get() so client-side implementations only have to touch the functor after construction in order to drive their DAGs.

Reviewed By: tjkswaine

Differential Revision: D3685651

fbshipit-source-id: 81169aefcff13ac8cc6cbb6bef6d90047732ad8a

8 years agoGate SysMembarrier to not FOLLY_MOBILE platforms
Michael Lee [Wed, 10 Aug 2016 23:45:18 +0000 (16:45 -0700)]
Gate SysMembarrier to not FOLLY_MOBILE platforms

Summary: Gate `kIsLinux` to not include `FOLLY_MOBILE` because "mobile" linux does not really behave like real linux.

Differential Revision: D3697717

fbshipit-source-id: 1b0f4208d2f71c35399c30f20a71bfa4ba4724e8

8 years agoFix scheduling bug
Dave Watson [Wed, 10 Aug 2016 22:41:29 +0000 (15:41 -0700)]
Fix scheduling bug

Summary:
Noticed this while debugging other timerwheel changes.  Scheduling new events in callbacks may result in us *running them right away* if they land in a bucket we are currently processing.

Instead, round up all the timeouts, then run them separately.  This means you can never schedule a timeout that will run immediately (0ticks), but that's probably fine.

Reviewed By: yfeldblum

Differential Revision: D3679413

fbshipit-source-id: 7e18632f23ea33c072c2718e30b378641895b094

8 years agofix bug in FBString::find
Philip Pronin [Wed, 10 Aug 2016 22:03:37 +0000 (15:03 -0700)]
fix bug in FBString::find

Summary:
Standard (21.4.7.2 / 1):

> Determines the lowest position xpos, if possible, such that both of the following conditions obtain:
- pos <= xpos and xpos + str.size() <= size();
- traits::eq(at(xpos+I), str.at(I)) for all elements I of the string controlled
by str.

The existing logic violates the first requirement for `str.size() == 0` by
unconditionally returning `pos`.

Reviewed By: ot, Gownta

Differential Revision: D3698862

fbshipit-source-id: 9622f1b99b259d2d81ae83795dff9cd94619c725

8 years agoMark FormatArg::error as noreturn
Christopher Dykes [Wed, 10 Aug 2016 20:18:10 +0000 (13:18 -0700)]
Mark FormatArg::error as noreturn

Summary: Because, if no inlining is enabled, the absence of this attribute caused compile errors due to functions that were expected to return a value not returning a value.

Reviewed By: meyering

Differential Revision: D3698413

fbshipit-source-id: 8f3505b17a2fa7b9710e3fb56d18c6ca00feacb3

8 years agoDon't attempt to call getsockname before binding an async socket
Christopher Dykes [Wed, 10 Aug 2016 20:15:18 +0000 (13:15 -0700)]
Don't attempt to call getsockname before binding an async socket

Summary: With WinSock, calling `getsockname` on a socket before it's been bound will always result in an error, so make sure to bind the socket first.

Reviewed By: yfeldblum

Differential Revision: D3698112

fbshipit-source-id: e9efe05323b242add3808ee1a6fec2593beb04ac

8 years agoSpecial-case /dev/null in open in the portability header
Christopher Dykes [Wed, 10 Aug 2016 19:35:31 +0000 (12:35 -0700)]
Special-case /dev/null in open in the portability header

Summary: `/dev/null` doesn't exist on Windows, but thankfully, `NUL` does, and has the same semantics.

Reviewed By: meyering

Differential Revision: D3698007

fbshipit-source-id: 5ef31c6576f988dd747ea3c39e296c244bc640b7

8 years agoUse ReadMostlyMainPtrDeleter in folly::Singleton
Andrii Grynenko [Wed, 10 Aug 2016 02:53:52 +0000 (19:53 -0700)]
Use ReadMostlyMainPtrDeleter in folly::Singleton

Reviewed By: yfeldblum

Differential Revision: D3691541

fbshipit-source-id: 9488c1487ebd0500a23300292215456ca3220f03

8 years agoReadMostlyMainPtrDeleter
Andrii Grynenko [Wed, 10 Aug 2016 02:42:57 +0000 (19:42 -0700)]
ReadMostlyMainPtrDeleter

Summary:
Deleter helper object, which may release multiple ReadMostlyMainPtrs at once.
This allows underlying ref count implementation to perform expensive synchronization operations (e.g. asymmetric heavy barrier only once).

Reviewed By: yfeldblum

Differential Revision: D3691524

fbshipit-source-id: 3ac593b0d813345daba3a81ff4e2eb71b4db292e

8 years agoWait for all threads to finish executing before leaving in an EventBase test
Christopher Dykes [Wed, 10 Aug 2016 00:33:05 +0000 (17:33 -0700)]
Wait for all threads to finish executing before leaving in an EventBase test

Summary:
If one of the assertions failed, it would result in any threads that are still running accessing already-disposed data, so wait for the threads to exit, even when an exception is thrown.

This also slightly cleans up the handling of threads a bit further down, because the mess it was doing was completely unnecessary.

Reviewed By: yfeldblum

Differential Revision: D3692438

fbshipit-source-id: 9082ba248b2cf1062e46c97faf0bc062312ee9ae

8 years agoAdd a utility for disabling some CRT assertions in debug mode
Christopher Dykes [Wed, 10 Aug 2016 00:00:14 +0000 (17:00 -0700)]
Add a utility for disabling some CRT assertions in debug mode

Summary:
See the comment on `msvcReturnInvalidParams` for more info on the issue.
This also adds a use of it to TestUtilTest.

Reviewed By: yfeldblum

Differential Revision: D3691526

fbshipit-source-id: f0f596e9b4c830e1d31de01926162636757329e8

8 years agoSupport read and write from blocking and non-blocking pipes and sockets
Christopher Dykes [Tue, 9 Aug 2016 23:58:56 +0000 (16:58 -0700)]
Support read and write from blocking and non-blocking pipes and sockets

Summary: Also switch `pipe` to return a socket pair instead, as libevent can't poll against a pipe on Windows. And lastly, fix the file descriptor for sockets leaking when close is called.

Reviewed By: yfeldblum

Differential Revision: D3691255

fbshipit-source-id: c684242d255ac5158a4c805d432d345dac1b3bd8

8 years agoAllow the time remaining parameter to nanosleep to be null
Christopher Dykes [Tue, 9 Aug 2016 23:47:40 +0000 (16:47 -0700)]
Allow the time remaining parameter to nanosleep to be null

Summary: Pah! This definitely wasn't causing the lock tests to segfault. Nope, not at all <_>.

Reviewed By: yfeldblum

Differential Revision: D3691120

fbshipit-source-id: 6601db637f22c7b0bc326907a2a7976f6df7c159

8 years agoProperly support socketpair and reading and writing non-blocking sockets
Christopher Dykes [Tue, 9 Aug 2016 23:44:11 +0000 (16:44 -0700)]
Properly support socketpair and reading and writing non-blocking sockets

Summary:
Also handle invalid file descriptors correctly and switch away from `WSASendMsg` for the implementation of `sendmsg` due to limitations imposed by WinSock.
This also fixes up a few places that were explicitly referencing the global version of some socket functions, which was bypassing the socket portability layer.

Reviewed By: yfeldblum

Differential Revision: D3692358

fbshipit-source-id: 05f394dcc9bac0591df7581345071ba2501b7695

8 years agoImplement setenv correctly and support setting values to empty strings
Christopher Dykes [Tue, 9 Aug 2016 23:34:41 +0000 (16:34 -0700)]
Implement setenv correctly and support setting values to empty strings

Summary: Just calling `SetEnvironmentVariableA` wasn't updating `_environ`, which meant that calls to `getenv` weren't reflecting the changes made via `setenv`. The correct way to implement it is using `_putenv_s`, but there's one problem with that: passing an empty string as the value to `_putenv_s` results in the environment variable being unset. To make it possible to set the environment variable to an empty string, we shall dive head-first into the implementation details of the CRT and emerge victorious by blatently ignoring the documentation of `getenv` and modifying the string it returns to terminate it early.

Reviewed By: yfeldblum

Differential Revision: D3691007

fbshipit-source-id: 350c2ec72ec90b9178a9a45b2c2ed2659b788e37

8 years agoLook for the PATH environment variable rather than USER
Christopher Dykes [Tue, 9 Aug 2016 23:24:21 +0000 (16:24 -0700)]
Look for the PATH environment variable rather than USER

Summary: Windows is weird and calls it USERNAME instead, so just use one that everything agrees on: PATH

Reviewed By: yfeldblum

Differential Revision: D3691072

fbshipit-source-id: 579c6484736ef47e130049c29bef8b59c66a4482

8 years agoSupport using fcntl to mark pipes as non-blocking
Christopher Dykes [Tue, 9 Aug 2016 21:57:19 +0000 (14:57 -0700)]
Support using fcntl to mark pipes as non-blocking

Summary: Because the comment was a lie; sockets are blocking by default, not non-blocking.

Reviewed By: yfeldblum

Differential Revision: D3691145

fbshipit-source-id: 5d3c62b3573205fe416d77fe4b5b9fbd593ffd93

8 years agoRemove getTFOSucceeded
Subodh Iyengar [Tue, 9 Aug 2016 14:53:04 +0000 (07:53 -0700)]
Remove getTFOSucceeded

Summary:
The getTFOsucceeded doesn't really work right now
as intended. Currently we check right after sendmsg,
however we can only know whether or not the server
has acked the data after 1-RTT.

This removes getTFOSucceeded. Will fix in another diff.

Differential Revision: D3679235

fbshipit-source-id: 6b2bb01d3743ea7e68ad3cc9a26be6806f17ffbe

8 years agoconstexpr_abs
Yedidya Feldblum [Tue, 9 Aug 2016 02:46:27 +0000 (19:46 -0700)]
constexpr_abs

Summary:
[Folly] `constexpr_abs`.

Is `constexpr`.

Works over integral and floating types.

If given an integral type, the return type is the usigned version of that integral type, thereby avoiding the undefined behavior of `std::abs(std::numeric_limits<int>::min())`.

Reviewed By: simpkins

Differential Revision: D3654072

fbshipit-source-id: 24fefc0c3b055f78ba3e07472c38fb9c550e0f31

8 years agoRemoving noexcept specifications in constructors for Synchronized that call contextua...
Aaryaman Sagar [Tue, 9 Aug 2016 01:43:01 +0000 (18:43 -0700)]
Removing noexcept specifications in constructors for Synchronized that call contextualLock() and contextualRLock()

Summary:
Most mutex lock() functions do not have a noexcept guarantee, saying that the
constructor for Synchronized based on whether the underlying constructor for
the type stored is not enough.  Although this will *rarely* cause bugs, it
probably can be fixed

Reviewed By: simpkins

Differential Revision: D3682974

fbshipit-source-id: ec0bb701d0af41ffc79128fe8db7935a5f19bc70

8 years agoAdd MSG_NOSIGNAL to AsyncSSLSocket
Subodh Iyengar [Tue, 9 Aug 2016 00:55:10 +0000 (17:55 -0700)]
Add MSG_NOSIGNAL to AsyncSSLSocket

Summary:
We are definitely not prepared to handle
SIGPIPEs, so add MSG_NOSIGNAL to sendmsg
of AsyncSSLSocket.

This is a problem which exists in openssl
as well which calls send with flags = 0.
We recently made a change to move the send
into our control, so we can now supply the
flag

Reviewed By: yfeldblum

Differential Revision: D3686679

fbshipit-source-id: ff8fe662e62923c25876bdfd516352639505dca6

8 years agoUpdate documentation for Synchronized
Adam Simpkins [Mon, 8 Aug 2016 19:40:50 +0000 (12:40 -0700)]
Update documentation for Synchronized

Summary:
Update the documentation for Synchronized to remove references to the
various SYNCHRONIZED macros, and document the lock() and withLock() APIs
instead.

Reviewed By: yfeldblum

Differential Revision: D3618871

fbshipit-source-id: e970f9a23e45831d62232eea2ba133a55e5a4a49

8 years agoInclude sys/syscall.h to SysMembarrier
Michael Lee [Mon, 8 Aug 2016 17:54:18 +0000 (10:54 -0700)]
Include sys/syscall.h to SysMembarrier

Summary: It calls syscall, but does not include the header.

Reviewed By: knekritz

Differential Revision: D3586636

fbshipit-source-id: 2ef05fc4b88f236a84b79afa708e98fe21529685

8 years agoMethodology for using DeterministicSchedule support for auxiliary data and global...
Maged Michael [Mon, 8 Aug 2016 17:07:59 +0000 (10:07 -0700)]
Methodology for using DeterministicSchedule support for auxiliary data and global invariants

Summary:
Depends on D3648195

This test example is intended to demonstrate the methodology for using DeterministicSchedule support for auxiliary data and global invariants.
The main goal is fine-grained invariant checking, ideally after every shared update.
The secondary goals are:
- Minimize intrusion in the original code. In this proposed methodology, it is adding a friend.
- Minimize duplication of original tested code. Unfortunately, depending on the original code, it seems that significant duplication may be unavoidable if we don't want to change the original code.

This diff is primarily about the methodology for testing already developed code. I plan to apply what we agree on through this diff to the dynamic MPMCQueue code (D3462592).

A future goal to keep in mind is creating a methodology for developing new code with hooks for DSched aux. data and invariant checking integrated in it, in order to minimize or eliminate duplication of tested code.  In past projects, I used non-standard source code (basically algorithm code) that is automatically translatable through scripts and macros to input to a DSched-like tool as well as to compilable code. The main challenge for such a methodology is to allow the original source code to be standard readable C++ code.

Reviewed By: djwatson

Differential Revision: D3675447

fbshipit-source-id: aae2c9f0550af88dc3a5dcbe53318a75a86b6e2b

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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

8 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