diff options
| author | git perforce import user <a@b> | 2016-10-25 12:29:14 -0600 |
|---|---|---|
| committer | Sheikh Dawood Abdul Ajees <Sheikh Dawood Abdul Ajees> | 2016-10-25 18:56:37 -0500 |
| commit | 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 (patch) | |
| tree | fa6485c169e50d7415a651bf838f5bcd0fd3bfbd /APEX_1.4/common/include/ApexFIFO.h | |
| download | physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.tar.xz physx-3.4-3dfe2108cfab31ba3ee5527e217d0d8e99a51162.zip | |
Initial commit:
PhysX 3.4.0 Update @ 21294896
APEX 1.4.0 Update @ 21275617
[CL 21300167]
Diffstat (limited to 'APEX_1.4/common/include/ApexFIFO.h')
| -rw-r--r-- | APEX_1.4/common/include/ApexFIFO.h | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/APEX_1.4/common/include/ApexFIFO.h b/APEX_1.4/common/include/ApexFIFO.h new file mode 100644 index 00000000..b087ac0e --- /dev/null +++ b/APEX_1.4/common/include/ApexFIFO.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA CORPORATION and its licensors retain all intellectual property + * and proprietary rights in and to this software, related documentation + * and any modifications thereto. Any use, reproduction, disclosure or + * distribution of this software and related documentation without an express + * license agreement from NVIDIA CORPORATION is strictly prohibited. + */ + + +#ifndef __APEX_FIFO_H__ +#define __APEX_FIFO_H__ + +#include "Apex.h" +#include "PsUserAllocated.h" + +namespace nvidia +{ +namespace apex +{ + +template <typename T> +struct FIFOEntry +{ + T data; + uint32_t next; + bool isValidEntry; +}; + +template<typename T> +class ApexFIFO : public UserAllocated +{ +public: + ApexFIFO() : first((uint32_t) - 1), last((uint32_t) - 1), count(0) {} + + bool popFront(T& frontElement) + { + if (first == (uint32_t)-1) + { + return false; + } + + PX_ASSERT(first < list.size()); + frontElement = list[first].data; + + if (first == last) + { + list.clear(); + first = (uint32_t) - 1; + last = (uint32_t) - 1; + } + else + { + list[first].isValidEntry = false; + + if (list[last].next == (uint32_t)-1) + { + list[last].next = first; + } + first = list[first].next; + } + + count--; + return true; + } + + + void pushBack(const T& newElement) + { + if (list.size() == 0 || list[last].next == (uint32_t)-1) + { + FIFOEntry<T> newEntry; + newEntry.data = newElement; + newEntry.next = (uint32_t) - 1; + newEntry.isValidEntry = true; + list.pushBack(newEntry); + + if (first == (uint32_t) - 1) + { + PX_ASSERT(last == (uint32_t) - 1); + first = list.size() - 1; + } + else + { + PX_ASSERT(last != (uint32_t) - 1); + list[last].next = list.size() - 1; + } + + last = list.size() - 1; + } + else + { + uint32_t freeIndex = list[last].next; + PX_ASSERT(freeIndex < list.size()); + + FIFOEntry<T>& freeEntry = list[freeIndex]; + freeEntry.data = newElement; + freeEntry.isValidEntry = true; + + if (freeEntry.next == first) + { + freeEntry.next = (uint32_t) - 1; + } + + last = freeIndex; + } + count++; + } + + uint32_t size() + { + return count; + } + + PX_INLINE void reserve(const uint32_t capacity) + { + list.reserve(capacity); + } + + PX_INLINE uint32_t capacity() const + { + return list.capacity(); + } + +private: + uint32_t first; + uint32_t last; + uint32_t count; + physx::Array<FIFOEntry<T> > list; +}; + +} +} // end namespace nvidia::apex + +#endif
\ No newline at end of file |