-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make multi-thread scheduler an action
- Loading branch information
Showing
8 changed files
with
297 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Created by Darwin Yuan on 2020/7/4. | ||
// | ||
|
||
#ifndef TRANS_DSL_2_TRANSACTION_H | ||
#define TRANS_DSL_2_TRANSACTION_H | ||
|
||
#include <trans-dsl/tsl_ns.h> | ||
#include <trans-dsl/sched/domain/MultiThreadContext.h> | ||
#include <trans-dsl/sched/domain/TransactionContext.h> | ||
#include <cstddef> | ||
#include <trans-dsl/sched/domain/Event.h> | ||
#include <trans-dsl/utils/ThreadActionTrait.h> | ||
|
||
TSL_NS_BEGIN | ||
|
||
template<typename SCHED> | ||
struct Transaction : private TransactionContext, private SCHED { | ||
using TransactionContext::updateInstanceId; | ||
using TransactionContext::updateUserContext; | ||
using TransactionContext::updateTimerInfo; | ||
using TransactionContext::updateListener; | ||
|
||
auto start() -> Status { | ||
return SCHED::start(*this); | ||
} | ||
|
||
auto startWithEvent(Event const& event) -> Status { | ||
Status status = SCHED::start(*this); | ||
if(status == Result::CONTINUE) { | ||
return SCHED::handleEvent(*this, event); | ||
} | ||
} | ||
|
||
auto handleEvent(Event const& event) -> Status { | ||
return SCHED::handleEvent(*this, event); | ||
} | ||
|
||
auto stop(Status cause) -> Status { | ||
return SCHED::stop(*this, cause); | ||
} | ||
|
||
auto kill(Status cause) -> void { | ||
SCHED::kill(*this, cause); | ||
} | ||
}; | ||
|
||
TSL_NS_END | ||
|
||
#endif //TRANS_DSL_2_TRANSACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// Created by Darwin Yuan on 2020/7/4. | ||
// | ||
|
||
#ifndef TRANS_DSL_2_MULTITHREADHELPER_H | ||
#define TRANS_DSL_2_MULTITHREADHELPER_H | ||
|
||
#include <trans-dsl/tsl_ns.h> | ||
#include <trans-dsl/sched/action/SchedMultiThreadAction.h> | ||
#include <trans-dsl/utils/ThreadActionTrait.h> | ||
|
||
TSL_NS_BEGIN | ||
|
||
namespace details { | ||
template<typename MAIN_ACTION> | ||
struct MultiThread : SchedMultiThreadAction { | ||
auto start(TransactionContext& context) -> Status { | ||
return SchedMultiThreadAction::start(context, mainThreadAction); | ||
} | ||
|
||
private: | ||
OVERRIDE(createThread(ThreadId tid) -> SchedAction*) { | ||
return threadCreator.createThreadAction(tid); | ||
} | ||
|
||
OVERRIDE(getMaxThreads() const -> uint8_t) { | ||
return MAX_NUM_OF_THREADS; | ||
} | ||
|
||
OVERRIDE(getThreads() -> Threads) { | ||
return threads; | ||
} | ||
|
||
enum : uint8_t { MAX_NUM_OF_THREADS = details::FinalThreadCreator<MAIN_ACTION>::threadId + 1 }; | ||
static_assert(MAX_NUM_OF_THREADS <= ThreadBitMap::max, "the specified tid is out of scope"); | ||
SchedAction* threads[MAX_NUM_OF_THREADS]{}; | ||
MAIN_ACTION mainThreadAction; | ||
details::FinalThreadCreator<MAIN_ACTION> threadCreator; | ||
}; | ||
} | ||
|
||
TSL_NS_END | ||
|
||
#define __multi_thread(...) TSL_NS::details::MultiThread<__VA_ARGS__> | ||
|
||
#endif //TRANS_DSL_2_MULTITHREADHELPER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Created by Darwin Yuan on 2020/7/4. | ||
// | ||
|
||
#ifndef TRANS_DSL_2_TRANSACTIONHELPER_H | ||
#define TRANS_DSL_2_TRANSACTIONHELPER_H | ||
|
||
#include <trans-dsl/sched/action/Transaction.h> | ||
#include <trans-dsl/sched/action/SchedMultiThreadAction.h> | ||
|
||
#define __transaction(...) TSL_NS::Transaction<__VA_ARGS__> | ||
#define __mt_transaction(...) __transaction(GenericMultiThreadScheduler<__VA_ARGS__>) | ||
|
||
#endif //TRANS_DSL_2_TRANSACTIONHELPER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.