Skip to content

Commit

Permalink
refactor: remove MoveWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
chloro-pn committed Dec 11, 2023
1 parent cdea234 commit 531d8a9
Show file tree
Hide file tree
Showing 6 changed files with 578 additions and 58 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ else()
-D__STDC_LIMIT_MACROS
-g
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
list(APPEND CXX_FLAGS -Wno-uninitialized)
else()
list(APPEND CXX_FLAGS -Wno-maybe-uninitialized)
endif()
endif()

set(IS_ACC OFF CACHE INTERNAL "Whether the current compiler is ACC")
Expand Down
13 changes: 6 additions & 7 deletions async_simple/FutureState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include <thread>
#include "async_simple/Common.h"
#include "async_simple/Executor.h"
#include "async_simple/MoveWrapper.h"
#include "async_simple/Try.h"
#include "async_simple/util/move_only_function.h"

namespace async_simple {

Expand Down Expand Up @@ -62,7 +62,7 @@ constexpr State operator&(State lhs, State rhs) {
template <typename T>
class FutureState {
private:
using Continuation = std::function<void(Try<T>&& value)>;
using Continuation = util::move_only_function<void(Try<T>&& value)>;

private:
// A helper to help FutureState to count the references to guarantee
Expand Down Expand Up @@ -228,11 +228,10 @@ class FutureState {
void setContinuation(F&& func) {
logicAssert(!hasContinuation(),
"FutureState already has a continuation");
MoveWrapper<F> lambdaFunc(std::move(func));
new (&_continuation) Continuation([lambdaFunc](Try<T>&& v) mutable {
auto& lambda = lambdaFunc.get();
lambda(std::forward<Try<T>>(v));
});
new (&_continuation)
Continuation([func = std::move(func)](Try<T>&& v) mutable {
func(std::forward<Try<T>>(v));
});

auto state = _state.load(std::memory_order_acquire);
switch (state) {
Expand Down
1 change: 0 additions & 1 deletion async_simple/LocalState.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <utility>
#include "async_simple/Common.h"
#include "async_simple/Executor.h"
#include "async_simple/MoveWrapper.h"
#include "async_simple/Try.h"

namespace async_simple {
Expand Down
50 changes: 0 additions & 50 deletions async_simple/MoveWrapper.h

This file was deleted.

Loading

0 comments on commit 531d8a9

Please sign in to comment.