Skip to content
Snippets Groups Projects
Commit 3cce90e9 authored by Michael Ghebremussie's avatar Michael Ghebremussie
Browse files

Added Comments to the Buffer and removes white Spaces

parent 0113a6f8
No related branches found
No related tags found
2 merge requests!3Added Comments to the Buffer and removes white Spaces,!1Added Comments to the Buffer and removes white Spaces
......@@ -4,31 +4,40 @@ using System.Threading;
namespace ConsoleApplication1
{
/// <summary>
/// Created a Class Buffer that contains a Queue which represents the "Garage".
/// The Queue is limited by the size
/// </summary>
public class Buffer
{
private Queue<Car> carQueue;
private int size = 10;
private Mutex mutex;
// The Buffer has a Mutex and a Queue
public Buffer()
{
mutex = new Mutex();
carQueue = new Queue<Car>();
}
// This functions adds a Car object into the Queue
public void push(Car c)
{
// Throws an Exception if the Buffer size equals size
if (carQueue.Count == size)
{
throw new Exception("Buffer full");
}
// Adds the passed Car object with the default Enqueue method
carQueue.Enqueue(c);
}
// removes a Car from the Queue and returns the Queue
public Car pop()
{
// Throws an Exception if the Buffer size equals 0
if (carQueue.Count == 0)
{
throw new Exception("Buffer empty");
......@@ -37,6 +46,7 @@ namespace ConsoleApplication1
return carQueue.Dequeue();
}
// returns a wheather the Queue is full or not
public bool full()
{
bool isFull = false;
......@@ -48,6 +58,7 @@ namespace ConsoleApplication1
return isFull;
}
// returns a wheather the Queue is empty or not
public bool empty()
{
if (carQueue.Count == 0)
......@@ -58,11 +69,11 @@ namespace ConsoleApplication1
return false;
}
// returns the mutex
public Mutex getMutex()
{
return this.mutex;
}
}
}
......@@ -3,7 +3,6 @@ using System.Threading;
namespace ConsoleApplication1
{
public class Producer
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment