Panda3D

cycleDataLockedStageReader.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 cycleDataLockedStageReader.I
10 * @author drose
11 * @date 2006-04-30
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 CycleDataLockedStageReader<CycleDataType>::
25 CycleDataLockedStageReader(const PipelineCycler<CycleDataType> &cycler,
26 int stage, Thread *current_thread) :
27 _cycler(&cycler),
28 _current_thread(current_thread),
29 _stage(stage)
30 {
31 _pointer = _cycler->read_stage(_stage, _current_thread);
32 nassertv(_pointer != nullptr);
33 }
34
35 /**
36 *
37 */
38 template<class CycleDataType>
39 INLINE CycleDataLockedStageReader<CycleDataType>::
40 CycleDataLockedStageReader(const CycleDataLockedStageReader<CycleDataType> &copy) :
41 _cycler(copy._cycler),
42 _current_thread(copy._current_thread),
43 _pointer(copy._pointer),
44 _stage(copy._stage)
45 {
46 nassertv(_pointer != nullptr);
47 _cycler->increment_read(_pointer);
48 }
49
50 /**
51 *
52 */
53 template<class CycleDataType>
54 INLINE CycleDataLockedStageReader<CycleDataType>::
55 CycleDataLockedStageReader(CycleDataLockedStageReader<CycleDataType> &&from) noexcept :
56 _cycler(from._cycler),
57 _current_thread(from._current_thread),
58 _pointer(from._pointer),
59 _stage(from._stage)
60 {
61 from._pointer = nullptr;
62 }
63
64 /**
65 *
66 */
67 template<class CycleDataType>
68 INLINE void CycleDataLockedStageReader<CycleDataType>::
69 operator = (const CycleDataLockedStageReader<CycleDataType> &copy) {
70 nassertv(_pointer == nullptr);
71 nassertv(_current_thread == copy._current_thread);
72
73 _cycler = copy._cycler;
74 _pointer = copy._pointer;
75 _stage = copy._stage;
76
77 nassertv(_pointer != nullptr);
78 _cycler->increment_read(_pointer);
79 }
80
81 /**
82 *
83 */
84 template<class CycleDataType>
85 INLINE void CycleDataLockedStageReader<CycleDataType>::
86 operator = (CycleDataLockedStageReader<CycleDataType> &&from) noexcept {
87 nassertv(_pointer == nullptr);
88 nassertv(_current_thread == from._current_thread);
89
90 _cycler = from._cycler;
91 _pointer = from._pointer;
92 _stage = from._stage;
93
94 from._pointer = nullptr;
95 }
96
97 /**
98 *
99 */
100 template<class CycleDataType>
101 INLINE CycleDataLockedStageReader<CycleDataType>::
102 ~CycleDataLockedStageReader() {
103 if (_pointer != nullptr) {
104 _cycler->release_read_stage(_stage, _pointer);
105 }
106 }
107
108 /**
109 * This provides an indirect member access to the actual CycleData data.
110 */
111 template<class CycleDataType>
112 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
113 operator -> () const {
114 nassertr(_pointer != nullptr, _cycler->cheat());
115 return _pointer;
116 }
117
118 /**
119 * This allows the CycleDataLockedStageReader to be passed to any function
120 * that expects a const CycleDataType pointer.
121 */
122 template<class CycleDataType>
123 INLINE CycleDataLockedStageReader<CycleDataType>::
124 operator const CycleDataType * () const {
125 nassertr(_pointer != nullptr, _cycler->cheat());
126 return _pointer;
127 }
128
129 /**
130 * This is intended to be called only from CycleDataStageWriter when it
131 * elevates the pointer from read to write status. This function returns the
132 * reader's pointer and relinquishes ownership of the pointer, rendering the
133 * reader invalid for future reads.
134 */
135 template<class CycleDataType>
136 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
137 take_pointer() {
138 const CycleDataType *pointer = _pointer;
139 _pointer = nullptr;
140 nassertr(pointer != nullptr, _cycler->cheat());
141 return pointer;
142 }
143
144 /**
145 * Returns the Thread pointer of the currently-executing thread, as passed to
146 * the constructor of this object.
147 */
148 template<class CycleDataType>
149 INLINE Thread *CycleDataLockedStageReader<CycleDataType>::
150 get_current_thread() const {
151 return _current_thread;
152 }
153
154 #else // !DO_PIPELINING
155 // This is the trivial, do-nothing implementation.
156
157 /**
158 *
159 */
160 template<class CycleDataType>
161 INLINE CycleDataLockedStageReader<CycleDataType>::
162 CycleDataLockedStageReader(const PipelineCycler<CycleDataType> &cycler, int,
163 Thread *) {
164 _pointer = cycler.cheat();
165 }
166
167 /**
168 *
169 */
170 template<class CycleDataType>
171 INLINE CycleDataLockedStageReader<CycleDataType>::
172 CycleDataLockedStageReader(const CycleDataLockedStageReader<CycleDataType> &copy) :
173 _pointer(copy._pointer)
174 {
175 }
176
177 /**
178 *
179 */
180 template<class CycleDataType>
181 INLINE CycleDataLockedStageReader<CycleDataType>::
182 CycleDataLockedStageReader(CycleDataLockedStageReader<CycleDataType> &&from) noexcept :
183 _pointer(from._cycler)
184 {
185 from._pointer = nullptr;
186 }
187
188 /**
189 *
190 */
191 template<class CycleDataType>
192 INLINE void CycleDataLockedStageReader<CycleDataType>::
193 operator = (const CycleDataLockedStageReader<CycleDataType> &copy) {
194 _pointer = copy._pointer;
195 }
196
197 /**
198 *
199 */
200 template<class CycleDataType>
201 INLINE void CycleDataLockedStageReader<CycleDataType>::
202 operator = (CycleDataLockedStageReader<CycleDataType> &&from) noexcept {
203 nassertv(_pointer == nullptr);
204
205 _pointer = from._pointer;
206 from._pointer = nullptr;
207 }
208
209 /**
210 *
211 */
212 template<class CycleDataType>
213 INLINE CycleDataLockedStageReader<CycleDataType>::
214 ~CycleDataLockedStageReader() {
215 }
216
217 /**
218 * This provides an indirect member access to the actual CycleData data.
219 */
220 template<class CycleDataType>
221 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
222 operator -> () const {
223 return _pointer;
224 }
225
226 /**
227 * This allows the CycleDataLockedStageReader to be passed to any function
228 * that expects a const CycleDataType pointer.
229 */
230 template<class CycleDataType>
231 INLINE CycleDataLockedStageReader<CycleDataType>::
232 operator const CycleDataType * () const {
233 return _pointer;
234 }
235
236 /**
237 * This is intended to be called only from CycleDataStageWriter when it
238 * elevates the pointer from read to write status. This function returns the
239 * reader's pointer and relinquishes ownership of the pointer, rendering the
240 * reader invalid for future reads.
241 */
242 template<class CycleDataType>
243 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
244 take_pointer() {
245 return _pointer;
246 }
247
248 /**
249 * Returns the Thread pointer of the currently-executing thread, as passed to
250 * the constructor of this object.
251 */
252 template<class CycleDataType>
253 INLINE Thread *CycleDataLockedStageReader<CycleDataType>::
254 get_current_thread() const {
255 return Thread::get_current_thread();
256 }
257
258 #endif // DO_PIPELINING
259 #endif // CPPPARSER
CycleDataLockedStageReader
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
Definition: cycleDataLockedStageReader.h:27
CycleDataLockedStageReader::operator->
const CycleDataType * operator->() const
This provides an indirect member access to the actual CycleData data.
Definition: cycleDataLockedStageReader.I:222
CycleDataLockedStageReader::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: cycleDataLockedStageReader.I:254
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
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