Panda3D

cycleDataStageWriter.I
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file cycleDataStageWriter.I
10 * @author drose
11 * @date 2006-02-06
12 */
13
14 #ifndef CPPPARSER
15
16 #ifdef DO_PIPELINING
17 // This is the implementation for full support of pipelining (as well as the
18 // sanity-check only implementation).
19
20 /**
21 *
22 */
23 template<class CycleDataType>
24 INLINE CycleDataStageWriter<CycleDataType>::
25 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int stage,
26 Thread *current_thread) :
27 _cycler(&cycler),
28 _current_thread(current_thread),
29 _stage(stage)
30 {
31 _pointer = _cycler->write_stage(_stage, _current_thread);
32 nassertv(_pointer != nullptr);
33 }
34
35 /**
36 *
37 */
38 template<class CycleDataType>
39 INLINE CycleDataStageWriter<CycleDataType>::
40 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int stage,
41 bool force_to_0, Thread *current_thread) :
42 _cycler(&cycler),
43 _current_thread(current_thread),
44 _stage(stage)
45 {
46 _pointer = _cycler->write_stage_upstream(_stage, force_to_0, _current_thread);
47 nassertv(_pointer != nullptr);
48 }
49
50 /**
51 *
52 */
53 template<class CycleDataType>
54 INLINE CycleDataStageWriter<CycleDataType>::
55 CycleDataStageWriter(const CycleDataStageWriter<CycleDataType> &copy) :
56 _cycler(copy._cycler),
57 _current_thread(copy._current_thread),
58 _pointer(copy._pointer),
59 _stage(copy._stage)
60 {
61 nassertv(_pointer != nullptr);
62 _cycler->increment_write(_pointer);
63 }
64
65 /**
66 * This flavor of the constructor elevates the pointer from the
67 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
68 * the reader).
69 */
70 template<class CycleDataType>
71 INLINE CycleDataStageWriter<CycleDataType>::
72 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int stage,
73 CycleDataLockedStageReader<CycleDataType> &take_from) :
74 _cycler(&cycler),
75 _current_thread(take_from.get_current_thread()),
76 _stage(stage)
77 {
78 _pointer = _cycler->elevate_read_stage(_stage, take_from.take_pointer(),
79 _current_thread);
80 }
81
82 /**
83 * This flavor of the constructor elevates the pointer from the
84 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
85 * the reader).
86 */
87 template<class CycleDataType>
88 INLINE CycleDataStageWriter<CycleDataType>::
89 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int stage,
90 CycleDataLockedStageReader<CycleDataType> &take_from,
91 bool force_to_0) :
92 _cycler(&cycler),
93 _current_thread(take_from.get_current_thread()),
94 _stage(stage)
95 {
96 _pointer = _cycler->elevate_read_stage_upstream(_stage, take_from.take_pointer(),
97 force_to_0, _current_thread);
98 }
99
100 /**
101 *
102 */
103 template<class CycleDataType>
104 INLINE CycleDataStageWriter<CycleDataType>::
105 CycleDataStageWriter(CycleDataStageWriter<CycleDataType> &&from) noexcept :
106 _cycler(from._cycler),
107 _current_thread(from._current_thread),
108 _pointer(from._pointer),
109 _stage(from._stage)
110 {
111 from._pointer = nullptr;
112 }
113
114 /**
115 *
116 */
117 template<class CycleDataType>
118 INLINE void CycleDataStageWriter<CycleDataType>::
119 operator = (const CycleDataStageWriter<CycleDataType> &copy) {
120 nassertv(_pointer == nullptr);
121 nassertv(_current_thread == copy._current_thread);
122
123 _cycler = copy._cycler;
124 _pointer = copy._pointer;
125 _stage = copy._stage;
126
127 nassertv(_pointer != nullptr);
128 _cycler->increment_write(_pointer);
129 }
130
131 /**
132 *
133 */
134 template<class CycleDataType>
135 INLINE void CycleDataStageWriter<CycleDataType>::
136 operator = (CycleDataStageWriter<CycleDataType> &&from) noexcept {
137 nassertv(_pointer == nullptr);
138 nassertv(_current_thread == from._current_thread);
139
140 _cycler = from._cycler;
141 _pointer = from._pointer;
142 _stage = from._stage;
143
144 from._pointer = nullptr;
145 }
146
147 /**
148 *
149 */
150 template<class CycleDataType>
151 INLINE CycleDataStageWriter<CycleDataType>::
152 ~CycleDataStageWriter() {
153 if (_pointer != nullptr) {
154 _cycler->release_write_stage(_stage, _pointer);
155 }
156 }
157
158 /**
159 * This provides an indirect member access to the actual CycleData data.
160 */
161 template<class CycleDataType>
162 INLINE CycleDataType *CycleDataStageWriter<CycleDataType>::
163 operator -> () {
164 nassertr(_pointer != nullptr, _cycler->cheat());
165 return _pointer;
166 }
167
168 /**
169 * This provides an indirect member access to the actual CycleData data.
170 */
171 template<class CycleDataType>
172 INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
173 operator -> () const {
174 nassertr(_pointer != nullptr, _cycler->cheat());
175 return _pointer;
176 }
177
178 /**
179 * This allows the CycleDataStageWriter to be passed to any function that
180 * expects a CycleDataType pointer.
181 */
182 template<class CycleDataType>
183 INLINE CycleDataStageWriter<CycleDataType>::
184 operator CycleDataType * () {
185 nassertr(_pointer != nullptr, _cycler->cheat());
186 return _pointer;
187 }
188
189 /**
190 * Returns the Thread pointer of the currently-executing thread, as passed to
191 * the constructor of this object.
192 */
193 template<class CycleDataType>
194 INLINE Thread *CycleDataStageWriter<CycleDataType>::
195 get_current_thread() const {
196 return _current_thread;
197 }
198
199 #else // !DO_PIPELINING
200 // This is the trivial, do-nothing implementation.
201
202 /**
203 *
204 */
205 template<class CycleDataType>
206 INLINE CycleDataStageWriter<CycleDataType>::
207 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int, Thread *) {
208 _pointer = cycler.cheat();
209 }
210
211 /**
212 *
213 */
214 template<class CycleDataType>
215 INLINE CycleDataStageWriter<CycleDataType>::
216 CycleDataStageWriter(PipelineCycler<CycleDataType> &cycler, int, bool, Thread *) {
217 _pointer = cycler.cheat();
218 }
219
220 /**
221 *
222 */
223 template<class CycleDataType>
224 INLINE CycleDataStageWriter<CycleDataType>::
225 CycleDataStageWriter(const CycleDataStageWriter<CycleDataType> &copy) :
226 _pointer(copy._pointer)
227 {
228 }
229
230 /**
231 *
232 */
233 template<class CycleDataType>
234 INLINE CycleDataStageWriter<CycleDataType>::
235 CycleDataStageWriter(CycleDataStageWriter<CycleDataType> &&from) noexcept :
236 _pointer(from._pointer)
237 {
238 from._pointer = nullptr;
239 }
240
241 /**
242 *
243 */
244 template<class CycleDataType>
245 INLINE void CycleDataStageWriter<CycleDataType>::
246 operator = (const CycleDataStageWriter<CycleDataType> &copy) {
247 _pointer = copy._pointer;
248 }
249
250 /**
251 *
252 */
253 template<class CycleDataType>
254 INLINE void CycleDataStageWriter<CycleDataType>::
255 operator = (CycleDataStageWriter<CycleDataType> &&from) noexcept {
256 nassertv(_pointer == nullptr);
257
258 _pointer = from._pointer;
259 from._pointer = nullptr;
260 }
261
262 /**
263 * This flavor of the constructor elevates the pointer from the
264 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
265 * the reader).
266 */
267 template<class CycleDataType>
268 INLINE CycleDataStageWriter<CycleDataType>::
269 CycleDataStageWriter(PipelineCycler<CycleDataType> &, int,
270 CycleDataLockedStageReader<CycleDataType> &take_from) :
271 _pointer((CycleDataType *)take_from.take_pointer())
272 {
273 }
274
275 /**
276 * This flavor of the constructor elevates the pointer from the
277 * CycleDataLockedStageReader from a read to a write pointer (and invalidates
278 * the reader).
279 */
280 template<class CycleDataType>
281 INLINE CycleDataStageWriter<CycleDataType>::
282 CycleDataStageWriter(PipelineCycler<CycleDataType> &, int,
283 CycleDataLockedStageReader<CycleDataType> &take_from,
284 bool) :
285 _pointer((CycleDataType *)take_from.take_pointer())
286 {
287 }
288
289 /**
290 *
291 */
292 template<class CycleDataType>
293 INLINE CycleDataStageWriter<CycleDataType>::
294 ~CycleDataStageWriter() {
295 }
296
297 /**
298 * This provides an indirect member access to the actual CycleData data.
299 */
300 template<class CycleDataType>
301 INLINE CycleDataType *CycleDataStageWriter<CycleDataType>::
302 operator -> () {
303 return _pointer;
304 }
305
306 /**
307 * This provides an indirect member access to the actual CycleData data.
308 */
309 template<class CycleDataType>
310 INLINE const CycleDataType *CycleDataStageWriter<CycleDataType>::
311 operator -> () const {
312 return _pointer;
313 }
314
315 /**
316 * This allows the CycleDataStageWriter to be passed to any function that
317 * expects a CycleDataType pointer.
318 */
319 template<class CycleDataType>
320 INLINE CycleDataStageWriter<CycleDataType>::
321 operator CycleDataType * () {
322 return _pointer;
323 }
324
325 /**
326 * Returns the Thread pointer of the currently-executing thread, as passed to
327 * the constructor of this object.
328 */
329 template<class CycleDataType>
330 INLINE Thread *CycleDataStageWriter<CycleDataType>::
331 get_current_thread() const {
332 return Thread::get_current_thread();
333 }
334
335 #endif // DO_PIPELINING
336 #endif // CPPPARSER
CycleDataLockedStageReader
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
Definition: cycleDataLockedStageReader.h:27
CycleDataLockedStageReader::take_pointer
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataStageWriter when it elevates the pointer from read t...
Definition: cycleDataLockedStageReader.I:244
CycleDataStageWriter
This class is similar to CycleDataWriter, except it allows writing to a particular stage of the pipel...
Definition: cycleDataStageWriter.h:31
CycleDataStageWriter::get_current_thread
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
Definition: cycleDataStageWriter.I:331
CycleDataStageWriter::operator->
CycleDataType * operator->()
This provides an indirect member access to the actual CycleData data.
Definition: cycleDataStageWriter.I:302
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46
Thread::get_current_thread
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
PipelineCycler
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
Definition: pipelineCycler.h:46
PipelineCycler::cheat
CycleDataType * cheat() const
Returns a pointer without counting it.
Definition: pipelineCycler.I:342