60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#include <cstdlib>
|
|
#include "graph.hpp"
|
|
|
|
/* reducible:
|
|
Perform the graph reduction algorithm on the adjacency matrix to detect deadlocks
|
|
This algorithm is described in section 5.2 of the Zybook
|
|
(!THIS MODIFIES THE GRAPH!)
|
|
@params: none, uses class-internal data
|
|
@returns:
|
|
bool:
|
|
false if graph is not reducible (deadlock)
|
|
true if graph is reducible (no deadlock)
|
|
*/
|
|
bool graph::reducible() {
|
|
// TODO: Implement a function which checks if a process is blocked
|
|
// TODO: Use that function to implement the graph reduction algorithm
|
|
//? Make sure when reducing the graph, you don't try to delete the
|
|
return false;
|
|
}
|
|
|
|
/* knotted:
|
|
Perform the knot detection algorithm on the adjacency matrix to detect deadlocks
|
|
(!THIS MODIFIES THE GRAPH!)
|
|
@params: none, uses class-internal data
|
|
@returns:
|
|
int:
|
|
true if graph is knotted (deadlock)
|
|
false if graph is not (no deadlock)
|
|
*/
|
|
bool graph::knotted() {
|
|
return false;
|
|
}
|
|
|
|
graph::graph (const int processes, const int resources) {
|
|
num_processes = processes;
|
|
num_resources = resources;
|
|
matrix.x = processes + resources;
|
|
matrix.y = matrix.x;
|
|
matrix.data = new int*[matrix.x];
|
|
for (int x = 0; x < matrix.x; x++) {
|
|
matrix.data[x] = new int[matrix.y];
|
|
}
|
|
}
|
|
|
|
graph::~graph() {
|
|
/* clean up the 2D matrix */
|
|
if (matrix.data) {
|
|
if (matrix.x || matrix.y) {
|
|
// delete y axes
|
|
for (int x = 0; x < matrix.x; x++) {
|
|
delete matrix.data[x];
|
|
}
|
|
// delete x axis
|
|
delete matrix.data;
|
|
matrix.x = 0; matrix.y = 0;
|
|
}
|
|
}
|
|
free(resource_counts);
|
|
}
|