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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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