summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorPyry Haulos <phaulos@google.com>2016-10-20 11:42:41 -0700
committerPyry Haulos <phaulos@google.com>2016-10-20 11:42:41 -0700
commit812d768b55dcedf2c0fda63e69db3c05600f379d (patch)
tree76064111d29dc97dc467d8dfe78c3cab42b8a0e0 /framework
parent05e378a71d3da241d1d15fd9c23b6257111355a5 (diff)
parent9c9bec54eeaf199c74f62ed9a4eb054ef2c4fb88 (diff)
downloadVK-GL-CTS-812d768b55dcedf2c0fda63e69db3c05600f379d.tar.gz
VK-GL-CTS-812d768b55dcedf2c0fda63e69db3c05600f379d.tar.bz2
VK-GL-CTS-812d768b55dcedf2c0fda63e69db3c05600f379d.zip
Merge aosp/upstream-vulkan-cts-1.0-dev into aosp/master
Change-Id: Ia92eae5ac913055ba0cd769b8ca3ac877e02d48c
Diffstat (limited to 'framework')
-rw-r--r--framework/delibs/decpp/dePoolArray.hpp15
-rw-r--r--framework/delibs/decpp/deThreadSafeRingBuffer.hpp59
2 files changed, 45 insertions, 29 deletions
diff --git a/framework/delibs/decpp/dePoolArray.hpp b/framework/delibs/decpp/dePoolArray.hpp
index cec9acd46..108dee759 100644
--- a/framework/delibs/decpp/dePoolArray.hpp
+++ b/framework/delibs/decpp/dePoolArray.hpp
@@ -48,13 +48,16 @@ class PoolArrayIterator;
* to access next element(s) doesn't work.
* \todo [2013-02-11 pyry] Make elements per page template argument.
*//*--------------------------------------------------------------------*/
-template<typename T, deUint32 Alignment = (sizeof(T) > 4 ? 4 : (deUint32)sizeof(T))>
+template<typename T, deUint32 Alignment = (sizeof(T) > sizeof(void*) ? (deUint32)sizeof(void*) : (deUint32)sizeof(T))>
class PoolArray
{
public:
typedef PoolArrayIterator<T, Alignment> Iterator;
typedef PoolArrayConstIterator<T, Alignment> ConstIterator;
+ typedef Iterator iterator;
+ typedef ConstIterator const_iterator;
+
explicit PoolArray (MemPool* pool);
PoolArray (MemPool* pool, const PoolArray<T, Alignment>& other);
~PoolArray (void);
@@ -83,6 +86,12 @@ public:
ConstIterator begin (void) const { return ConstIterator(this, 0); }
ConstIterator end (void) const { return ConstIterator(this, (deIntptr)m_numElements); }
+ const T& front (void) const { return at(0); }
+ T& front (void) { return at(0); }
+
+ const T& back (void) const { return at(m_numElements-1); }
+ T& back (void) { return at(m_numElements-1); }
+
private:
enum
{
@@ -129,7 +138,7 @@ public:
const PoolArray<T, Alignment>* getArray (void) const throw() { return m_array; }
// De-reference operators.
- const T* operator-> (void) const throw() { return (*m_array)[this->m_ndx]; }
+ const T* operator-> (void) const throw() { return &(*m_array)[this->m_ndx]; }
const T& operator* (void) const throw() { return (*m_array)[this->m_ndx]; }
const T& operator[] (deUintptr offs) const throw() { return (*m_array)[this->m_ndx+offs]; }
@@ -165,7 +174,7 @@ public:
PoolArray<T, Alignment>* getArray (void) const throw() { return m_array; }
// De-reference operators.
- T* operator-> (void) const throw() { return (*m_array)[this->m_ndx]; }
+ T* operator-> (void) const throw() { return &(*m_array)[this->m_ndx]; }
T& operator* (void) const throw() { return (*m_array)[this->m_ndx]; }
T& operator[] (deUintptr offs) const throw() { return (*m_array)[this->m_ndx+offs]; }
diff --git a/framework/delibs/decpp/deThreadSafeRingBuffer.hpp b/framework/delibs/decpp/deThreadSafeRingBuffer.hpp
index b03ee65ba..bb7065f2e 100644
--- a/framework/delibs/decpp/deThreadSafeRingBuffer.hpp
+++ b/framework/delibs/decpp/deThreadSafeRingBuffer.hpp
@@ -27,6 +27,8 @@
#include "deMutex.hpp"
#include "deSemaphore.hpp"
+#include <vector>
+
namespace de
{
@@ -37,57 +39,59 @@ template <typename T>
class ThreadSafeRingBuffer
{
public:
- ThreadSafeRingBuffer (int size);
- ~ThreadSafeRingBuffer (void) {}
+ ThreadSafeRingBuffer (size_t size);
+ ~ThreadSafeRingBuffer (void) {}
- void pushFront (const T& elem);
- bool tryPushFront (const T& elem);
- T popBack (void);
- bool tryPopBack (T& dst);
+ void pushFront (const T& elem);
+ bool tryPushFront (const T& elem);
+ T popBack (void);
+ bool tryPopBack (T& dst);
protected:
- void pushFrontInternal (const T& elem);
- T popBackInternal (void);
+ void pushFrontInternal (const T& elem);
+ T popBackInternal (void);
+
+ const size_t m_size;
+ std::vector<T> m_elements;
- int m_front;
- int m_back;
- T* m_buffer;
- int m_size;
+ size_t m_front;
+ size_t m_back;
- Mutex m_writeMutex;
- Mutex m_readMutex;
+ Mutex m_writeMutex;
+ Mutex m_readMutex;
- Semaphore m_fill;
- Semaphore m_empty;
+ Semaphore m_fill;
+ Semaphore m_empty;
};
// ThreadSafeRingBuffer implementation.
template <typename T>
-ThreadSafeRingBuffer<T>::ThreadSafeRingBuffer (int size)
- : m_front (0)
+ThreadSafeRingBuffer<T>::ThreadSafeRingBuffer (size_t size)
+ : m_size (size+1)
+ , m_elements (m_size)
+ , m_front (0)
, m_back (0)
- , m_size (size+1)
, m_fill (0)
- , m_empty (size)
+ , m_empty ((int)size)
{
- DE_ASSERT(size > 0);
- m_buffer = new T[m_size];
+ // Semaphores currently only support INT_MAX
+ DE_ASSERT(size > 0 && size < 0x7fffffff);
}
template <typename T>
inline void ThreadSafeRingBuffer<T>::pushFrontInternal (const T& elem)
{
- m_buffer[m_front] = elem;
+ m_elements[m_front] = elem;
m_front = (m_front + 1) % m_size;
}
template <typename T>
inline T ThreadSafeRingBuffer<T>::popBackInternal ()
{
- int ndx = m_back;
+ const size_t ndx = m_back;
m_back = (m_back + 1) % m_size;
- return m_buffer[ndx];
+ return m_elements[ndx];
}
template <typename T>
@@ -105,12 +109,15 @@ bool ThreadSafeRingBuffer<T>::tryPushFront (const T& elem)
{
if (!m_writeMutex.tryLock())
return false;
- bool success = m_empty.tryDecrement();
+
+ const bool success = m_empty.tryDecrement();
+
if (success)
{
pushFrontInternal(elem);
m_fill.increment();
}
+
m_writeMutex.unlock();
return success;
}