ScopedPhysXLock.h
00001 /* 00002 * Copyright (c) 2008-2017, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * NVIDIA CORPORATION and its licensors retain all intellectual property 00005 * and proprietary rights in and to this software, related documentation 00006 * and any modifications thereto. Any use, reproduction, disclosure or 00007 * distribution of this software and related documentation without an express 00008 * license agreement from NVIDIA CORPORATION is strictly prohibited. 00009 */ 00010 00011 #ifndef SCOPED_PHYS_XLOCK_H 00012 00013 #define SCOPED_PHYS_XLOCK_H 00014 00015 #include "foundation/PxPreprocessor.h" 00016 #include "ApexDefs.h" 00017 00018 00019 #include "PxScene.h" 00020 #include "Scene.h" 00021 00022 namespace nvidia 00023 { 00024 namespace apex 00025 { 00026 00034 class ScopedPhysXLockRead 00035 { 00036 public: 00037 00044 ScopedPhysXLockRead(nvidia::Scene* scene, const char *fileName, int lineno) : mApexScene(scene), mPhysXScene(0) 00045 { 00046 if (mApexScene) 00047 { 00048 mApexScene->lockRead(fileName, (uint32_t)lineno); 00049 } 00050 } 00051 00058 ScopedPhysXLockRead(physx::PxScene* scene, const char *fileName, int lineno) : mPhysXScene(scene), mApexScene(0) 00059 { 00060 if (mPhysXScene) 00061 { 00062 mPhysXScene->lockRead(fileName, (uint32_t)lineno); 00063 } 00064 } 00065 00066 ~ScopedPhysXLockRead() 00067 { 00068 if (mApexScene) 00069 { 00070 mApexScene->unlockRead(); 00071 } 00072 if (mPhysXScene) 00073 { 00074 mPhysXScene->unlockRead(); 00075 } 00076 } 00077 private: 00078 nvidia::Scene* mApexScene; 00079 physx::PxScene* mPhysXScene; 00080 }; 00081 00088 class ScopedPhysXLockWrite 00089 { 00090 public: 00097 ScopedPhysXLockWrite(nvidia::Scene *scene, const char *fileName, int lineno) : mApexScene(scene), mPhysXScene(0) 00098 { 00099 if (mApexScene) 00100 { 00101 mApexScene->lockWrite(fileName, (uint32_t)lineno); 00102 } 00103 } 00104 00111 ScopedPhysXLockWrite(physx::PxScene *scene, const char *fileName, int lineno) : mPhysXScene(scene), mApexScene(0) 00112 { 00113 if (mPhysXScene) 00114 { 00115 mPhysXScene->lockWrite(fileName, (uint32_t)lineno); 00116 } 00117 } 00118 00119 ~ScopedPhysXLockWrite() 00120 { 00121 if (mApexScene) 00122 { 00123 mApexScene->unlockWrite(); 00124 } 00125 if (mPhysXScene) 00126 { 00127 mPhysXScene->unlockWrite(); 00128 } 00129 } 00130 private: 00131 nvidia::Scene* mApexScene; 00132 physx::PxScene* mPhysXScene; 00133 }; 00134 } 00135 } 00136 00137 00138 #if defined(_DEBUG) || PX_CHECKED 00139 00142 #define SCOPED_PHYSX_LOCK_WRITE(x) nvidia::apex::ScopedPhysXLockWrite _wlock(x,__FILE__,__LINE__); 00143 #else 00144 00147 #define SCOPED_PHYSX_LOCK_WRITE(x) nvidia::apex::ScopedPhysXLockWrite _wlock(x,"",0); 00148 #endif 00149 00150 #if defined(_DEBUG) || PX_CHECKED 00151 00154 #define SCOPED_PHYSX_LOCK_READ(x) nvidia::apex::ScopedPhysXLockRead _rlock(x,__FILE__,__LINE__); 00155 #else 00156 00159 #define SCOPED_PHYSX_LOCK_READ(x) nvidia::apex::ScopedPhysXLockRead _rlock(x,"",0); 00160 #endif 00161 00162 00163 00164 #endif
Generated on Fri Dec 15 2017 13:58:35 Copyright © 2012-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.