Skip to content

Commit b4d8109

Browse files
committed
doc: add doxygen documentation to round_robin_scheduling.cpp
1 parent 4885fac commit b4d8109

File tree

1 file changed

+80
-5
lines changed

1 file changed

+80
-5
lines changed

cpu_scheduling_algorithms/round_robin_scheduling.cpp

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* @file
3+
* @brief Implementation of Round Robin CPU scheduling algorithm
4+
* @details
5+
* Round-robin is a preemptive CPU scheduling algorithm where each
6+
* ready task runs turn by turn only in a cyclic queue for a limited
7+
* time slice. This algorithm also offers starvation free execution
8+
* of processes.
9+
* @author [Daemon19](https://github.com/Daemon19)
10+
*/
11+
112
#include <iomanip>
213
#include <cassert>
314
#include <string>
@@ -7,23 +18,43 @@
718
#include <utility>
819
#include <vector>
920

21+
/**
22+
* @brief Represent a process to be executed.
23+
*/
1024
struct Process {
1125
uint32_t id;
1226
uint32_t arrival_time;
1327
uint32_t burst_time;
1428
};
1529

30+
/**
31+
* @brief Represent the result of a process execution.
32+
*/
1633
struct ProcessResult : public Process {
1734
uint32_t completion_time;
1835
uint32_t turn_around_time;
1936
uint32_t waiting_time;
2037

38+
/**
39+
* @brief Constructor that calculate member variables based on a
40+
* process and completion time.
41+
*
42+
* \param process A process that have been executed
43+
* \param completion_time The process execution finish time
44+
*/
2145
ProcessResult(const Process& process, uint32_t completion_time)
2246
: Process(process), completion_time(completion_time) {
2347
turn_around_time = completion_time - arrival_time;
2448
waiting_time = turn_around_time - burst_time;
2549
}
2650

51+
/**
52+
* @brief Compare each member variable.
53+
*
54+
* \param p ProcessResult to be compared with
55+
* \return true if the processes IS equal
56+
* \return false if the processes IS NOT equal
57+
*/
2758
bool operator==(const ProcessResult& p) const {
2859
return id == p.id && arrival_time == p.arrival_time &&
2960
burst_time == p.burst_time &&
@@ -33,16 +64,65 @@ struct ProcessResult : public Process {
3364
}
3465
};
3566

67+
/**
68+
* @brief Execute processes based on Round-robin algorithm.
69+
*
70+
* \param processes Processes to be executed
71+
* \param time_slice Time slice for processes execution
72+
* \return Results of each process execution
73+
*/
3674
std::vector<ProcessResult> RRExecute(const std::vector<Process>& processes,
3775
uint32_t time_slice);
76+
77+
/**
78+
* @brief Print a table containing process results data.
79+
*
80+
* \return ostream inputted ostream
81+
*/
3882
std::ostream& operator<<(std::ostream& ostream,
3983
const std::vector<ProcessResult>& results);
84+
85+
/**
86+
* @brief Self-test implementations.
87+
*
88+
* \returns void
89+
*/
4090
void Test();
4191

92+
93+
/**
94+
* @brief Comparator function for sorting processes.
95+
*
96+
* \param p1 Process to be compared
97+
* \param p2 Process to be compared
98+
* \return
99+
*/
42100
bool CompareAT(const Process& p1, const Process& p2) {
43101
return p1.arrival_time < p2.arrival_time;
44102
}
45103

104+
/**
105+
* @brief Check processes that arrive after the given time_elapsed.
106+
*
107+
* If a process arrive after the give time_elapsed, then the process
108+
* will be pushed into the schedule queue and inserted into the
109+
* arrived_process set.
110+
*
111+
* \param processes Processes that will be checked for arrival
112+
* \param arrived_process A set containing processes that has arrived
113+
* \param schedule Queue containing pair of process and its remaining burst time
114+
* \param time_elapsed Time that has elapsed after processes execution
115+
*/
116+
void CheckArriveProcess(const std::vector<Process>& processes,
117+
std::set<uint32_t>& arrived_process,
118+
std::queue<std::pair<Process, uint32_t>>& schedule,
119+
uint32_t time_elapsed);
120+
121+
/**
122+
* @brief Entry point of the program.
123+
*
124+
* \return 0 on exit
125+
*/
46126
int main() {
47127
Test();
48128
return 0;
@@ -68,11 +148,6 @@ void Test() {
68148
std::cout << "All test passed";
69149
}
70150

71-
void CheckArriveProcess(const std::vector<Process>& processes,
72-
std::set<uint32_t>& arrived_process,
73-
std::queue<std::pair<Process, uint32_t>>& schedule,
74-
uint32_t time_elapsed);
75-
76151
std::vector<ProcessResult> RRExecute(const std::vector<Process>& processes,
77152
uint32_t time_slice) {
78153
std::vector<Process> sorted_processes = processes;

0 commit comments

Comments
 (0)