-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <Producer/Producer.hpp> | ||
|
||
Producer::Producer(std::shared_ptr<IThreadSafeQueue<ReserveTimeRecord>> inputQueue, | ||
std::shared_ptr<IThreadSafeQueue<TrafficRecord>> outputQueue) | ||
: _InputQueue(inputQueue), _OutputQueue(outputQueue) | ||
{ | ||
} | ||
|
||
void Producer::Task() | ||
{ | ||
while (IsContinue()) | ||
{ | ||
auto dequeueTimeout = std::chrono::milliseconds(1); | ||
auto reserveTimeRecordOpt = _InputQueue->Dequeue(dequeueTimeout); | ||
if (!reserveTimeRecordOpt.has_value()) | ||
{ | ||
continue; | ||
} | ||
|
||
{ | ||
auto reserveTimeRecord = reserveTimeRecordOpt.value(); | ||
auto reservationTime = reserveTimeRecord.ReservationTime(); | ||
SleepUntil(reservationTime); | ||
// When woken up, check this task should continue. | ||
if (!IsContinue()) | ||
{ | ||
continue; | ||
} | ||
|
||
auto trafficRecord = TrafficRecord(reserveTimeRecord.Data(), std::chrono::nanoseconds(0)); | ||
_OutputQueue->Enqueue(trafficRecord); | ||
} | ||
} | ||
} |
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,21 @@ | ||
#ifndef PRODUCER__PRODUCER_HPP | ||
#define PRODUCER__PRODUCER_HPP | ||
|
||
#include <Queue/IThreadSafeQueue.hpp> | ||
#include <Thread/Runnable.hpp> | ||
#include <TimingAdjuster/ReserveTimeRecord.hpp> | ||
#include <TrafficRecord.hpp> | ||
|
||
class Producer : public Thread::Runnable | ||
{ | ||
public: | ||
Producer(std::shared_ptr<IThreadSafeQueue<ReserveTimeRecord>> inputQueue, | ||
std::shared_ptr<IThreadSafeQueue<TrafficRecord>> outputQueue); | ||
virtual void Task() override; | ||
|
||
private: | ||
std::shared_ptr<IThreadSafeQueue<ReserveTimeRecord>> _InputQueue; | ||
std::shared_ptr<IThreadSafeQueue<TrafficRecord>> _OutputQueue; | ||
}; | ||
|
||
#endif |
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