Adam Simpkins [Thu, 1 Dec 2016 23:45:22 +0000 (15:45 -0800)]
add a new writeFileAtomic() function
Summary:
Add a utility function to more safely set a file's contents by writing to a
temporary file first, then renaming the temporary file into place. On Linux
systems where renames are atomic, this ensures that the operation either
succeeds or that the old file state is left unchanged on failure.
Note that unlike most of the other APIs in FileUtil.h, I intentionally made
writeFileAtomic() throw an exception on failure. This is implemented using a
lower-level writeFileAtomicNoThrow() version. Callers who care about the
exception overhead can use the lower level version instead. (Exception
overhead should be relatively low compared to the file I/O operations, though,
so I suspect most users will prefer the throwing APIs.)
Reviewed By: yfeldblum
Differential Revision:
D4253964
fbshipit-source-id:
5301e2791b82c6f90b63bb509b0411841c266705
Yedidya Feldblum [Thu, 1 Dec 2016 20:43:06 +0000 (12:43 -0800)]
Future<typename>::getTryVia
Summary:
[Folly] `Future<typename>::getTryVia`.
We have `waitVia` and `getVia` and `getTry`, but `getTryVia` was missing.
Reviewed By: fugalh
Differential Revision:
D4254972
fbshipit-source-id:
403e1a3496ad5dfc93c4c55ab75a83bcc89e6c64
Subodh Iyengar [Thu, 1 Dec 2016 14:39:24 +0000 (06:39 -0800)]
Fix assertion in unit test
Summary:
Fix test for AsyncSSLSocket. When a timeout
occurs during a handshake it's possible that
invokeConnectError is called with sslState_ ==
CONNECTING. This just removes the assertion in
this case. This doesnt affect prod code, only
tests
Reviewed By: yfeldblum
Differential Revision:
D4252677
fbshipit-source-id:
4db3a94ae28aa140546554c087bedcee7f06d201
Andrii Grynenko [Thu, 1 Dec 2016 01:59:58 +0000 (17:59 -0800)]
Use singleton EventBasePool in ServiceRouter
Summary:
Switching ServiceRouter code to use VirtualEventBase instead of EventBase allows us to have same thread-pool shared between multiple ServiceRouter instances.
In future this allows us to replace EventBasePoolImpl with some generic thread-pool implementation (e.g. IOThreadPoolExecutor). It also makes it trivial to have ServiceRouter run on a any existing thread-pool if necessary.
Reviewed By: smichelson
Differential Revision:
D3935283
fbshipit-source-id:
3275bbace15a0df8b06d12c970ccc098a631658d
Andrii Grynenko [Thu, 1 Dec 2016 00:50:04 +0000 (16:50 -0800)]
Use SingletonThreadLocal in folly::Random
Summary: folly::SingletonThreadLocal should be used for all thread-local singletons to avoid SDOF.
Reviewed By: yfeldblum
Differential Revision:
D4253009
fbshipit-source-id:
5b4ca57a7a77b7b54c94630a2a29d13b84a3af27
Christopher Dykes [Wed, 30 Nov 2016 19:17:39 +0000 (11:17 -0800)]
Start fixing implicit truncations
Summary:
Truncations should be explicit, but for some reason, MSVC seems to be the only compiler that will warn you when you implicitly truncate integer or float values.
This allows Folly to be compiled with warnings 4018, 4242, 4244 and 4305 enabled.
Technically 4018 is a sign mismatch warning, but there was only one place it was being triggered so I included it anyways. The other 3 are warnings for implicit truncation.
There is one other implicit truncation warning that currently triggers in Folly, 4267, but there are a lot more places where that triggers so I'll do that in a separate diff.
Reviewed By: yfeldblum
Differential Revision:
D4249471
fbshipit-source-id:
e18a93d85856c998576934a6229c9edd1638a54e
Teng Qin [Wed, 30 Nov 2016 19:07:23 +0000 (11:07 -0800)]
Add optional Tracepoint for RequestContext switch
Summary: Using newly added `StaticTracepoint.h`, add a Tracepoint for `RequestContext` switch that could be enabled by compiler flag.
Reviewed By: drarmstr
Differential Revision:
D4238658
fbshipit-source-id:
043a035ba8251b48d7b29d63a2219ad2edda164f
Eric Niebler [Wed, 30 Nov 2016 03:42:04 +0000 (19:42 -0800)]
Add constexpr to the simple folly::Range accessors (begin, end, data, empty, etc)
Summary: More constexpr is better!
Reviewed By: yfeldblum, luciang, ot
Differential Revision:
D4244996
fbshipit-source-id:
30a9b726c115a92bb18538d7f18e50eccb0a1ef6
Tiho Tarnavski [Tue, 29 Nov 2016 23:41:06 +0000 (15:41 -0800)]
Fix incorrect bytesWritten computation in AsyncSocket
Summary: If a write request is buffered after a partial write, then bytes written is not updated after subsequent write operations (`performWrite`) for the buffered write request (`BytesWriteRequest`). This results in a wrong value for totalBytesWritten_, which is reported in the error callback in case the write request fails.
Reviewed By: yfeldblum
Differential Revision:
D4205743
fbshipit-source-id:
f77ca55ccfdceda1008c45e72ec093b00bf250e4
Andrii Grynenko [Tue, 29 Nov 2016 23:34:43 +0000 (15:34 -0800)]
Disallow folly::Singletons before main()
Summary:
Make folly::Singleton fail if singleton is requested before registrationComplete. By doing this we disallow any folly::Singleton to be created before main().
Strict mode is still disabled for Python and Hs.
Reviewed By: yfeldblum
Differential Revision:
D4121322
fbshipit-source-id:
b66c23e24f6a7324cd12ddb77cad960e0950a1aa
Guo Xiao [Tue, 29 Nov 2016 20:30:16 +0000 (12:30 -0800)]
Escape backticks in shell script
Summary: Closes https://github.com/facebook/folly/pull/520
Reviewed By: pixelb
Differential Revision:
D4243347
Pulled By: yfeldblum
fbshipit-source-id:
cae0b36abdc7807afc188220f7f421f2a3bbc973
Nick Terrell [Tue, 29 Nov 2016 19:37:10 +0000 (11:37 -0800)]
Support old LZ4 versions
Summary:
D4194834 broke the OSS build. Ubuntu 14.4 has r114 in its repo, so support it.
Reviewed By: yfeldblum
Differential Revision:
D4224129
fbshipit-source-id:
c85e95716ee1a08b33455bfe6fc9f7712d226edf
Christopher Dykes [Tue, 29 Nov 2016 05:23:33 +0000 (21:23 -0800)]
Use std::terminate rather than throwing in a noexcept function
Summary: Because MSVC isn't happy about it and generates a warning with a lot of context.
Reviewed By: yfeldblum
Differential Revision:
D4242688
fbshipit-source-id:
b1e26c9e3b58e7bac0e00ab8959358010fa610e8
r8k [Mon, 28 Nov 2016 19:26:46 +0000 (11:26 -0800)]
fix bootstrap on osx
Summary:
* include all dependencies
* update `autoconf` & `configure` with correct params
* include `make` & `make install` in the bootstrap for a better user experience
* fixes #332
Closes https://github.com/facebook/folly/pull/513
Reviewed By: yfeldblum
Differential Revision:
D4177362
Pulled By: Orvid
fbshipit-source-id:
c62d6633c382fca57bb06db08724a7355b71bdb3
Yedidya Feldblum [Mon, 28 Nov 2016 06:02:48 +0000 (22:02 -0800)]
Canonicalize some aspects of the folly/experimental/hazptr test
Summary:
[Folly] Canonicalize some aspects of the `folly/experimental/hazptr` test.
* Remove the custom `main()` and use the provided weak symbol, either from `folly/test/common/TestMain.cpp` or from `gtest` depending on the build.
* Extract some common setup/teardown (just debug logging in this case) to a test fixture.
Reviewed By: Orvid
Differential Revision:
D4234154
fbshipit-source-id:
25613cba0ad6c9147714d98150e013fba1a64d46
Phil Willoughby [Sun, 27 Nov 2016 17:41:10 +0000 (09:41 -0800)]
Fix termination output on GCC
Summary:
Thanks nbronson for suggesting this fix. I don't see why this should make any
difference (and nor does clang) but the important thing is that it works now.
Reviewed By: nbronson
Differential Revision:
D4212670
fbshipit-source-id:
08b4313d736f237039a807fbc458d4d581a2ef35
Christopher Dykes [Fri, 25 Nov 2016 23:04:03 +0000 (15:04 -0800)]
Allow the use of an emulated futex for EventCount
Summary:
Otherwise it won't work under MSVC where we don't have Futexes.
This is achieved by using the Futex API already used elsewhere in Folly.
Reviewed By: yfeldblum
Differential Revision:
D4233517
fbshipit-source-id:
d6ae6a34b2287cf485f8e4a316445a2ba746d1a7
Christopher Dykes [Fri, 25 Nov 2016 19:29:21 +0000 (11:29 -0800)]
Revert
D4214296: [Folly] Include init/Init.cpp
Summary: This reverts commit
636ed5ae8ad36a323054efaad96d3756f1b7b9d0
Differential Revision:
D4214296
fbshipit-source-id:
41fe55a8fcbf41cce44fee7ba65eda5aadbf97b3
Subodh Iyengar [Fri, 25 Nov 2016 05:18:22 +0000 (21:18 -0800)]
Fix TFO refused case
Summary:
When TFO falls back, it's possible that
the fallback can also error out.
We handle this correctly in AsyncSocket,
however because AsyncSSLSocket is so
inter-twined with AsyncSocket, we missed
the case of error as well.
This changes it so that a connect error on
fallback will cause a handshake error
Differential Revision:
D4226477
fbshipit-source-id:
c6e845e4a907bfef1e6ad1b4118db47184d047e0
Yedidya Feldblum [Thu, 24 Nov 2016 22:56:49 +0000 (14:56 -0800)]
Suppress deprecation warnings in related tests
Summary:
[Folly] Suppress deprecation warnings in related tests.
When a test specifically exercises a marked-deprecated library or a marked-deprecated part of a library, we do not need to see the deprecation warnings - they are noise.
Specifically, `Singleton` and `Subprocess` have tested but marked-deprecated APIs, so we suppress deprecation warnings in those specific test suites.
Reviewed By: andrewjcg
Differential Revision:
D4230826
fbshipit-source-id:
937b078029cde492906088caa3a9e5eee449bc12
Christopher Dykes [Wed, 23 Nov 2016 23:19:57 +0000 (15:19 -0800)]
Don't expect .native() to return a string
Summary: It's called `.native()` for a reason, and returns a `wstring` on windows, so call `string()` instead.
Reviewed By: yfeldblum
Differential Revision:
D4229254
fbshipit-source-id:
d5f9658b41f45fd719ca3e878a2e61c9dce24f10
Teng Qin [Wed, 23 Nov 2016 22:05:39 +0000 (14:05 -0800)]
Add USDT header file to folly
Summary:
Derived from `sdt.h` in [[ https://sourceware.org/systemtap/ | SystemTap ]]
Performed changes and clean-ups including:
- Get rid of the `sdt-config.h`.
- Get rid of "Running in Assembler" code.
- Replace the `DTRACE_PROBE_1, ... DTRACE_PROBE_N` Macro family with a single Macro using the "count Macro arguments" trick
- Get rid of argument signed-ness calculation. A **lot** of painful code were there only for this, and it has no real usage except for displaying purposes.
- Re-structure the helper methods (Macros) so that the logic of the code is a bit more readable.
- Add some comments so that it would be easier for users and future developers to understand what this header file is actually doing.
- Update license banner.
Reviewed By: meyering
Differential Revision:
D3792966
fbshipit-source-id:
564a1011f7946d30be78191f334e072d94fa264e
Christopher Dykes [Wed, 23 Nov 2016 19:07:11 +0000 (11:07 -0800)]
Close sockets properly in the portability headers
Summary:
Even when linked against the dynamic runtime.
In truth, the old way was far cleaner, but we do need to be able to close the file descriptors as there is a hard global limit set by the CRT when it's compiled of 8k file descriptors.
This closes it by applying a flag that prevents calls to `CloseHandle` from actually closing the handle, then we call `_close` to get the file descriptor itself closed, then we can call `_closesocket` to close the socket and handle.
This is complicated by the fact that attempting to close a handle that you've marked as being prevented from being closed will trigger an SEH exception, but only if you have a debugger attached. That means that, for anything closing sockets to be debuggable, we have to handle that exception (as a no-op) and then get to have fun trying to get `STATUS_HANDLE_NOT_CLOSABLE`, which for some absurd reason, is only defined as part of the driver developer kit's headers. Some fun ensued where VS was nice enough to point out that the bcrypt headers also defines `NTSTATUS`, and doesn't require building as a driver to use it. For that reason we borrow its definition of `NTSTATUS` rather than declaring it ourselves.
We also have to prevent the main windows headers from defining the base SEH exceptions, because those will be redefined by `ntstatus.h` otherwise :(
Reviewed By: yfeldblum
Differential Revision:
D4222625
fbshipit-source-id:
6ed7e91b7a735b5506eb189e452983cd8cace34b
Christopher Dykes [Wed, 23 Nov 2016 18:43:24 +0000 (10:43 -0800)]
Suppress some aborts in debug mode when using already closed file descriptors
Summary: The helper exists because MSVC is a pain in this regard, so use it.
Reviewed By: yfeldblum
Differential Revision:
D4224037
fbshipit-source-id:
6c6415877785f13ea91618a3042f2470dccd08c1
Stepan Palamarchuk [Tue, 22 Nov 2016 22:39:34 +0000 (14:39 -0800)]
Fix fibers gdb utils script
Summary:
There was a recent change in boost compatibility that changed fibers internals and thus broke this script.
This diff fixes gdb script to properly print stack trace for fibers.
Reviewed By: yfeldblum
Differential Revision:
D4214575
fbshipit-source-id:
4bf69e9b297c7539a2b2b71093998c30d6a2d81c
Lovro Puzar [Tue, 22 Nov 2016 18:45:34 +0000 (10:45 -0800)]
Tweak zstd autoconf check so the build works with older zstd
Summary: Ubuntu 16.10 has a package for zstd 0.5.1 which is too old to be used by folly. With this change autoconf will check that one of the newer functions is present, disable zstd if not.
Reviewed By: Orvid, philippv
Differential Revision:
D4219964
fbshipit-source-id:
1e64dfb62f81f7e61b097cb7d4fd3810da476625
Christopher Dykes [Tue, 22 Nov 2016 17:48:18 +0000 (09:48 -0800)]
Correctly bind to the wildcard address in AsyncServerSocket::bind
Summary: Because Windows disagrees with everything else about how to specify that you want the wildcard address. It's done with an empty string on Windows, but `nullptr` everywhere else.
Reviewed By: yfeldblum
Differential Revision:
D4216970
fbshipit-source-id:
b5dc136946d9677a96be3252e44d383a6abca800
Christopher Dykes [Mon, 21 Nov 2016 23:40:54 +0000 (15:40 -0800)]
Work around an MSVC expression SFINAE bug in DynamicParser
Summary: The good news is that it's cleaner than it was to start with.
Reviewed By: yfeldblum
Differential Revision:
D4215323
fbshipit-source-id:
6758092f1e76f60b360753026bb7716737a51304
Christopher Dykes [Mon, 21 Nov 2016 23:39:27 +0000 (15:39 -0800)]
Disable the DoubleRegistrationLogging singleton test under MSVC
Summary: It's the only test in the file that is dependent on Subprocess, which is currently unsupported under MSVC.
Reviewed By: yfeldblum
Differential Revision:
D4214812
fbshipit-source-id:
9dcd9763b51d037e0c452f79f134df286a11e718
Zach Amsden [Mon, 21 Nov 2016 22:42:11 +0000 (14:42 -0800)]
Include init/Init.cpp
Summary: Anything calling folly::init() will not link with open source build
Reviewed By: yfeldblum
Differential Revision:
D4214296
fbshipit-source-id:
636ed5ae8ad36a323054efaad96d3756f1b7b9d0
Christopher Dykes [Sat, 19 Nov 2016 05:34:19 +0000 (21:34 -0800)]
Workaround a bug resolving decltype'd locals in lambdas
Summary:
Then it's time to get food.
The bug report linked in the comment has more details.
Reviewed By: yfeldblum
Differential Revision:
D4209389
fbshipit-source-id:
87e72691555992bdf964b0ded1173daadcedffa4
Christopher Dykes [Sat, 19 Nov 2016 04:56:29 +0000 (20:56 -0800)]
Don't explicitly alias dynamic after using the entire folly namespace
Summary: Because, to the best of my knowledge, MSVC is quite right to claim it doesn't know which `dynamic` everyone keeps referring to. Is it `folly::dynamic` or `::dynamic`?
Reviewed By: yfeldblum
Differential Revision:
D4209535
fbshipit-source-id:
63322a8f960954e1a63fe5c9a4a5d9395c7827d9
Christopher Dykes [Sat, 19 Nov 2016 02:35:02 +0000 (18:35 -0800)]
Use the GTest portability header in shell_test
Summary: It was including gtest directly, making MSVC unhappy.
Reviewed By: yfeldblum
Differential Revision:
D4208744
fbshipit-source-id:
7100058f3c9fde38744888c99e927c610f11d013
Christopher Dykes [Sat, 19 Nov 2016 01:54:36 +0000 (17:54 -0800)]
Don't attempt to separately close the underlying file descriptor in the format other test
Summary: Windows automatically closes the underlying file descriptor when you call fclose, however fclose is not a function that can be easily overriden in the portability layer, so choose to just not call `close` on Windows instead.
Reviewed By: yfeldblum
Differential Revision:
D4190524
fbshipit-source-id:
a68edccd04e63f89c178ade584fa7192845773f8
Christopher Dykes [Sat, 19 Nov 2016 01:53:37 +0000 (17:53 -0800)]
Use structs rather than type aliases for Unit::Lift and Unit::Drop
Summary:
VS 2017 RC brings with it fixes for some things and unfortunately, a few known regressions in expression SFINAE. In this case, alias templates with dependent `decltype()` calls are broken, so switch to a templated struct instead.
It's the very last issue mentioned in: https://blogs.msdn.microsoft.com/vcblog/2016/06/07/expression-sfinae-improvements-in-vs-2015-update-3/
Reviewed By: yfeldblum
Differential Revision:
D4199676
fbshipit-source-id:
9ce157cc891182509a30b000de1b509063387244
Maxime Boucher [Sat, 19 Nov 2016 00:53:50 +0000 (16:53 -0800)]
Synchronized: disable operator= when the type isn't copy assignable
Summary: The value of std::is_copy_assignable<folly::Synchronized<T>>::value is incorrect when T isn't copy assignable. As a result, it isn't possible to use SFINAE to properly select a function when the base type is a folly::Synchronized. This diff selectively deletes the copy constructor and copy assignment operator when the underlying type T isn't copyable. This is most useful in the case of folly::Synchronized<std::unique_ptr<...>>
Reviewed By: yfeldblum
Differential Revision:
D4203081
fbshipit-source-id:
1e811f9e52db26c23b1c6f1907bac9e2854ddb9d
Christopher Dykes [Fri, 18 Nov 2016 23:07:58 +0000 (15:07 -0800)]
Disable a range test under MSVC
Summary: Because, as the comment says, MSVC fails miserably at this, producing errors at compile time.
Reviewed By: yfeldblum
Differential Revision:
D4207544
fbshipit-source-id:
d9a11b72877d22d3d3fe2e2c862d99601ab21431
Martin Martin [Fri, 18 Nov 2016 17:59:37 +0000 (09:59 -0800)]
Expose folly::symbolizer::dumpStackTrace().
Summary:
Expose folly::symbolizer::dumpStackTrace() for use with
custom signal handlers.
Reviewed By: luciang
Differential Revision:
D4174004
fbshipit-source-id:
510b77edef652f3e9d10f0acfb4998b64a15fad5
Phil Willoughby [Fri, 18 Nov 2016 16:08:19 +0000 (08:08 -0800)]
Explain crash when exception is thrown from Scope Guard
Summary:
Print a message to `std::cerr` when the current program is about to call `std::terminate` because a `folly::ScopeGuard` callback threw an exception. This goes to `std::terminate` in the (common) cases when the `ScopeGuard` destructor is `noexcept`
This gives the user a small clue as to what just happened, since the default diagnostics for this on some platforms do not help at all.
Reviewed By: nbronson
Differential Revision:
D4061096
fbshipit-source-id:
c3b534d4a36b095e08e46f375251b6fd416ccd68
Nathan Bronson [Fri, 18 Nov 2016 16:07:09 +0000 (08:07 -0800)]
force read for doNotOptimizeAway(*ptr_to_small_trivial)
Summary:
doNotOptimizeAway's "X" input operand constraint is interpreted
more loosely by gcc than by clang, resulting in surprising behavior
for doNotOptimizeAway(*ptr) and a difference in behavior between gcc
and clang benchmarks. clang also is more aggressive about placing an
input operand into a register even when the constraint would allow it to
be in memory, so an "r,m" constraint has a similar problem. This diff
changes the input constraint so that register-sized values must actually
be copied into a register, which makes the behavior more intuitive and
more consistent across platforms.
Reviewed By: davidtgoldblatt
Differential Revision:
D4199767
fbshipit-source-id:
aa56a7b11cb3229b95da87295f0dfc38476959d2
Yedidya Feldblum [Fri, 18 Nov 2016 07:01:42 +0000 (23:01 -0800)]
Fix Build: folly with -Wmissing-braces
Summary:
[Folly] Fix Build: `folly` with `-Wmissing-braces`.
Construction of `std::array` with list-initialization for the contained C array requires double braces, per the standard.
Compilers accept it with single braces, but will reject it when `-Wmissing-braces` is passed.
Reviewed By: igorsugak, meyering
Differential Revision:
D4202629
fbshipit-source-id:
e5b87a655e7f25e6cddb931dda28b172c768f227
Andrew Gallagher [Fri, 18 Nov 2016 05:16:07 +0000 (21:16 -0800)]
folly/portability: move some macro definitions to `CPortability.h`
Summary: These macros apply to both C and C++.
Reviewed By: yfeldblum
Differential Revision:
D4199905
fbshipit-source-id:
8dc22959d0a6349c6c76415d1a38eda52cab83a5
Tom Jackson [Fri, 18 Nov 2016 02:14:14 +0000 (18:14 -0800)]
Faster unhexlify
Summary:
Using already-available lookup table instead of a bunch of branching, this improves read throughput from ~750MB/s to 2.1GB/s in benchmarks.
```
before: (time) (rate)
BM_unhexlify 1.39ns 719.26M
after:
BM_unhexlify 470.59ps 2.13G
```
Reviewed By: philippv
Differential Revision:
D4201352
fbshipit-source-id:
8393e066c45c402ccb8b537fdb25417e8e6a9511
Christopher Dykes [Fri, 18 Nov 2016 00:30:31 +0000 (16:30 -0800)]
Don't rely on implicit lookup of member names in dependent base classes
Summary:
The standard says this shouldn't be done, but GCC, Clang, and MSVC all do, at least, MSVC does if you don't pass the `/permissive-` switch to disable this non-compliant lookup.
This just qualifies it with `this->` which solves the problem.
MSVC plans to eventually (some time after the 2017 release) enable `/permissive-` by default, so let's start compiling with it now.
Reviewed By: yfeldblum
Differential Revision:
D4200725
fbshipit-source-id:
8545c6bcda9ba6006733c15f668805cb1260517a
Christopher Dykes [Fri, 18 Nov 2016 00:30:12 +0000 (16:30 -0800)]
Include atomic in SingletonTestStructs.cpp
Summary: This was relying on it being transitively included by system headers, which isn't the case under MSVC.
Reviewed By: yfeldblum
Differential Revision:
D4199882
fbshipit-source-id:
c25dc1e86687e19851923a1a660a91bcf63f0e6d
Christopher Dykes [Fri, 18 Nov 2016 00:29:09 +0000 (16:29 -0800)]
Mark a couple more local constexpr values as static
Summary: Because MSVC doesn't let you access it without capturing it from within a lambda otherwise.
Reviewed By: yfeldblum
Differential Revision:
D4199867
fbshipit-source-id:
7b829b2cc373edbebe3498901fa323c89a211818
Srinivas \"Teja\" Rao [Thu, 17 Nov 2016 22:55:03 +0000 (14:55 -0800)]
Update AtomicHashMap.md
Summary:
it seems second is the boolean that we need to compare.
Closes https://github.com/facebook/folly/pull/518
Differential Revision:
D4197096
Pulled By: yfeldblum
fbshipit-source-id:
71987dafac0ddbdb7817b55732619edbe9aed81b
Nick Terrell [Thu, 17 Nov 2016 21:18:48 +0000 (13:18 -0800)]
Replace deprecated LZ4 functions
Summary:
Replace deprecated functions with their functionally equivalent counterparts.
See https://github.com/lz4/lz4/blob/dev/lib/lz4.c#L1405 and https://github.com/lz4/lz4/blob/dev/lib/lz4hc.c#L634
Reviewed By: Cyan4973
Differential Revision:
D4194834
fbshipit-source-id:
aa4f934c46fe764fcec8ea29221e3882da2b5cdf
Andrii Grynenko [Thu, 17 Nov 2016 20:44:52 +0000 (12:44 -0800)]
VirtualEventBase
Summary:
This implements a view onto an EventBase, which can keep track of all tasks created through it and join them on destruction. Multiple VirtualEventBases can be backed by the same EventBase. This can be useful to have the same IO thread/thread-pool be shared between multiple libraries, allowing them to each have it's own VirtualEventBase and control its lifetime.
Since VirtualEventBase also supports LoopKeepAlive and onDestruction functionality, it can be easily integrated with FiberManagerMap.
Reviewed By: yfeldblum
Differential Revision:
D4158719
fbshipit-source-id:
7df964f36e5276e2b5665fd8394ea2e187aa298c
Lucian Grijincu [Thu, 17 Nov 2016 19:06:36 +0000 (11:06 -0800)]
folly: ExceptionWrapper: remove <iostream> from header
Summary: #accept2ship
Reviewed By: yfeldblum
Differential Revision:
D4192095
fbshipit-source-id:
eb0cad875bcc24d1c87a99890c51aea31f7024c9
Christopher Dykes [Thu, 17 Nov 2016 03:20:16 +0000 (19:20 -0800)]
Add folly::getCurrentThreadID()
Summary: And also use it in a couple of tests, so that they can be compiled on Windows, where `pthread_t` is a struct rather than a pointer or integer.
Reviewed By: yfeldblum
Differential Revision:
D4191560
fbshipit-source-id:
5bcf0a2952109b2a9bc5220c4640d42e2cdf8977
Delyan Kratunov [Thu, 17 Nov 2016 00:48:47 +0000 (16:48 -0800)]
Remove unneeded iostream include
Summary:
Including `iostream` in a header causes anything that uses this header to gain
an extra static initializer for an `std::ios_base::Init` object.
If there are N translation units in a library that use the header, that's N
more static initializers that need to run.
Reviewed By: yfeldblum
Differential Revision:
D4191798
fbshipit-source-id:
65b47401b9177177999cff65a47ac8dffa0e0546
Christopher Dykes [Thu, 17 Nov 2016 00:41:51 +0000 (16:41 -0800)]
Adjust the Function::NonCopyableLambda test to use a large struct rather than a C Array
Summary:
Because MSVC doesn't like it when you attempt to explicitly capture a c-style array in a lambda capture list.
See: https://developercommunity.visualstudio.com/content/problem/2444/cannot-explicitly-capture-c-style-array-in-lambda.html
Reviewed By: yfeldblum
Differential Revision:
D4191400
fbshipit-source-id:
305f8086c29f079ccf2c322f20da6393235bc76d
Geert Van Laethem [Wed, 16 Nov 2016 22:50:58 +0000 (14:50 -0800)]
Broken link to gtest 1.7.0 zip replaced with correct one
Summary: Closes https://github.com/facebook/folly/pull/517
Reviewed By: igorsugak
Differential Revision:
D4191764
Pulled By: Orvid
fbshipit-source-id:
5ab921bd0df0b9dbaca46cdf9ecdeea9ecda6f5a
Christopher Dykes [Wed, 16 Nov 2016 22:50:29 +0000 (14:50 -0800)]
Disable the CArray RangeFunc tests under MSVC
Summary: Because it won't compile due to an MSVC bug. See the link in the comment for more info.
Reviewed By: yfeldblum
Differential Revision:
D4191233
fbshipit-source-id:
523deebe12379ff56934a4259b601d4ab677b9b6
Nathan Bronson [Wed, 16 Nov 2016 22:01:49 +0000 (14:01 -0800)]
folly: fbvector: ubsan: avoid memset(nullptr, 0, 0)
Summary:
Constructing an empty FBVector by length results in a call to
memset with a null destination, which is undefined behavior. This diff
fixes it.
Reviewed By: luciang, meyering, Gownta
Differential Revision:
D4191612
fbshipit-source-id:
3dcc091396fc33ac2230bd2d90906325131b0a3b
Christopher Dykes [Wed, 16 Nov 2016 21:20:32 +0000 (13:20 -0800)]
Mark a few constexpr locals in ThreadLocalTest as static
Summary:
Because, as discussed in past diffs, MSVC currently requires them to be static in order to resolve them from within the scope of a lambda when they aren't captured.
The only one that actually needs to be marked as `static` is `numReps`, but I like consistency, so I marked them all as static.
Reviewed By: yfeldblum
Differential Revision:
D4191610
fbshipit-source-id:
7246170f30551d2079b4373eefbf3d02aab6dfa9
Christopher Dykes [Wed, 16 Nov 2016 21:19:59 +0000 (13:19 -0800)]
Hint that the port is numeric when binding an AsyncServerSocket
Summary: Because it had better be numeric or something is very wrong.
Reviewed By: yfeldblum
Differential Revision:
D4190568
fbshipit-source-id:
52a5ebfcedb545201191fc48f66a4419eee8f748
Lucian Grijincu [Wed, 16 Nov 2016 04:24:38 +0000 (20:24 -0800)]
folly: MemoryMapping: less verbose warning on TRY_LOCK+ENOMEM failures
Reviewed By: philippv
Differential Revision:
D4184097
fbshipit-source-id:
2f1f82b845528fea4667af612c92c348f8d9ec25
Christopher Dykes [Wed, 16 Nov 2016 02:46:23 +0000 (18:46 -0800)]
Qualify a field name in NotificationQueueTest
Summary: MSVC currently has a bug that causes it to incorrectly resolve it to `std::queue`: https://developercommunity.visualstudio.com/content/problem/2342/c-failure-to-resolve-instance-member-in-lambda-con.html
Reviewed By: lbrandy
Differential Revision:
D4187256
fbshipit-source-id:
207eafa339f7255ae881d8ab80f4847222c3b8c9
Christopher Dykes [Wed, 16 Nov 2016 01:30:09 +0000 (17:30 -0800)]
Don't assume standard library types are relocatable
Summary: Although currently the only one of these that isn't relocatable is `std::string`, making assumptions about the standard library is a terrible idea, so disable all of them.
Reviewed By: yfeldblum
Differential Revision:
D4186024
fbshipit-source-id:
4d2a54d232df0cb05959a8d9cb1a2d2cf34d1302
Andrii Grynenko [Tue, 15 Nov 2016 22:52:48 +0000 (14:52 -0800)]
Thread-safe version of loopKeepAlive()
Reviewed By: yfeldblum
Differential Revision:
D4152380
fbshipit-source-id:
8b3c6dc4b14b9138bb5012e05f50496e51c0fa4b
Christopher Dykes [Tue, 15 Nov 2016 19:38:18 +0000 (11:38 -0800)]
Mark FingerprintPolynomial.size() constexpr
Summary: Because it is, and so that MSVC doesn't complain about things in the fingerprint table generator.
Reviewed By: yfeldblum
Differential Revision:
D4178562
fbshipit-source-id:
8816f413bc100b42dd72f0e991aec8559b328e9b
Lucian Grijincu [Tue, 15 Nov 2016 04:39:13 +0000 (20:39 -0800)]
folly: MemoryMapping: isolate _MSC_VER-related changes
Summary: Cleaner to isolate the #ifdefs to a constant than different code based on platform.
Reviewed By: yfeldblum, Orvid
Differential Revision:
D4179949
fbshipit-source-id:
5b9975a78cf234f29a379c1dbe489373b7f1c253
Andrii Grynenko [Tue, 15 Nov 2016 02:13:02 +0000 (18:13 -0800)]
Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This is useful to add more TimeoutManager implementations.
Reviewed By: yfeldblum
Differential Revision:
D4178511
fbshipit-source-id:
9167cfe40e7487da1c35c537f9db8a2bdf085626
Andrii Grynenko [Tue, 15 Nov 2016 02:07:46 +0000 (18:07 -0800)]
Make Observer stress test pass a stress run
Reviewed By: yfeldblum
Differential Revision:
D4179908
fbshipit-source-id:
493b302cd7e9f7ebc851599b2ca5988af817387d
yizhiren [Tue, 15 Nov 2016 00:19:37 +0000 (16:19 -0800)]
correct the description about the thread to run
Summary:
exchange A and B in this sentence :
"Or, maybe x will execute in Thread B, but y and/or z will execute in Thread A".
I think x in B and y,z in A is impossible. but x in A and y,z in B is possible, in that example.
Closes https://github.com/facebook/folly/pull/514
Reviewed By: yfeldblum
Differential Revision:
D4176766
Pulled By: Orvid
fbshipit-source-id:
cf3a47a30d7e43e5291d6b6401198025beba33f8
Alejandro Peláez [Mon, 14 Nov 2016 00:19:32 +0000 (16:19 -0800)]
Revert
D4164236: [EventBase] Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This reverts commit
5f2057f6ebfbdc971bc0b5594e3bc4b5a337aaef
Differential Revision:
D4164236
fbshipit-source-id:
a397e6ba8c9d7a691cc6381b8f60bfcea3eb91b0
Subodh Iyengar [Sun, 13 Nov 2016 01:13:44 +0000 (17:13 -0800)]
Add ecdsa smart ptr
Summary: Add ecdsa smart ptr.
Reviewed By: knekritz
Differential Revision:
D4173310
fbshipit-source-id:
abd5f799b3414b70128635c4390af6f2de329e11
Andrii Grynenko [Sat, 12 Nov 2016 03:49:34 +0000 (19:49 -0800)]
Move runAfterDelay/tryRunAfterDelay into TimeoutManager
Summary: This is useful to add more TimeoutManager implementations.
Reviewed By: yfeldblum
Differential Revision:
D4164236
fbshipit-source-id:
5f2057f6ebfbdc971bc0b5594e3bc4b5a337aaef
Marcin Pawlowski [Sat, 12 Nov 2016 02:37:38 +0000 (18:37 -0800)]
try to improve folly/io/async/test:async_test - AsyncSocketTest.Write
Summary:
the test fails a lot as seen on the task.
To kill the connection in said test, we depeneded
on destructor, however this uses a delayed destruction
patter so I guess we did not destroy on time and
we were failing the tests.
I close socket explicitly. No idea if this misses
the point of whole test.
Reviewed By: yfeldblum
Differential Revision:
D4171111
fbshipit-source-id:
01b8c97a04a2bcdfaeeea522ca8bcae343d6bb5d
Mirek Klimos [Sat, 12 Nov 2016 02:17:17 +0000 (18:17 -0800)]
Revert DLOG_INFO warnings about RequestContext being overriden
Summary: This is causing a log spew on some services, let's remove it until we figure out where the problem is and fix
Differential Revision:
D4171379
fbshipit-source-id:
2afdab6917a2498c376559f9171f6e93ab9c8ad7
Andrii Grynenko [Sat, 12 Nov 2016 02:12:11 +0000 (18:12 -0800)]
Make Observer.Stress test not fail under load
Reviewed By: marcinpe
Differential Revision:
D4171655
fbshipit-source-id:
e6ef33c50d5d91e05250520171c959a893470460
Martin Martin [Sat, 12 Nov 2016 00:08:46 +0000 (16:08 -0800)]
When you read from a default-constructed MPMCQueue, assert instead of SIGFPE.
Summary:
I accidentally forgot to specify the capacity for my
MPMCQueue. When I then did a blockingRead(), I got a SIGFPE. Thanks
to a custom signal handler that doesn't print stack traces, and a few
more comedy of errors, I lost a day to this. With this patch, I would
have gotten an assertion failure instead.
Reviewed By: yfeldblum
Differential Revision:
D4169033
fbshipit-source-id:
fab97ea0d5afc3c06885758b31a5e8c91ae75a45
Mirek Klimos [Fri, 11 Nov 2016 19:15:55 +0000 (11:15 -0800)]
Add warnings when overriding RequestContext
Summary: We currently store the previous value on creation of RequestContextScopeGuard and reset it to the previous one when it goes out of scope - this means that if it's not unset properly somewhere, we'll prolong its life by saving it and restoring later. We need to do this because of some edge cases but a RequestContext should generally never be overridden by a different RequestContext - let's add a warning if this happens
Reviewed By: djwatson, palmtenor
Differential Revision:
D3971904
fbshipit-source-id:
e72b5f01102d18977d8aa5f8dca5a7802545098a
Andrew Gallagher [Fri, 11 Nov 2016 06:44:43 +0000 (22:44 -0800)]
folly/test/SingletonTestStructs: move inlined function to impl file
Reviewed By: yfeldblum
Differential Revision:
D4162763
fbshipit-source-id:
25c9bfae2e7679f4b98a3d64ee9f2319eb6e7f4a
Yedidya Feldblum [Fri, 11 Nov 2016 06:02:17 +0000 (22:02 -0800)]
Let folly::range(const std::array<...>&) be constexpr
Summary:
[Folly] Let `folly::range(const std::array<...>&)` be `constexpr`.
This may be useful for future work.
Reviewed By: simpkins
Differential Revision:
D4165608
fbshipit-source-id:
8f1064c3cdc07301e198acd596ff26724d603cdd
Jim Meyering [Fri, 11 Nov 2016 00:50:45 +0000 (16:50 -0800)]
folly/Foreach.h: fix FOR_EACH_R and FOR_EACH_KV to avoid shadowing warnings
Summary:
Fix these macros not to self-shadow for nested uses.
How? Make each local variable name include __LINE__.
This works in most cases, but not all: if you put the
nested uses all on one line, you'll still get shadowing warnings.
Reviewed By: yfeldblum
Differential Revision:
D4161553
fbshipit-source-id:
9e11ae6778272c733a4c820cfb30c5db59998a5b
Christopher Dykes [Thu, 10 Nov 2016 20:46:19 +0000 (12:46 -0800)]
Always use inline-asm version on GCC/Clang
Summary:
Because the intrinsic version requires explicitly adding `__target__` attributes, which results in things not being inlined. Although the code generated with the `__target__` attribute is strictly better, ensuring it's applied on all the relevant functions is error-prone, so just use the inline assembly version for GCC/Clang so that it can be inlined elsewhere. MSVC will inline the intrinsic version without any issue.
This also marks the functions as `ALWAYS_INLINE`, as the diff that is getting reverted made that change as well.
Reviewed By: yfeldblum, philippv, ot
Differential Revision:
D3963935
fbshipit-source-id:
47175d64e7be351eb455a4d053b91ce9392bf152
Tudor Bosman [Thu, 10 Nov 2016 20:40:38 +0000 (12:40 -0800)]
Add include files necessary to use symbolizer
Summary:
Some include files are not installed, causing including symbolizer/Symbolizer.h to fail.
Closes https://github.com/facebook/folly/pull/512
Reviewed By: philippv
Differential Revision:
D4161113
Pulled By: luciang
fbshipit-source-id:
5a5f8577f8d84ba33f89073781d374b99ba37df6
Christopher Dykes [Thu, 10 Nov 2016 20:32:51 +0000 (12:32 -0800)]
Don't try to call _free_osfhnd when not compiling agains the static CRT
Summary:
Because, unfortunately, it isn't exported from the dynamic CRT dlls :(
There's not really a nice way to handle this when using the dynamic CRT without doing very fragile hocus-pocus that relies on the exact layout and implementation details of the file descriptor table in the CRT, so the best we can really do is close the socket and just let the file descriptor itself leak.
Reviewed By: yfeldblum
Differential Revision:
D4156558
fbshipit-source-id:
32cb4bf357f6746cf6597b66649ff9f018fb1bed
Phil Willoughby [Thu, 10 Nov 2016 12:09:21 +0000 (04:09 -0800)]
Use std::cerr for folly/Singleton.cpp error printing
Summary:
Create a local std::ios_base::Init instance to ensure that it is valid, then
use std::cerr.
Reviewed By: yfeldblum, nbronson
Differential Revision:
D4139681
fbshipit-source-id:
03377dd417710e320a6b53298d507fd0168592f6
Andrii Grynenko [Thu, 10 Nov 2016 04:19:57 +0000 (20:19 -0800)]
Fix wrong use of upgrade lock
Reviewed By: yfeldblum, nbronson
Differential Revision:
D4149681
fbshipit-source-id:
37bd1b0b7d1ad6e6fa813228307abebfe772012f
Christopher Dykes [Wed, 9 Nov 2016 23:13:35 +0000 (15:13 -0800)]
Don't try to install the failure signal handler in folly::init on Windows
Summary: Because GTest doesn't support it on platforms that don't implement `sigaction`.
Reviewed By: yfeldblum
Differential Revision:
D4155882
fbshipit-source-id:
fe8df316242b293afaf94c2a5d0f8a5e60b51285
Christopher Dykes [Wed, 9 Nov 2016 23:13:25 +0000 (15:13 -0800)]
Disable a couple of warnings generated by the GTest and GMock headers
Summary: As the comment says, this disables a couple of warnings related to exporting classes derived from stdlib classes that aren't explicitly exported.
Reviewed By: yfeldblum
Differential Revision:
D4155978
fbshipit-source-id:
6e732b53c280a3bc3a39b2128cd577ba7cb70408
Christopher Dykes [Wed, 9 Nov 2016 22:35:17 +0000 (14:35 -0800)]
Don't generate empty statements in DeterministicScheduleTest
Summary: Because MSVC generates warnings if you have a control-flow statement followed by a single trailing semicolon.
Reviewed By: yfeldblum
Differential Revision:
D4155588
fbshipit-source-id:
dfd8774fc6a62675764f7e069c26b799b622a9af
Christopher Dykes [Wed, 9 Nov 2016 22:31:44 +0000 (14:31 -0800)]
Request lower privilege crypt context when generating random numbers
Summary: Without this flag, we were unintentionally requesting a context with access to private keys.
Reviewed By: yfeldblum
Differential Revision:
D4155525
fbshipit-source-id:
f33d18451b06e32b81d03bf6180efc1671cfa204
Christopher Dykes [Wed, 9 Nov 2016 19:20:55 +0000 (11:20 -0800)]
Use ASSERT_EQ rather than CHECK_EQ in the socket tests
Summary: Because `CHECK_EQ` is a fatal error, and makes it impossible to keep running the other tests if it fails, even if it was just a timeout.
Reviewed By: yfeldblum
Differential Revision:
D4151084
fbshipit-source-id:
db88dc2ef875e5d1fe31792f26a3dc2d223ded5e
Christopher Dykes [Wed, 9 Nov 2016 19:07:51 +0000 (11:07 -0800)]
Split the benchmarks out of UriTest
Summary: So that they can be run independently of the tests.
Reviewed By: yfeldblum
Differential Revision:
D4150331
fbshipit-source-id:
3ab39024795add84885436b757f2505527297a3d
Christopher Dykes [Wed, 9 Nov 2016 19:07:23 +0000 (11:07 -0800)]
Return the correct resolution for clock_getres
Summary: When the implementation of `clock_gettime` for `REALTIME` and `MONOTONIC` was switched to use `std::chrono`, this didn't get switched over to the resolution of the new implementation.
Reviewed By: yfeldblum
Differential Revision:
D4150297
fbshipit-source-id:
a4578af85cae538a3ebb6da7e759058927c31d3e
Ali Zaveri [Wed, 9 Nov 2016 08:29:32 +0000 (00:29 -0800)]
Expose isFamilyInet() to check if SocketAddress is a valid ipv4 or ipv6
Summary: Expose isFamilyInet() in SocketAddress. This cleans up code and provides a way to validate if SocketAddress is a ipv4 or ipv6
Differential Revision:
D4150650
fbshipit-source-id:
dc8883e904b6577fc27bdd54064fcc50de93b0d2
Christopher Dykes [Tue, 8 Nov 2016 18:40:14 +0000 (10:40 -0800)]
Make NeedleFinderTest::Needles256 actually do things
Summary:
The min value of a `char` is `-128`, but we're initializing our `size_t` i's with it, so, as MSVC quite rightly warns (as C6294) the condition is never true and the loop never loops.
Fix it by signing our i's.
Reviewed By: yfeldblum
Differential Revision:
D4145419
fbshipit-source-id:
87591d0f84c54472b1b5847e025d091de3f98bca
James Sedgwick [Tue, 8 Nov 2016 07:13:30 +0000 (23:13 -0800)]
add tryReadUntil and make fixes along the way
Summary:
this diff adds tryReadUntil, which is a mirror of tryWriteUntil in both function and implementation.
Two bugs were exposed in the process of implementing and testing tryWriteUntil; they are fixed as well and are as follows:
1. tryObtainPromisedPopTicket didn't assign to the passed ticket return reference in the failure case
2. TurnSequencer::tryWaitForTurn() didn't distinguish between past turns and timeouts in the failure case; they need to be
differentiated because SingleElementQueue::tryWaitFor{De/En}queue() should only fail in the timeout case, not if the turn has passed.
The two added unit tests are admittedly clumsy, but making the obvious simplifications to them keeps them from triggering the premature timeout race caused by bug 2 above, so I kept them as is.
Reviewed By: magedm
Differential Revision:
D4050515
fbshipit-source-id:
b0a3dd894d502c44be62d362ea347a1837df4c2f
Andrew Gallagher [Tue, 8 Nov 2016 00:10:41 +0000 (16:10 -0800)]
Mark implicitly inlined static locals with default visibility
Summary:
These functions contain static locals which need to be exported to
the global dynamic symbol table to get deduplicated at runtime. Since
using `-fvisibility-inlines-hidden` demotes the visibility of these
static locals, explicitly tag them.
Reviewed By: yfeldblum
Differential Revision:
D4139154
fbshipit-source-id:
08b81721c6c945ac5556472481ae771d0eeb5f88
Stepan Palamarchuk [Mon, 7 Nov 2016 20:37:52 +0000 (12:37 -0800)]
Remove noexcept from AsyncSocket::prepareReadBuffer
Summary:
`prepareReadBuffer` is calling a callback function that is not a noexcept
also `prepareReadBuffer` is being called only from one place, that wraps this function call with try/catch.
Reviewed By: jmswen
Differential Revision:
D4138424
fbshipit-source-id:
a05bdd6f741761567a7d0291017c285b0bf15522
Andrew Gallagher [Mon, 7 Nov 2016 04:06:46 +0000 (20:06 -0800)]
Annotate some static locals as "library-local"
Summary:
This tags certain static locals, wich may get duplicated via dynamic
linking and inlining, as safe to have multiple copies at runtime,
making this subtle behavior explicit.
Reviewed By: igorsugak
Differential Revision:
D4082929
fbshipit-source-id:
ba4e23cb121e957a43f5659a1ca3432cb89cb8f3
Yedidya Feldblum [Sun, 6 Nov 2016 21:09:44 +0000 (13:09 -0800)]
Let folly::range be constexpr
Summary:
[Folly] Let `folly::range` be `constexpr`.
It will be useful to have this helper function be `constexpr` to support further compile-time code.
Reviewed By: juchem
Differential Revision:
D4135943
fbshipit-source-id:
a62be93f9e492ca302130d1a3b190ed4b69f7a80
Christopher Small [Sat, 5 Nov 2016 19:36:36 +0000 (12:36 -0700)]
operator== for ReadMostlySharedPtr to nullptr_t
Summary: add operator== against nullptr_t for ReadMostlySharedPtr
Reviewed By: andriigrynenko, nbronson, yfeldblum
Differential Revision:
D4128722
fbshipit-source-id:
40d08bb85bfe2f96ad4ed4995f5829e0616d0661
Zach Amsden [Fri, 4 Nov 2016 19:59:59 +0000 (12:59 -0700)]
Add StringKeyedMap/Set.h to OSS build
Summary: Eden uses this and won't build with OSS folly without it.
Reviewed By: Orvid
Differential Revision:
D4132103
fbshipit-source-id:
68d6c7dc642a7401eca60b0713db9f90cc11ced1
Mirek Klimos [Fri, 4 Nov 2016 18:10:46 +0000 (11:10 -0700)]
Trying to improve the efficiency of RequestContext callbacks
Summary: Changed RWSpinLock to a SharedMutex in the RequestContext to see if this would lower the overhead of the onSet/onUnset callbacks.
Reviewed By: djwatson
Differential Revision:
D3780396
fbshipit-source-id:
3d91f8194357533072fe053d23e0454a36faecff