Skip to content

Commit

Permalink
refactoreed Wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Darwin Yuan committed Mar 29, 2021
1 parent 7969be6 commit a947973
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion include/trans-dsl/sched/helper/SafeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TSL_NS_BEGIN

namespace details {
template<typename T_ACTION>
struct Safe : SchedSafe {
struct Safe {
template<TransListenerObservedAids const& AIDs>
class ActionRealType : public SchedSafe {
using Action = ActionRealTypeTraits_t<AIDs, T_ACTION>;
Expand Down
13 changes: 8 additions & 5 deletions include/trans-dsl/sched/helper/WaitHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ TSL_NS_BEGIN

namespace details {
template<bool V_IS_WAIT, EV_NS::EventId V_EVENT_ID>
class Wait_ final : public SchedWait {
OVERRIDE(getEventId() const -> EV_NS::EventId) { return V_EVENT_ID; }
OVERRIDE(isWait() const -> bool) { return V_IS_WAIT; }
struct Wait {
template<TransListenerObservedAids const& AIDs>
class ActionRealType : public SchedWait {
OVERRIDE(getEventId() const -> EV_NS::EventId) { return V_EVENT_ID; }
OVERRIDE(isWait() const -> bool) { return V_IS_WAIT; }
};
};
}

TSL_NS_END

#define __wait(eventId) TSL_NS::details::Wait_<true, eventId>
#define __peek(eventId) TSL_NS::details::Wait_<false, eventId>
#define __wait(eventId) TSL_NS::details::Wait<true, eventId>
#define __peek(eventId) TSL_NS::details::Wait<false, eventId>

#endif //TRANS_DSL_2_WAITHELPER_H
2 changes: 1 addition & 1 deletion src/sched/action/SchedExclusive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ auto SchedExclusive::stop(TransactionContext& context, Status cause) -> Status {
likely_branch
case State::Selecting: {
(void)cleanUp(context, cause);
return Result::FORCE_STOPPED;
return cause;
}
case State::Working: {
return stopOnSelected(context, cause);
Expand Down
4 changes: 0 additions & 4 deletions src/sched/action/SchedLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ auto SchedLoop::handleEvent_(TransactionContext& context, Event const& event) ->
reportFailure(status);
}

if(stopping) {
return Result::FORCE_STOPPED;
}

return looping(context);
}

Expand Down
4 changes: 2 additions & 2 deletions src/sched/action/SchedWait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ auto SchedWait::handleEvent(TransactionContext&, Event const& event) -> Status {
}

///////////////////////////////////////////////////////////////////////////////
auto SchedWait::stop(TransactionContext&, Status) -> Status {
return Result::FORCE_STOPPED;
auto SchedWait::stop(TransactionContext&, Status cause) -> Status {
return cause;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions src/sched/domain/RuntimeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ TSL_NS_BEGIN

namespace {
bool shouldUpdate(Status current, Status newStatus) {
if(current == newStatus || !cub::is_failed_status(newStatus)) return false;
return (newStatus == Result::FORCE_STOPPED) ? current == Result::SUCCESS : true;
return (current != newStatus && cub::is_failed_status(newStatus));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ut/TestExclusive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace {
}

WHEN("invoking stop, should return OUT_OF_SCOPE") {
REQUIRE(Result::FORCE_STOPPED == action.stop(context, Result::OUT_OF_SCOPE));
REQUIRE(Result::OUT_OF_SCOPE == action.stop(context, Result::OUT_OF_SCOPE));
AND_WHEN("exec again, should return FATAL_BUG") {
REQUIRE(Result::FATAL_BUG == action.exec(context));
}
Expand Down
12 changes: 11 additions & 1 deletion tests/ut/WithIdTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <trans-dsl/trans-dsl.h>
#include "StupidTransactionContext.h"
#include "SimpleActionsDefs.h"
#include <iostream>

namespace {
using namespace TSL_NS;
Expand Down Expand Up @@ -113,5 +112,16 @@ namespace {
REQUIRE(Result::CONTINUE == trans.start());
}
}

GIVEN("a transaction has multi-with-id actions") {
__def(Trans4) __as_trans
( __with_id(4, __apply(Fork2, __with(AsyncAction1, AsyncAction4)))
, __with_id(3, __wait(EV_MSG_2)), __join()
);

using Trans2WithListener = __bind_listener(Trans4, Listeners);
Trans2WithListener trans;
REQUIRE(Result::CONTINUE == trans.start());
}
}
}

0 comments on commit a947973

Please sign in to comment.