DPsim
Loading...
Searching...
No Matches
ThreadScheduler.h
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#pragma once
10
11#include <dpsim/Scheduler.h>
12
13#include <thread>
14#include <vector>
15
16namespace DPsim {
17class ThreadScheduler : public Scheduler {
18public:
19 ThreadScheduler(Int threads, String outMeasurementFile,
20 Bool useConditionVariable);
21 virtual ~ThreadScheduler();
22
23 void step(Real time, Int timeStepCount);
24 virtual void stop();
25
26protected:
27 void finishSchedule(const Edges &inEdges);
28 void scheduleTask(int thread, CPS::Task::Ptr task);
29
31
32private:
33 void doStep(Int scheduleIdx);
34 static void threadFunction(ThreadScheduler *sched, Int idx);
35
36 String mOutMeasurementFile;
37 Barrier mStartBarrier;
38
39 std::vector<std::thread> mThreads;
40
41 std::vector<CPS::Task::List> mTempSchedules;
42 struct ScheduleEntry {
43 CPS::Task *task;
44 Counter endCounter;
45 std::vector<Counter *> reqCounters;
46 };
47 std::vector<ScheduleEntry *> mSchedules;
48
49 Bool mJoining = false;
50 Real mTime = 0;
51 Int mTimeStepCount = 0;
52};
53} // namespace DPsim
Tasks to be defined by every component.
Definition Task.h:25
std::shared_ptr< Task > Ptr
Definition Task.h:27
Scheduler(CPS::Logger::Level logLevel=CPS::Logger::Level::off)
Definition Scheduler.h:36
std::unordered_map< CPS::Task::Ptr, std::deque< CPS::Task::Ptr > > Edges
Definition Scheduler.h:31
virtual void stop()
Called on simulation stop to reliably clean up e.g. running helper threads.
void step(Real time, Int timeStepCount)
Performs a single simulation step.
ThreadScheduler(Int threads, String outMeasurementFile, Bool useConditionVariable)
void scheduleTask(int thread, CPS::Task::Ptr task)
void finishSchedule(const Edges &inEdges)
CPS::Real Real
Definition Definitions.h:18
CPS::String String
Definition Definitions.h:20
CPS::Int Int
Definition Definitions.h:22
CPS::Bool Bool
Definition Definitions.h:21