NeuralEngine
A Game Engine with embeded Machine Learning algorithms based on Gaussian Processes.
NeThreadSafeQueue.inl
1
11template <typename Element>
13{
14}
15
16template <typename Element>
18 :
19 mMaxNumElements(maxNumElements)
20{
21}
22
23template <typename Element>
24size_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
35template <typename Element>
36size_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
47template <typename Element>
48bool 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
67template <typename Element>
68bool 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}