So I have to write a program that mimics the operating system, such as having PCBs, ReadyQueues and DeviceQueues. Devices and DeviceQueues is where I'm having trouble understanding. So from what I know, DeviceQueues has PCBs that wait for the device, and then those PCBs goes into the ReadyQueue afterwards. I was wondering if my approach is correct. I created a DeviceQueue class that has the functions to add into the queue, pop from the queue, prints the queue and returns the front of the queue. Then in my Device class I set the name of the device and the device ID, and I also have a deviceQueue object inside my class, which would mean that my device has a queue of PCBs that can be then pushed into the ReadyQueue. My concern right now is creating a device object and placing those items into that queue. I have this function :
in another class and I don't know if that's enough to set a DeviceQueue as the Device's queue, and then when I create a new Device, I'll add the PCBs into the device.
#ifndef DEVICE_QUEUE_H
#define DEVICE_QUEUE_H
#include <list>
#include <memory>
#include "PCB.h"
class DeviceQueue{
public:
DeviceQueue(){}
~DeviceQueue(){}
void pushIntoQueue(std::shared_ptr<PCB> aPCB){
dQueue.push_back(aPCB);
}
// Gets whatever is at the front of the queue
std::shared_ptr<PCB> getFront(){
return dQueue.front();
}
// Removes the first element in the queue
void deviceQueueDequeue(){
dQueue.pop_front();
}
// Prints the numbers of the PCBs
void printDQ(){
for(std::list< std::shared_ptr<PCB> >::iterator it = dQueue.begin(); it != dQueue.end(); it++ ){
std::cout << (*it)->getPID() << " ";
}
std::cout << '\n';
}
private:
std::list< std::shared_ptr<PCB> > dQueue;
};
#endif