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

added Comments and changed the Function- and Variable names.

parent 3cbe0809
No related branches found
No related tags found
1 merge request!2added Comments and changed the Function- and Variable names.
...@@ -4,70 +4,59 @@ using System.Threading; ...@@ -4,70 +4,59 @@ using System.Threading;
namespace ConsoleApplication1 namespace ConsoleApplication1
{ {
/// <summary>
/// Creating a Class Buffer that contains a Queue that represent the "Parking lot".
/// The Queue is limited by the size that can manually be setted
/// </summary>
public class Buffer public class Buffer
{ {
private Queue<Car> carQueue; private Queue<Car> _carQueue;
private int size = 10; private int _size = 10;
private Mutex mutex; private Mutex _mutex;
// Constructor initialized with a Mutex and a Queue.
public Buffer() public Buffer()
{ {
mutex = new Mutex(); _mutex = new Mutex();
carQueue = new Queue<Car>(); _carQueue = new Queue<Car>();
} }
public void push(Car c) // This function adds a Car Object into the Queue.
public void Push(Car c)
{ {
if (carQueue.Count == size) // Check whether the Queue is full and throws an Exception if so.
if (_carQueue.Count == _size)
{ {
throw new Exception("Buffer full"); throw new Exception("Buffer full");
} }
carQueue.Enqueue(c); _carQueue.Enqueue(c);
} }
public Car pop() // Removes a Car Object from the Queue and returns the Queue.
public Car Pop()
{ {
if (carQueue.Count == 0) if (_carQueue.Count == 0)
{ {
throw new Exception("Buffer empty"); throw new Exception("Buffer empty");
} }
return carQueue.Dequeue(); return _carQueue.Dequeue();
} }
public bool full() // Check if the Queue is full.
public bool Full()
{ {
bool isFull = false; return _carQueue.Count == _size;
if (carQueue.Count == size)
{
isFull = true;
}
return isFull;
} }
public bool empty() // Check if the Queue is empty.
public bool Empty()
{ {
if (carQueue.Count == 0) return _carQueue.Count == 0;
{
return true;
}
return false;
} }
public Mutex getMutex() // returns the Mutex.
public Mutex GetMutex()
{ {
return this.mutex; return this._mutex;
} }
} }
} }
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