Panda3D
Loading...
Searching...
No Matches
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 */
23template<class CycleDataType>
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 */
38template<class CycleDataType>
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 */
53template<class CycleDataType>
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 */
67template<class CycleDataType>
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 */
84template<class CycleDataType>
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 */
100template<class CycleDataType>
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 */
111template<class CycleDataType>
112INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
113operator -> () 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 */
122template<class CycleDataType>
124operator 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 */
135template<class CycleDataType>
136INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
137take_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 */
148template<class CycleDataType>
150get_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 */
160template<class CycleDataType>
163 Thread *) {
164 _pointer = cycler.cheat();
165}
166
167/**
168 *
169 */
170template<class CycleDataType>
173 _pointer(copy._pointer)
174{
175}
176
177/**
178 *
179 */
180template<class CycleDataType>
183 _pointer(from._cycler)
184{
185 from._pointer = nullptr;
186}
187
188/**
189 *
190 */
191template<class CycleDataType>
194 _pointer = copy._pointer;
195}
196
197/**
198 *
199 */
200template<class CycleDataType>
203 nassertv(_pointer == nullptr);
204
205 _pointer = from._pointer;
206 from._pointer = nullptr;
207}
208
209/**
210 *
211 */
212template<class CycleDataType>
215}
216
217/**
218 * This provides an indirect member access to the actual CycleData data.
219 */
220template<class CycleDataType>
222operator -> () 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 */
230template<class CycleDataType>
232operator 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 */
242template<class CycleDataType>
244take_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 */
252template<class CycleDataType>
257
258#endif // DO_PIPELINING
259#endif // CPPPARSER
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
const CycleDataType * operator->() const
This provides an indirect member access to the actual CycleData data.
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataStageWriter when it elevates the pointer from read t...
A thread; that is, a lightweight process.
Definition thread.h:46
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition thread.h:109
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
CycleDataType * cheat() const
Returns a pointer without counting it.