1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_PHYSICS_NX_SCENELOCK
15#define PX_PHYSICS_NX_SCENELOCK
16/** \addtogroup physics
17@{
18*/
19
20#include "PxPhysXConfig.h"
21#include "PxScene.h"
22
23#ifndef PX_DOXYGEN
24namespace physx
25{
26#endif
27
28/**
29\brief RAII wrapper for the PxScene read lock.
30
31Use this class as follows to lock the scene for reading by the current thread
32for the duration of the enclosing scope:
33
34 PxSceneReadLock lock(sceneRef);
35
36\see PxScene::lockRead(), PxScene::unlockRead(), PxSceneFlag::eREQUIRE_RW_LOCK
37*/
38class PxSceneReadLock
39{
40 PxSceneReadLock(const PxSceneReadLock&);
41 PxSceneReadLock& operator=(const PxSceneReadLock&);
42
43public:
44
45 /**
46 \brief Constructor
47 \param scene The scene to lock for reading
48 \param file Optional string for debugging purposes
49 \param line Optional line number for debugging purposes
50 */
51 PxSceneReadLock(PxScene& scene, const char* file=NULL, PxU32 line=0)
52 : mScene(scene)
53 {
54 mScene.lockRead(file, line);
55 }
56
57 ~PxSceneReadLock()
58 {
59 mScene.unlockRead();
60 }
61
62private:
63
64 PxScene& mScene;
65};
66
67/**
68\brief RAII wrapper for the PxScene write lock.
69
70Use this class as follows to lock the scene for writing by the current thread
71for the duration of the enclosing scope:
72
73 PxSceneWriteLock lock(sceneRef);
74
75\see PxScene::lockWrite(), PxScene::unlockWrite(), PxSceneFlag::eREQUIRE_RW_LOCK
76*/
77class PxSceneWriteLock
78{
79 PxSceneWriteLock(const PxSceneWriteLock&);
80 PxSceneWriteLock& operator=(const PxSceneWriteLock&);
81
82public:
83
84 /**
85 \brief Constructor
86 \param scene The scene to lock for writing
87 \param file Optional string for debugging purposes
88 \param line Optional line number for debugging purposes
89 */
90 PxSceneWriteLock(PxScene& scene, const char* file=NULL, PxU32 line=0)
91 : mScene(scene)
92 {
93 mScene.lockWrite(file, line);
94 }
95
96 ~PxSceneWriteLock()
97 {
98 mScene.unlockWrite();
99 }
100
101private:
102
103 PxScene& mScene;
104};
105
106
107#ifndef PX_DOXYGEN
108} // namespace physx
109#endif
110
111/** @} */
112#endif
113