Panda3D
 All Classes Functions Variables Enumerations
cycleDataLockedStageReader.I
1 // Filename: cycleDataLockedStageReader.I
2 // Created by: drose (30Apr06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef CPPPARSER
16 
17 #ifdef DO_PIPELINING
18 // This is the implementation for full support of pipelining (as well
19 // as the sanity-check only implementation).
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: CycleDataLockedStageReader::Constructor (full)
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 template<class CycleDataType>
29  int stage, Thread *current_thread) :
30  _cycler(&cycler),
31  _current_thread(current_thread),
32  _stage(stage)
33 {
34  _pointer = _cycler->read_stage(_stage, _current_thread);
35  nassertv(_pointer != (const CycleDataType *)NULL);
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: CycleDataLockedStageReader::Copy Constructor (full)
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 template<class CycleDataType>
46  _cycler(copy._cycler),
47  _current_thread(copy._current_thread),
48  _pointer(copy._pointer),
49  _stage(copy._stage)
50 {
51  nassertv(_pointer != (const CycleDataType *)NULL);
52  _cycler->increment_read(_pointer);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: CycleDataLockedStageReader::Copy Assignment (full)
57 // Access: Public
58 // Description:
59 ////////////////////////////////////////////////////////////////////
60 template<class CycleDataType>
63  nassertv(_pointer == (CycleDataType *)NULL);
64  nassertv(_current_thread == copy._current_thread);
65 
66  _cycler = copy._cycler;
67  _pointer = copy._pointer;
68  _stage = copy._stage;
69 
70  nassertv(_pointer != (const CycleDataType *)NULL);
71  _cycler->increment_read(_pointer);
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: CycleDataLockedStageReader::Destructor (full)
76 // Access: Public
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 template<class CycleDataType>
82  if (_pointer != NULL) {
83  _cycler->release_read_stage(_stage, _pointer);
84  }
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: CycleDataLockedStageReader::operator -> (full)
89 // Access: Public
90 // Description: This provides an indirect member access to the actual
91 // CycleData data.
92 ////////////////////////////////////////////////////////////////////
93 template<class CycleDataType>
94 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
95 operator -> () const {
96  nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat());
97  return _pointer;
98 }
99 
100 ////////////////////////////////////////////////////////////////////
101 // Function: CycleDataLockedStageReader::Typecast pointer (full)
102 // Access: Public
103 // Description: This allows the CycleDataLockedStageReader to be passed to any
104 // function that expects a const CycleDataType pointer.
105 ////////////////////////////////////////////////////////////////////
106 template<class CycleDataType>
108 operator const CycleDataType * () const {
109  nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat());
110  return _pointer;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: CycleDataLockedStageReader::take_pointer (full)
115 // Access: Public
116 // Description: This is intended to be called only from
117 // CycleDataStageWriter when it elevates the pointer from
118 // read to write status. This function returns the
119 // reader's pointer and relinquishes ownership of the
120 // pointer, rendering the reader invalid for future
121 // reads.
122 ////////////////////////////////////////////////////////////////////
123 template<class CycleDataType>
124 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
125 take_pointer() {
126  const CycleDataType *pointer = _pointer;
127  _pointer = (CycleDataType *)NULL;
128  nassertr(pointer != (const CycleDataType *)NULL, _cycler->cheat());
129  return pointer;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: CycleDataLockedStageReader::get_current_thread (full)
134 // Access: Public
135 // Description: Returns the Thread pointer of the currently-executing
136 // thread, as passed to the constructor of this object.
137 ////////////////////////////////////////////////////////////////////
138 template<class CycleDataType>
140 get_current_thread() const {
141  return _current_thread;
142 }
143 
144 #else // !DO_PIPELINING
145 // This is the trivial, do-nothing implementation.
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: CycleDataLockedStageReader::Constructor (trivial)
149 // Access: Public
150 // Description:
151 ////////////////////////////////////////////////////////////////////
152 template<class CycleDataType>
155  Thread *) {
156  _pointer = cycler.cheat();
157 }
158 
159 ////////////////////////////////////////////////////////////////////
160 // Function: CycleDataLockedStageReader::Copy Constructor (trivial)
161 // Access: Public
162 // Description:
163 ////////////////////////////////////////////////////////////////////
164 template<class CycleDataType>
167  _pointer(copy._pointer)
168 {
169 }
170 
171 ////////////////////////////////////////////////////////////////////
172 // Function: CycleDataLockedStageReader::Copy Assignment (trivial)
173 // Access: Public
174 // Description:
175 ////////////////////////////////////////////////////////////////////
176 template<class CycleDataType>
179  _pointer = copy._pointer;
180 }
181 
182 ////////////////////////////////////////////////////////////////////
183 // Function: CycleDataLockedStageReader::Destructor (trivial)
184 // Access: Public
185 // Description:
186 ////////////////////////////////////////////////////////////////////
187 template<class CycleDataType>
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: CycleDataLockedStageReader::operator -> (trivial)
194 // Access: Public
195 // Description: This provides an indirect member access to the actual
196 // CycleData data.
197 ////////////////////////////////////////////////////////////////////
198 template<class CycleDataType>
199 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
200 operator -> () const {
201  return _pointer;
202 }
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: CycleDataLockedStageReader::Typecast pointer (trivial)
206 // Access: Public
207 // Description: This allows the CycleDataLockedStageReader to be passed to any
208 // function that expects a const CycleDataType pointer.
209 ////////////////////////////////////////////////////////////////////
210 template<class CycleDataType>
212 operator const CycleDataType * () const {
213  return _pointer;
214 }
215 
216 ////////////////////////////////////////////////////////////////////
217 // Function: CycleDataLockedStageReader::take_pointer (trivial)
218 // Access: Public
219 // Description: This is intended to be called only from
220 // CycleDataStageWriter when it elevates the pointer from
221 // read to write status. This function returns the
222 // reader's pointer and relinquishes ownership of the
223 // pointer, rendering the reader invalid for future
224 // reads.
225 ////////////////////////////////////////////////////////////////////
226 template<class CycleDataType>
227 INLINE const CycleDataType *CycleDataLockedStageReader<CycleDataType>::
229  return _pointer;
230 }
231 
232 ////////////////////////////////////////////////////////////////////
233 // Function: CycleDataLockedStageReader::get_current_thread (trivial)
234 // Access: Public
235 // Description: Returns the Thread pointer of the currently-executing
236 // thread, as passed to the constructor of this object.
237 ////////////////////////////////////////////////////////////////////
238 template<class CycleDataType>
242 }
243 
244 #endif // DO_PIPELINING
245 #endif // CPPPARSER
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataStageWriter when it elevates the pointer from read t...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
const CycleDataType * operator->() const
This provides an indirect member access to the actual CycleData data.
CycleDataType * cheat() const
Returns a pointer without counting it.
This class is similar to CycleDataLockedReader, except it allows reading from a particular stage of t...
A thread; that is, a lightweight process.
Definition: thread.h:51
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...