Skip to content

Commit

Permalink
Use folly::Function in folly::EventBase
Browse files Browse the repository at this point in the history
Summary:[Folly] Use `folly::Function` in `folly::EventBase`.

`folly::Function` is moveable but noncopyable and therefore supports wrapping moveable but noncopyable lambdas - like the kind that arises when move-capturing a `std::unique_ptr`.

`std::function` is copyable - therefore it does not support wrapping such noncopyable lambdas.

Switching `folly::EventBase` to use it will allow callers to pass such noncopyable lambdas, allowing, e.g.:

```
auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable
folly::EventBase eb;
eb.runInLoop([numptr = std::move(numptr)] { // therefore lambda is noncopyable
  int num = *numptr;
});
eb.loop();
```

This allows us to move away from the `folly::MoveWrapper` hack, which worked like:

```
auto numptr = folly::make_unique<int>(7); // unique_ptr is noncopyable
auto numptrw = folly::makeMoveWrapper(std::move(numptr)); // MoveWrapper is "copyable" - hacky
folly::EventBase eb;
eb.runInLoop([numptrw] { // therefore lambda is "copyable" - hacky
  int num = **numptrw;
});
```

We needed to do that hack while:

But neither condition is true anymore.

Reviewed By: spacedentist

Differential Revision: D3143931

fb-gh-sync-id: 4fbdf5fb77eb5848ed1c6de942b022382141577f
fbshipit-source-id: 4fbdf5fb77eb5848ed1c6de942b022382141577f
  • Loading branch information
yfeldblum authored and Facebook Github Bot 7 committed Apr 7, 2016
1 parent d18fc89 commit d9179d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions wangle/bootstrap/AcceptRoutingHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#pragma once

#include <folly/MoveWrapper.h>
#include <wangle/bootstrap/RoutingDataHandler.h>
#include <wangle/bootstrap/ServerBootstrap.h>
#include <wangle/channel/Pipeline.h>
Expand Down
7 changes: 4 additions & 3 deletions wangle/channel/OutputBufferingHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

#pragma once

#include <folly/MoveWrapper.h>
#include <folly/futures/SharedPromise.h>
#include <wangle/channel/Handler.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventBaseManager.h>
#include <folly/io/IOBuf.h>
#include <folly/io/IOBufQueue.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventBaseManager.h>
#include <wangle/channel/Handler.h>

namespace wangle {

Expand Down
1 change: 1 addition & 0 deletions wangle/channel/test/MockHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include <folly/MoveWrapper.h>
#include <gmock/gmock.h>
#include <wangle/channel/Handler.h>

Expand Down
1 change: 1 addition & 0 deletions wangle/concurrent/FutureExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#pragma once
#include <folly/MoveWrapper.h>
#include <folly/futures/Future.h>

namespace wangle {
Expand Down
2 changes: 2 additions & 0 deletions wangle/concurrent/PriorityThreadFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <sys/time.h>
#include <sys/resource.h>

#include <folly/MoveWrapper.h>

namespace wangle {

/**
Expand Down
11 changes: 11 additions & 0 deletions wangle/service/ExecutorFilter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/*
* Copyright (c) 2016, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/

#pragma once

#include <folly/MoveWrapper.h>
#include <wangle/service/Service.h>

namespace wangle {
Expand Down

0 comments on commit d9179d9

Please sign in to comment.