locked_queue.hh
changeset 269 26c8597fe860
parent 0 0aa9866d751c
     1.1 --- a/locked_queue.hh	Thu Feb 01 23:30:55 2018 +0100
     1.2 +++ b/locked_queue.hh	Fri Feb 02 22:03:16 2018 +0100
     1.3 @@ -5,48 +5,48 @@
     1.4  
     1.5  namespace utility
     1.6  {
     1.7 -	using namespace std;
     1.8 +    using namespace std;
     1.9  
    1.10 -	template<class T> class locked_queue
    1.11 -	{
    1.12 -		mutex _mtx;
    1.13 -		list<T> _q;
    1.14 +    template<class T> class locked_queue
    1.15 +    {
    1.16 +        mutex _mtx;
    1.17 +        list<T> _q;
    1.18  
    1.19 -	public:
    1.20 -		T& back()
    1.21 -		{
    1.22 -			lock_guard<mutex> lg(_mtx);
    1.23 -			return _q.back();
    1.24 -		}
    1.25 -		T& front()
    1.26 -		{
    1.27 -			lock_guard<mutex> lg(_mtx);
    1.28 -			return _q.front();
    1.29 -		}
    1.30 -		void pop_back()
    1.31 -		{
    1.32 -			lock_guard<mutex> lg(_mtx);
    1.33 -			_q.pop_back();
    1.34 -		}
    1.35 -		void pop_front()
    1.36 -		{
    1.37 -			lock_guard<mutex> lg(_mtx);
    1.38 -			_q.pop_front();
    1.39 -		}
    1.40 -		void push_back(const T& data)
    1.41 -		{
    1.42 -			lock_guard<mutex> lg(_mtx);
    1.43 -			_q.push_back(data);
    1.44 -		}
    1.45 -		void push_front(const T& data)
    1.46 -		{
    1.47 -			lock_guard<mutex> lg(_mtx);
    1.48 -			_q.push_front(data);
    1.49 -		}
    1.50 -		size_t size()
    1.51 -		{
    1.52 -			lock_guard<mutex> lg(_mtx);
    1.53 -			return _q.size();
    1.54 -		}
    1.55 -	};
    1.56 +    public:
    1.57 +        T& back()
    1.58 +        {
    1.59 +            lock_guard<mutex> lg(_mtx);
    1.60 +            return _q.back();
    1.61 +        }
    1.62 +        T& front()
    1.63 +        {
    1.64 +            lock_guard<mutex> lg(_mtx);
    1.65 +            return _q.front();
    1.66 +        }
    1.67 +        void pop_back()
    1.68 +        {
    1.69 +            lock_guard<mutex> lg(_mtx);
    1.70 +            _q.pop_back();
    1.71 +        }
    1.72 +        void pop_front()
    1.73 +        {
    1.74 +            lock_guard<mutex> lg(_mtx);
    1.75 +            _q.pop_front();
    1.76 +        }
    1.77 +        void push_back(const T& data)
    1.78 +        {
    1.79 +            lock_guard<mutex> lg(_mtx);
    1.80 +            _q.push_back(data);
    1.81 +        }
    1.82 +        void push_front(const T& data)
    1.83 +        {
    1.84 +            lock_guard<mutex> lg(_mtx);
    1.85 +            _q.push_front(data);
    1.86 +        }
    1.87 +        size_t size()
    1.88 +        {
    1.89 +            lock_guard<mutex> lg(_mtx);
    1.90 +            return _q.size();
    1.91 +        }
    1.92 +    };
    1.93  };