Line data Source code
1 :
2 : /* Copyright (c) 2010-2013, Stefan Eilemann <eile@equalizergraphics.com>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : namespace lunchbox
19 : {
20 : template <typename T>
21 : void LFQueue<T>::clear()
22 : {
23 : LB_TS_SCOPED(_reader);
24 : _readPos = 0;
25 : _writePos = 0;
26 : }
27 :
28 : template <typename T>
29 : void LFQueue<T>::resize(const int32_t size)
30 : {
31 : LBASSERT(isEmpty());
32 : _readPos = 0;
33 : _writePos = 0;
34 : _data.resize(size + 1);
35 : }
36 :
37 : template <typename T>
38 243509 : bool LFQueue<T>::pop(T& result)
39 : {
40 487018 : LB_TS_SCOPED(_reader);
41 243509 : if (_readPos == _writePos)
42 0 : return false;
43 :
44 243509 : result = _data[_readPos];
45 243509 : _readPos = (_readPos + 1) % _data.size();
46 243509 : return true;
47 : }
48 :
49 : template <typename T>
50 243510 : bool LFQueue<T>::getFront(T& result)
51 : {
52 487020 : LB_TS_SCOPED(_reader);
53 243510 : if (_readPos == _writePos)
54 1 : return false;
55 :
56 243509 : result = _data[_readPos];
57 243509 : return true;
58 : }
59 :
60 : template <typename T>
61 498392 : bool LFQueue<T>::push(const T& element)
62 : {
63 996784 : LB_TS_SCOPED(_writer);
64 498392 : int32_t nextPos = (_writePos + 1) % _data.size();
65 498392 : if (nextPos == _readPos)
66 253864 : return false;
67 :
68 244528 : _data[_writePos] = element;
69 244528 : _writePos = nextPos;
70 244528 : return true;
71 : }
72 : }
|