NeuralEngine A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes. |

NeThreadSafeQueue.inl
1
11 template <typename Element>
12 ThreadSafeQueue<Element>::~ThreadSafeQueue()
13{
14}
15
16 template <typename Element>
17 ThreadSafeQueue<Element>::ThreadSafeQueue(size_t maxNumElements)
18 :
19 mMaxNumElements(maxNumElements)
20{
21}
22
23 template <typename Element>
24 size_t ThreadSafeQueue<Element>::GetMaxNumElements() const
25{
26 size_t maxNumElements;
27 mMutex.lock();
28 {
29 maxNumElements = mMaxNumElements;
30 }
31 mMutex.unlock();
32 return maxNumElements;
33}
34
35 template <typename Element>
36 size_t ThreadSafeQueue<Element>::GetNumElements() const
37{
38 size_t numElements;
39 mMutex.lock();
40 {
41 numElements = mQueue.size();
42 }
43 mMutex.unlock();
44 return numElements;
45}
46
47 template <typename Element>
48 bool ThreadSafeQueue<Element>::Push(Element const& element)
49{
50 bool pushed;
51 mMutex.lock();
52 {
53 if (mQueue.size() < mMaxNumElements)
54 {
55 mQueue.push(element);
56 pushed = true;
57 }
58 else
59 {
60 pushed = false;
61 }
62 }
63 mMutex.unlock();
64 return pushed;
65}
66
67 template <typename Element>
68 bool ThreadSafeQueue<Element>::Pop(Element& element)
69{
70 bool popped;
71 mMutex.lock();
72 {
73 if (mQueue.size() > 0)
74 {
75 element = mQueue.front();
76 mQueue.pop();
77 popped = true;
78 }
79 else
80 {
81 popped = false;
82 }
83 }
84 mMutex.unlock();
85 return popped;
86}
NeuralEngine::ThreadSafeQueue
Definition: NeThreadSafeQueue.h:22