Skip to content

Commit

Permalink
Split EventBaseThread from ScopedEventBaseThread
Browse files Browse the repository at this point in the history
Summary:
[Folly] Split `EventBaseThread` from `ScopedEventBaseThread`.

Now `ScopedEventBaseThread` is really scoped and immovable, while `EventBaseThread` is movable and can be started and stopped.

Users which will never move, and will never start or stop, the `ScopedEventBaseThread` can continue using it. Users which need to move, or which need to start and stop, the object will use `EventBaseThread` instead.

Reviewed By: andriigrynenko

Differential Revision: D4338447

fbshipit-source-id: 57c186630bc199a7a7b7223b1fcb077ce3d86743
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Dec 17, 2016
1 parent 69a585a commit 952b773
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions mcrouter/CarbonRouterInstanceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <memory>
#include <unordered_map>

#include <folly/io/async/ScopedEventBaseThread.h>
#include <folly/io/async/EventBaseThread.h>

#include "mcrouter/ConfigApi.h"
#include "mcrouter/LeaseTokenMap.h"
Expand Down Expand Up @@ -142,7 +142,7 @@ class CarbonRouterInstanceBase {
const std::unique_ptr<AsyncWriter> asyncWriter_;

// Auxiliary EventBase thread.
folly::ScopedEventBaseThread evbAuxiliaryThread_;
folly::EventBaseThread evbAuxiliaryThread_;

LogPostprocessCallbackFunc postprocessCallback_;

Expand Down
2 changes: 1 addition & 1 deletion mcrouter/LeaseTokenMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline uint64_t applyMagic(uint32_t id) {

} // anonymous

LeaseTokenMap::LeaseTokenMap(folly::ScopedEventBaseThread& evbThread,
LeaseTokenMap::LeaseTokenMap(folly::EventBaseThread& evbThread,
uint32_t leaseTokenTtl)
: evbThread_(evbThread),
timeoutHandler_(*this, *evbThread.getEventBase()),
Expand Down
6 changes: 3 additions & 3 deletions mcrouter/LeaseTokenMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <folly/IntrusiveList.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/ScopedEventBaseThread.h>
#include <folly/io/async/EventBaseThread.h>
#include <folly/Optional.h>
#include <folly/Range.h>

Expand All @@ -43,7 +43,7 @@ class LeaseTokenMap {
* @param leaseTokenTtl How many milliseconds the lease token will live.
* Must be greater than 0.
*/
explicit LeaseTokenMap(folly::ScopedEventBaseThread& evbThread,
explicit LeaseTokenMap(folly::EventBaseThread& evbThread,
uint32_t leaseTokenTtl = 10000);
~LeaseTokenMap();

Expand Down Expand Up @@ -144,7 +144,7 @@ class LeaseTokenMap {
private:
LeaseTokenMap& parent_;
};
folly::ScopedEventBaseThread& evbThread_;
folly::EventBaseThread& evbThread_;
TimeoutHandler timeoutHandler_;
uint32_t leaseTokenTtlMs_;

Expand Down
3 changes: 1 addition & 2 deletions mcrouter/lib/network/AsyncMcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ AsyncMcServer::AsyncMcServer(Options opts)
: opts_(std::move(opts)) {
if (opts_.congestionController.cpuControlTarget > 0 ||
opts_.congestionController.memControlTarget > 0) {
auxiliaryEvbThread_ =
folly::make_unique<folly::ScopedEventBaseThread>(true /* auto start */);
auxiliaryEvbThread_ = folly::make_unique<folly::ScopedEventBaseThread>();

if (opts_.congestionController.cpuControlTarget > 0) {
opts_.worker.cpuController = std::make_shared<CpuController>(
Expand Down
12 changes: 6 additions & 6 deletions mcrouter/test/cpp_unit_tests/LeaseTokenMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <gtest/gtest.h>

#include <folly/io/async/EventBase.h>
#include <folly/io/async/ScopedEventBaseThread.h>
#include <folly/io/async/EventBaseThread.h>
#include <folly/Optional.h>

#include "mcrouter/LeaseTokenMap.h"
Expand All @@ -41,7 +41,7 @@ void assertQueryFalse(LeaseTokenMap& map, std::string routeName,
} // anonymous namespace

TEST(LeaseTokenMap, sanity) {
folly::ScopedEventBaseThread evbAuxThread;
folly::EventBaseThread evbAuxThread;
LeaseTokenMap map(evbAuxThread);

EXPECT_EQ(map.size(), 0);
Expand All @@ -67,7 +67,7 @@ TEST(LeaseTokenMap, magicConflict) {
// by memcached) that contains our "magic", LeaseTokenMap should handle it
// gracefully.

folly::ScopedEventBaseThread evbAuxThread;
folly::EventBaseThread evbAuxThread;
LeaseTokenMap map(evbAuxThread);

EXPECT_EQ(map.size(), 0);
Expand All @@ -85,7 +85,7 @@ TEST(LeaseTokenMap, nestedRoutes) {
// Simulates the following routing:
// proxyRoute -> failover:route02 -> failover:route01 -> destinationRoute

folly::ScopedEventBaseThread evbAuxThread;
folly::EventBaseThread evbAuxThread;
LeaseTokenMap map(evbAuxThread);

// LEASE-GET
Expand All @@ -107,7 +107,7 @@ TEST(LeaseTokenMap, nestedRoutes) {

TEST(LeaseTokenMap, shrink) {
size_t tokenTtl = 100;
folly::ScopedEventBaseThread evbAuxThread;
folly::EventBaseThread evbAuxThread;
LeaseTokenMap map(evbAuxThread, tokenTtl);

EXPECT_EQ(map.size(), 0);
Expand All @@ -125,7 +125,7 @@ TEST(LeaseTokenMap, shrink) {

TEST(LeaseTokenMap, stress) {
size_t tokenTtl = 1000;
folly::ScopedEventBaseThread evbAuxThread;
folly::EventBaseThread evbAuxThread;
LeaseTokenMap map(evbAuxThread, tokenTtl);

EXPECT_EQ(map.size(), 0);
Expand Down

0 comments on commit 952b773

Please sign in to comment.