RavEngine
Loading...
Searching...
No Matches
PxTask.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
27#ifndef PX_TASK_H
28#define PX_TASK_H
29
30#include "task/PxTaskManager.h"
31#include "task/PxCpuDispatcher.h"
32#include "foundation/PxAssert.h"
33
34#if !PX_DOXYGEN
35namespace physx
36{
37#endif
38
45{
46public:
47 PxBaseTask() : mContextID(0), mTm(NULL) {}
48 virtual ~PxBaseTask() {}
49
56 virtual void run() = 0;
57
65 virtual const char* getName() const = 0;
66
68 virtual void addReference() = 0;
70 virtual void removeReference() = 0;
72 virtual int32_t getReference() const = 0;
73
80 virtual void release() = 0;
81
89 {
90 return mTm;
91 }
92
93 PX_FORCE_INLINE void setContextId(PxU64 id) { mContextID = id; }
94 PX_FORCE_INLINE PxU64 getContextId() const { return mContextID; }
95
96protected:
97 PxU64 mContextID;
99
100 friend class PxTaskMgr;
101};
102
103
110class PxTask : public PxBaseTask
111{
112public:
113 PxTask() : mTaskID(0) {}
114 virtual ~PxTask() {}
115
117 virtual void release() PX_OVERRIDE
118 {
119 PX_ASSERT(mTm);
120
121 // clear mTm before calling taskCompleted() for safety
122 PxTaskManager* save = mTm;
123 mTm = NULL;
124 save->taskCompleted(*this);
125 }
126
128 // task is allowed to start.
129 PX_INLINE void finishBefore(PxTaskID taskID)
130 {
131 PX_ASSERT(mTm);
132 mTm->finishBefore(*this, taskID);
133 }
134
136 // task has completed.
137 PX_INLINE void startAfter(PxTaskID taskID)
138 {
139 PX_ASSERT(mTm);
140 mTm->startAfter(*this, taskID);
141 }
142
148 {
149 PX_ASSERT(mTm);
150 mTm->addReference(mTaskID);
151 }
152
158 {
159 PX_ASSERT(mTm);
160 mTm->decrReference(mTaskID);
161 }
162
166 virtual int32_t getReference() const PX_OVERRIDE
167 {
168 return mTm->getReference(mTaskID);
169 }
170
174 PX_INLINE PxTaskID getTaskID() const
175 {
176 return mTaskID;
177 }
178
184 virtual void submitted()
185 {
186 }
187
188protected:
189 PxTaskID mTaskID;
190
191 friend class PxTaskMgr;
192};
193
194
209{
210public:
212 : mCont( NULL )
213 , mRefCount( 0 )
214 {
215 }
216 virtual ~PxLightCpuTask()
217 {
218 mTm = NULL;
219 }
220
231 {
232 PX_ASSERT(mRefCount == 0);
233 mRefCount = 1;
234 mCont = c;
235 mTm = &tm;
236 if(mCont)
238 }
239
248 {
249 PX_ASSERT(c);
250 PX_ASSERT(mRefCount == 0);
251 mRefCount = 1;
252 mCont = c;
253 if(mCont)
254 {
257 PX_ASSERT(mTm);
258 }
259 }
260
265 {
266 return mCont;
267 }
268
274 {
275 mTm->decrReference(*this);
276 }
277
279 virtual int32_t getReference() const PX_OVERRIDE
280 {
281 return mRefCount;
282 }
283
289 {
290 mTm->addReference(*this);
291 }
292
298 virtual void release() PX_OVERRIDE
299 {
300 if(mCont)
302 }
303
304protected:
305
307 volatile int32_t mRefCount;
308
309 friend class PxTaskMgr;
310};
311
312
313#if !PX_DOXYGEN
314} // namespace physx
315#endif
316
317
318#endif
319
Base class of all task types.
Definition PxTask.h:45
virtual void addReference()=0
Implemented by derived implementation classes.
virtual void release()=0
Implemented by derived implementation classes.
virtual void run()=0
The user-implemented run method where the task's work should be performed.
virtual int32_t getReference() const =0
Implemented by derived implementation classes.
PxU64 mContextID
Context ID for profiler interface.
Definition PxTask.h:97
virtual void removeReference()=0
Implemented by derived implementation classes.
virtual const char * getName() const =0
Return a user-provided task name for profiling purposes.
PX_FORCE_INLINE PxTaskManager * getTaskManager() const
Return PxTaskManager to which this task was submitted.
Definition PxTask.h:88
PxTaskManager * mTm
Owning PxTaskManager instance.
Definition PxTask.h:98
A PxBaseTask implementation with immediate execution and simple dependencies.
Definition PxTask.h:209
volatile int32_t mRefCount
PxTask is dispatched when reaches 0.
Definition PxTask.h:307
PX_INLINE void setContinuation(PxBaseTask *c)
Initialize this task and specify the task that will have its ref count decremented on completion.
Definition PxTask.h:247
virtual int32_t getReference() const PX_OVERRIDE
Return the ref-count for this task.
Definition PxTask.h:279
virtual void removeReference() PX_OVERRIDE
Manually decrement this task's reference count. If the reference count reaches zero,...
Definition PxTask.h:273
PX_INLINE void setContinuation(PxTaskManager &tm, PxBaseTask *c)
Initialize this task and specify the task that will have its ref count decremented on completion.
Definition PxTask.h:230
virtual void addReference() PX_OVERRIDE
Manually increment this task's reference count. The task will not be allowed to run until removeRefer...
Definition PxTask.h:288
virtual void release() PX_OVERRIDE
called by CpuDispatcher after run method has completed
Definition PxTask.h:298
PxBaseTask * mCont
Continuation task, can be NULL.
Definition PxTask.h:306
PX_INLINE PxBaseTask * getContinuation() const
Retrieves continuation task.
Definition PxTask.h:264
The PxTaskManager interface.
Definition PxTaskManager.h:81
virtual void taskCompleted(PxTask &task)=0
Called by the worker threads to inform the PxTaskManager that a task has completed processing.
Definition TaskManager.cpp:85
A PxBaseTask implementation with deferred execution and full dependencies.
Definition PxTask.h:111
virtual void removeReference() PX_OVERRIDE
Manually decrement this task's reference count. If the reference count reaches zero,...
Definition PxTask.h:157
virtual void submitted()
Called by PxTaskManager at submission time for initialization.
Definition PxTask.h:184
virtual int32_t getReference() const PX_OVERRIDE
Return the ref-count for this task.
Definition PxTask.h:166
PX_INLINE void startAfter(PxTaskID taskID)
Inform the PxTaskManager this task cannot start until the given.
Definition PxTask.h:137
virtual void addReference() PX_OVERRIDE
Manually increment this task's reference count. The task will not be allowed to run until removeRefer...
Definition PxTask.h:147
PX_INLINE void finishBefore(PxTaskID taskID)
Inform the PxTaskManager this task must finish before the given.
Definition PxTask.h:129
PxTaskID mTaskID
ID assigned at submission.
Definition PxTask.h:189
virtual void release() PX_OVERRIDE
Release method implementation.
Definition PxTask.h:117
PX_INLINE PxTaskID getTaskID() const
Return the unique ID for this task.
Definition PxTask.h:174
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39