RavEngine
Loading...
Searching...
No Matches
NpCheck.h
1
// Redistribution and use in source and binary forms, with or without
2
// modification, are permitted provided that the following conditions
3
// are met:
4
// * Redistributions of source code must retain the above copyright
5
// notice, this list of conditions and the following disclaimer.
6
// * Redistributions in binary form must reproduce the above copyright
7
// notice, this list of conditions and the following disclaimer in the
8
// documentation and/or other materials provided with the distribution.
9
// * Neither the name of NVIDIA CORPORATION nor the names of its
10
// contributors may be used to endorse or promote products derived
11
// from this software without specific prior written permission.
12
//
13
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
//
25
// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29
#ifndef NP_CHECK_H
30
#define NP_CHECK_H
31
32
#include "foundation/PxSimpleTypes.h"
33
34
namespace
physx
35
{
36
37
class
NpScene;
38
39
// RAII wrapper around the PxScene::startRead() method, note that this
40
// object does not acquire any scene locks, it is an error checking only mechanism
41
class
NpReadCheck
42
{
43
public
:
44
NpReadCheck
(
const
NpScene
* scene,
const
char
* functionName);
45
~NpReadCheck
();
46
private
:
47
const
NpScene
* mScene;
48
const
char
* mName;
49
PxU32 mErrorCount;
50
};
51
52
// RAII wrapper around the PxScene::startWrite() method, note that this
53
// object does not acquire any scene locks, it is an error checking only mechanism
54
class
NpWriteCheck
55
{
56
public
:
57
NpWriteCheck
(
NpScene
* scene,
const
char
* functionName,
bool
allowReentry=
true
);
58
~NpWriteCheck
();
59
60
private
:
61
62
NpScene
* mScene;
63
const
char
* mName;
64
bool
mAllowReentry;
65
PxU32 mErrorCount;
66
};
67
68
#if (PX_DEBUG || PX_CHECKED)
69
// Creates a scoped read check object that detects whether appropriate scene locks
70
// have been acquired and checks if reads/writes overlap, this macro should typically
71
// be placed at the beginning of any const API methods that are not multi-thread safe,
72
// the error conditions checked can be summarized as:
73
74
// 1. PxSceneFlag::eREQUIRE_RW_LOCK was specified but PxScene::lockRead() was not yet called
75
// 2. Other threads were already writing, or began writing during the object lifetime
76
#define NP_READ_CHECK(npScenePtr) NpReadCheck npReadCheck(static_cast<const NpScene*>(npScenePtr), __FUNCTION__);
77
78
// Creates a scoped write check object that detects whether appropriate scene locks
79
// have been acquired and checks if reads/writes overlap, this macro should typically
80
// be placed at the beginning of any non-const API methods that are not multi-thread safe.
81
// By default re-entrant write calls by the same thread are allowed, the error conditions
82
// checked can be summarized as:
83
84
// 1. PxSceneFlag::eREQUIRE_RW_LOCK was specified but PxScene::lockWrite() was not yet called
85
// 2. Other threads were already reading, or began reading during the object lifetime
86
// 3. Other threads were already writing, or began writing during the object lifetime
87
#define NP_WRITE_CHECK(npScenePtr) NpWriteCheck npWriteCheck(npScenePtr, __FUNCTION__);
88
89
// Creates a scoped write check object that disallows re-entrant writes, this is used by
90
// the NpScene::simulate method to detect when callbacks make write calls to the API
91
#define NP_WRITE_CHECK_NOREENTRY(npScenePtr) NpWriteCheck npWriteCheck(npScenePtr, __FUNCTION__, false);
92
#else
93
#define NP_READ_CHECK(npScenePtr)
94
#define NP_WRITE_CHECK(npScenePtr)
95
#define NP_WRITE_CHECK_NOREENTRY(npScenePtr)
96
#endif
97
98
/*
99
PT: suggested ordering for Np-level checks & macros:
100
101
PX_PROFILE_ZONE(...);
102
NP_WRITE_CHECK(...);
103
PX_CHECK_AND_RETURN_XXX(...);
104
PX_CHECK_SCENE_API_WRITE_FORBIDDEN_AND_RETURN_VAL(...);
105
PX_SIMD_GUARD;
106
107
Current rationale:
108
109
- profile zone first to include the cost of the checks in the profiling results.
110
111
- NP_WRITE_CHECK before PX_CHECK macros. I tried both and the DLL size is smaller with NP_WRITE_CHECK macros first.
112
113
- PX_CHECK_SCENE_API_WRITE_FORBIDDEN_AND_RETURN_VAL after PX_CHECK_AND_RETURN macros, because contrary to the others
114
these macros don't vanish in Release builds. So we want to group together NP_WRITE_CHECK and PX_CHECK_AND_RETURN macros
115
(the ones that do vanish). That way we can eventually skip them with a runtime flag.
116
117
- PX_SIMD_GUARD last. No need to take the guard before the PX_CHECK_SCENE_API are done, it would only generate more
118
guard dtor code when the macro eary exits.
119
*/
120
}
121
122
#endif
physx::NpReadCheck
Definition
NpCheck.h:42
physx::NpScene
Definition
NpScene.h:130
physx::NpWriteCheck
Definition
NpCheck.h:55
physx
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition
PxBoxController.h:39
RavEngine
deps
physx
physx
source
physx
src
NpCheck.h
Generated by
1.9.8