diff --git a/Aufgabe3/ConsoleApplication1/Buffer.cs b/Aufgabe3/ConsoleApplication1/Buffer.cs index cb5d1bce6dc66385bee08b9278ef5b14f592bb80..7de3950656149f76616e91009a1befe908e9c01f 100644 --- a/Aufgabe3/ConsoleApplication1/Buffer.cs +++ b/Aufgabe3/ConsoleApplication1/Buffer.cs @@ -4,70 +4,59 @@ using System.Threading; 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 { - private Queue<Car> carQueue; - private int size = 10; - private Mutex mutex; + private Queue<Car> _carQueue; + private int _size = 10; + private Mutex _mutex; + // Constructor initialized with a Mutex and a Queue. public Buffer() { - mutex = new Mutex(); - carQueue = new Queue<Car>(); + _mutex = new Mutex(); + _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"); - } - + } - 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"); } - return carQueue.Dequeue(); + return _carQueue.Dequeue(); } - public bool full() + // Check if the Queue is full. + public bool Full() { - bool isFull = false; - if (carQueue.Count == size) - { - isFull = true; - } - - return isFull; + return _carQueue.Count == _size; } - public bool empty() + // Check if the Queue is empty. + public bool Empty() { - if (carQueue.Count == 0) - { - return true; - } - - return false; + return _carQueue.Count == 0; } - public Mutex getMutex() + // returns the Mutex. + public Mutex GetMutex() { - return this.mutex; + return this._mutex; } - - } }