E:/p4/sw/physx/PxShared/1.0/trunk/src/foundation/include/PsSList.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2014 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 00029 00030 #ifndef PSFOUNDATION_PSSLIST_H 00031 #define PSFOUNDATION_PSSLIST_H 00032 00033 #include "foundation/Px.h" 00034 #include "foundation/PxAssert.h" 00035 #include "PsAlignedMalloc.h" 00036 00037 #if PX_P64_FAMILY 00038 #define PX_SLIST_ALIGNMENT 16 00039 #else 00040 #define PX_SLIST_ALIGNMENT 8 00041 #endif 00042 00043 namespace physx 00044 { 00045 namespace shdfnd 00046 { 00047 00048 #if PX_VC 00049 #pragma warning(push) 00050 #pragma warning(disable : 4324) // Padding was added at the end of a structure because of a __declspec(align) value. 00051 #endif 00052 00053 #if !PX_GCC_FAMILY 00054 __declspec(align(PX_SLIST_ALIGNMENT)) 00055 #endif 00056 class SListEntry 00057 { 00058 friend struct SListImpl; 00059 00060 public: 00061 SListEntry() : mNext(NULL) 00062 { 00063 PX_ASSERT((size_t(this) & (PX_SLIST_ALIGNMENT - 1)) == 0); 00064 } 00065 00066 // Only use on elements returned by SList::flush() 00067 // because the operation is not atomic. 00068 SListEntry* next() 00069 { 00070 return mNext; 00071 } 00072 00073 private: 00074 SListEntry* mNext; 00075 } 00076 #if PX_GCC_FAMILY 00077 __attribute__((aligned(PX_SLIST_ALIGNMENT))); 00078 #else 00079 ; 00080 #endif 00081 00082 #if PX_VC 00083 #pragma warning(pop) 00084 #endif 00085 00086 // template-less implementation 00087 struct PX_FOUNDATION_API SListImpl 00088 { 00089 SListImpl(); 00090 ~SListImpl(); 00091 void push(SListEntry* entry); 00092 SListEntry* pop(); 00093 SListEntry* flush(); 00094 static const uint32_t& getSize(); 00095 }; 00096 00097 template <typename Alloc = ReflectionAllocator<SListImpl> > 00098 class SListT : protected Alloc 00099 { 00100 public: 00101 SListT(const Alloc& alloc = Alloc()) : Alloc(alloc) 00102 { 00103 mImpl = reinterpret_cast<SListImpl*>(Alloc::allocate(SListImpl::getSize(), __FILE__, __LINE__)); 00104 PX_ASSERT((size_t(mImpl) & (PX_SLIST_ALIGNMENT - 1)) == 0); 00105 PX_PLACEMENT_NEW(mImpl, SListImpl)(); 00106 } 00107 ~SListT() 00108 { 00109 mImpl->~SListImpl(); 00110 Alloc::deallocate(mImpl); 00111 } 00112 00113 // pushes a new element to the list 00114 void push(SListEntry& entry) 00115 { 00116 mImpl->push(&entry); 00117 } 00118 00119 // pops an element from the list 00120 SListEntry* pop() 00121 { 00122 return mImpl->pop(); 00123 } 00124 00125 // removes all items from list, returns pointer to first element 00126 SListEntry* flush() 00127 { 00128 return mImpl->flush(); 00129 } 00130 00131 private: 00132 SListImpl* mImpl; 00133 }; 00134 00135 typedef SListT<> SList; 00136 00137 } // namespace shdfnd 00138 } // namespace physx 00139 00140 #endif // #ifndef PSFOUNDATION_PSSLIST_H
Generated on Tue Jul 28 14:21:55 2015 for NVIDIA(R) PsFoundation Reference by
![doxygen](doxygen.png)