Loop Time Summary: Only do the exponential loop smoothing once every 10ms. If we need it before then, do it linearly. Also, remove one of the now()s by only calling it once. Reviewed By: bmaurer, yfeldblum Differential Revision: D6690047 fbshipit-source-id: 8267c01064aabc17cb8e86eb888e6120c99a129f
Fix copyright lines Summary: [Folly] Fix copyright lines based on file histories. Reviewed By: spalamarchuk Differential Revision: D6720312 fbshipit-source-id: c70a667a1977e70e2d4451ea624f96163982f681
give EventBase a non-explicit default constructor Summary: Default constructors are strange and often unexpected. Refactor. Reviewed By: yfeldblum Differential Revision: D6667480 fbshipit-source-id: 24c456c46c846c61e28f1a88806d7c36d9192493
Fix RequestContext held too long issue in EventBase Summary: Upon debugging for the attached task, it appears to me the problem are in two places: . After a callback has been run, context_ wasn't reset . After a callback has been canceled, context_ wasn't reset In this diff: . Fix these two places. . Updating unit tests to cover these two cases. Reviewed By: yfeldblum Differential Revision: D6465788 fbshipit-source-id: 85b3b29dc80c9f3971c85f302385d41ded44fa0e
Improve folly::RequestContext onSet and onUnset efficiency Summary: In previous discussions, it has been pointed out that `folly::RequestContext::setContext` consumes considerable amount of CPU cycles in production environments. After some investigation, we thought that might be caused by looping over all `RequestData` instances can calling the virtual `onSet` and `onUnset` callback of them. Both the iteration and invoking virtual methods are not cheap. As you can see from this change, most of the derived classes of `RequestData` don't override the `onSet` and `onUnset` methods. Mostly likely they are only used for per-Request tracking. So the natural idea is to skip those instances when iterating and avoid the unnecessary virtual method invoke. I have explored the solution to dynamically examine if the `RequestData` instance added has `onSet` and `onUnset` method overridden. That is possible with GCC's PMF extension, but not [[ http://lists.llvm.org/pipermail/llvm-bugs/2015-July/041164.html | for Clang ]] and probably many other compilers. This definitely won't be very good for `folly`'s probability, even if we gate it by compiler flags. Therefore, this Diff adds the `hasCallback` method to `RequestData` class indicating whether the instance would have `onSet` and `onUnset` overridden. To make it clear to users that they need to correctly override it in order for their `onSet` and `onUnset` callback to work, making it abstract so that user must override it to something and would aware of that. Also made some improvements on documentation. Reviewed By: myreg Differential Revision: D6144049 fbshipit-source-id: 4c9fd72e9efaeb6763d55f63760eaf582ee4839e
Consistently have the namespace closing comment Summary: It's done in a lot of places, but not all. clang-tidy gives us llvm-namespace-comment, which can force this consistently. Reviewed By: yfeldblum Differential Revision: D6108129 fbshipit-source-id: 1b44c5a26250364f9edf70f84173e9ba6389f06c
move CallOnce to synchronization/ Summary: as above Reviewed By: knekritz Differential Revision: D6088687 fbshipit-source-id: 0efbb7f5fa33b5f553c0c2019658370fc6e8613f
move futures/DrivableExecutor to executors/DrivableExecutor Summary: as title Reviewed By: yfeldblum Differential Revision: D6062437 fbshipit-source-id: 4f99e779e280fdb0b1f035013caff18764e86ab5
Let EventBase::runInEventBaseThreadAndWait consume its argument Summary: [Folly] Let `EventBase::runInEventBaseThreadAndWait` consume its argument. Likewise `EventBase::runImmediatelyOrRunInEventBaseThreadAndWait`. And enforce that the function is destructed before returning, so that, in the case of a wrapped lambda, all captured objects' destructors run before returning from the function. Reviewed By: elsteveogrande Differential Revision: D5994106 fbshipit-source-id: 816c9431a85a3d41e4fda321065614f4c18f0697
Make keepAliveRelease consistent between EventBase and VirtualEventBase Summary: [Folly] Make `keepAliveRelease` consistent between `EventBase` and `VirtualEventBase`. Reviewed By: elsteveogrande Differential Revision: D5982132 fbshipit-source-id: 536d48e5672567e78786691bfb283c34d1f31960
Move keepalive-acquire code into Executor::keepAliveAcquire overrides Summary: [Folly] Move keepalive-acquire code into `Executor::keepAliveAcquire` overrides. This makes the API more symmetric and allows for more flexibility. Also serves as preparation for generalizing the keepalive-token interface. Reviewed By: andriigrynenko Differential Revision: D5974080 fbshipit-source-id: 26209e49a0f5834ba229d4bbfc9272c2e4ffb3fd
Let keep-alive tokens be destroyed from any thread Summary: [Folly] Let keep-alive tokens be destroyed from any thread. Reviewed By: andriigrynenko Differential Revision: D5951397 fbshipit-source-id: 91e72588de4ef33a730ebef5770e77635d4e93ba
Consistency in namespace-closing comments Summary: [Folly] Consistency in namespace-closing comments. Reviewed By: Orvid Differential Revision: D5524744 fbshipit-source-id: ced4dd2398ed6baa3ad5b68b74eee6a5d6b2b103
Sort #include lines Summary: [Folly] Sort `#include` lines, as required by `clang-format`. Reviewed By: igorsugak, Orvid Differential Revision: D5405153 fbshipit-source-id: 3bb1c2b84271bcf7a195e07680777dbfdd499823
Print expected/actual thread names when running EventBase logic in unexpected thread Summary: The existing assertion errors do not give a lot of information to track down which thread is incorrectly using the `EventBase`. Print both the current thread name and the name of the thread running the event base loop. Reviewed By: luciang Differential Revision: D5289790 fbshipit-source-id: 563c7f68b7f9b7a6e85e22290d7e81afbf89871e
apply clang-tidy modernize-use-override Summary: This is generated by applying clang-tidy -checks=modernize-use-override to all .cpp files under folly. It enforces the use of the keywords virtual, override and final in a way compliant to the style guide. Reviewed By: yfeldblum Differential Revision: D5108973 fbshipit-source-id: 61c55aa372feebe3b3be12a2705a04879aae57a4
Shift the job of defining NOMINMAX into source rather than the build system Summary: This makes it easier to consume Folly from a non-cmake project. Note that this also requires making libevent, which was previously categorized as a semi-portable header into a non-portable header, meaning it can't be referenced directly. (libevent includes `Windows.h` in one of its headers -_-....) Reviewed By: yfeldblum Differential Revision: D5106051 fbshipit-source-id: 5ce2d4188c9036d6ab206af3036c8fd4b09516a4
EventBaseLocal cleanup Summary: 1. Restrict EventBaseLocal API to only be used from EventBase thread to avoid extra locking. 2. Make sure objects stored in EventBaseLocal are destroyed in EventBase thread. Reviewed By: yfeldblum Differential Revision: D4918282 fbshipit-source-id: b7cb4c2b62fef85a9b1d796fa71af8af9087479d
Default VirtualEventBase Summary: Make each EventBase have a defuault VirtualEventBase which is attached to it and is joined on destruction. Default VirtualEventBase is lazily created on first request. This makes it trivial to use code switched to VirtualEventBase both with VirtualEventBase and EventBase. Reviewed By: yfeldblum Differential Revision: D4644639 fbshipit-source-id: cf28a3632463a1c61404c225ce1186f5a4a062a3
Add keepAlive() mechanism Summary: EventBase and VirtualEventBase already had a loopKeepAlive() mechanism, which enabled libraries to prevent EventBase/VirtualEventBase from being destroyed until all keep-alive tokens were released. This change adds generic keepAlive() support into folly::Executor. folly::Executors which don't support keep-alive mechanism yet, will just return a no-op KeepAlive token. Reviewed By: yfeldblum Differential Revision: D4516649 fbshipit-source-id: 869779621c746cb14d985aa73bc4536859914c03