Panda3D
cycleDataLockedReader.I
1 // Filename: cycleDataLockedReader.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: CycleDataLockedReader::Constructor (full)
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 template<class CycleDataType>
29  Thread *current_thread) :
30  _cycler(&cycler),
31  _current_thread(current_thread)
32 {
33  _pointer = _cycler->read(_current_thread);
34  nassertv(_pointer != (const CycleDataType *)NULL);
35 }
36 
37 ////////////////////////////////////////////////////////////////////
38 // Function: CycleDataLockedReader::Copy Constructor (full)
39 // Access: Public
40 // Description:
41 ////////////////////////////////////////////////////////////////////
42 template<class CycleDataType>
45  _cycler(copy._cycler),
46  _current_thread(copy._current_thread),
47  _pointer(copy._pointer)
48 {
49  nassertv(_pointer != (const CycleDataType *)NULL);
50  _cycler->increment_read(_pointer);
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: CycleDataLockedReader::Copy Assignment (full)
55 // Access: Public
56 // Description:
57 ////////////////////////////////////////////////////////////////////
58 template<class CycleDataType>
61  nassertv(_pointer == (CycleDataType *)NULL);
62  nassertv(_current_thread == copy._current_thread);
63 
64  _cycler = copy._cycler;
65  _pointer = copy._pointer;
66 
67  nassertv(_pointer != (const CycleDataType *)NULL);
68  _cycler->increment_read(_pointer);
69 }
70 
71 ////////////////////////////////////////////////////////////////////
72 // Function: CycleDataLockedReader::Destructor (full)
73 // Access: Public
74 // Description:
75 ////////////////////////////////////////////////////////////////////
76 template<class CycleDataType>
79  if (_pointer != NULL) {
80  _cycler->release_read(_pointer);
81  }
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: CycleDataLockedReader::operator -> (full)
86 // Access: Public
87 // Description: This provides an indirect member access to the actual
88 // CycleData data.
89 ////////////////////////////////////////////////////////////////////
90 template<class CycleDataType>
91 INLINE const CycleDataType *CycleDataLockedReader<CycleDataType>::
92 operator -> () const {
93  nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat());
94  return _pointer;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: CycleDataLockedReader::Typecast pointer (full)
99 // Access: Public
100 // Description: This allows the CycleDataLockedReader to be passed to any
101 // function that expects a const CycleDataType pointer.
102 ////////////////////////////////////////////////////////////////////
103 template<class CycleDataType>
105 operator const CycleDataType * () const {
106  nassertr(_pointer != (const CycleDataType *)NULL, _cycler->cheat());
107  return _pointer;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: CycleDataLockedReader::take_pointer (full)
112 // Access: Public
113 // Description: This is intended to be called only from
114 // CycleDataWriter when it elevates the pointer from
115 // read to write status. This function returns the
116 // reader's pointer and relinquishes ownership of the
117 // pointer, rendering the reader invalid for future
118 // reads.
119 ////////////////////////////////////////////////////////////////////
120 template<class CycleDataType>
121 INLINE const CycleDataType *CycleDataLockedReader<CycleDataType>::
122 take_pointer() {
123  const CycleDataType *pointer = _pointer;
124  _pointer = (CycleDataType *)NULL;
125  nassertr(pointer != (const CycleDataType *)NULL, _cycler->cheat());
126  return pointer;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: CycleDataLockedReader::get_current_thread (full)
131 // Access: Public
132 // Description: Returns the Thread pointer of the currently-executing
133 // thread, as passed to the constructor of this object.
134 ////////////////////////////////////////////////////////////////////
135 template<class CycleDataType>
137 get_current_thread() const {
138  return _current_thread;
139 }
140 
141 #else // !DO_PIPELINING
142 // This is the trivial, do-nothing implementation.
143 
144 ////////////////////////////////////////////////////////////////////
145 // Function: CycleDataLockedReader::Constructor (trivial)
146 // Access: Public
147 // Description:
148 ////////////////////////////////////////////////////////////////////
149 template<class CycleDataType>
152  _pointer = cycler.cheat();
153 }
154 
155 ////////////////////////////////////////////////////////////////////
156 // Function: CycleDataLockedReader::Copy Constructor (trivial)
157 // Access: Public
158 // Description:
159 ////////////////////////////////////////////////////////////////////
160 template<class CycleDataType>
163  _pointer(copy._pointer)
164 {
165 }
166 
167 ////////////////////////////////////////////////////////////////////
168 // Function: CycleDataLockedReader::Copy Assignment (trivial)
169 // Access: Public
170 // Description:
171 ////////////////////////////////////////////////////////////////////
172 template<class CycleDataType>
175  _pointer = copy._pointer;
176 }
177 
178 ////////////////////////////////////////////////////////////////////
179 // Function: CycleDataLockedReader::Destructor (trivial)
180 // Access: Public
181 // Description:
182 ////////////////////////////////////////////////////////////////////
183 template<class CycleDataType>
186 }
187 
188 ////////////////////////////////////////////////////////////////////
189 // Function: CycleDataLockedReader::operator -> (trivial)
190 // Access: Public
191 // Description: This provides an indirect member access to the actual
192 // CycleData data.
193 ////////////////////////////////////////////////////////////////////
194 template<class CycleDataType>
195 INLINE const CycleDataType *CycleDataLockedReader<CycleDataType>::
196 operator -> () const {
197  return _pointer;
198 }
199 
200 ////////////////////////////////////////////////////////////////////
201 // Function: CycleDataLockedReader::Typecast pointer (trivial)
202 // Access: Public
203 // Description: This allows the CycleDataLockedReader to be passed to any
204 // function that expects a const CycleDataType pointer.
205 ////////////////////////////////////////////////////////////////////
206 template<class CycleDataType>
208 operator const CycleDataType * () const {
209  return _pointer;
210 }
211 
212 ////////////////////////////////////////////////////////////////////
213 // Function: CycleDataLockedReader::take_pointer (trivial)
214 // Access: Public
215 // Description: This is intended to be called only from
216 // CycleDataWriter when it elevates the pointer from
217 // read to write status. This function returns the
218 // reader's pointer and relinquishes ownership of the
219 // pointer, rendering the reader invalid for future
220 // reads.
221 ////////////////////////////////////////////////////////////////////
222 template<class CycleDataType>
223 INLINE const CycleDataType *CycleDataLockedReader<CycleDataType>::
225  return _pointer;
226 }
227 
228 ////////////////////////////////////////////////////////////////////
229 // Function: CycleDataLockedReader::get_current_thread (trivial)
230 // Access: Public
231 // Description: Returns the Thread pointer of the currently-executing
232 // thread, as passed to the constructor of this object.
233 ////////////////////////////////////////////////////////////////////
234 template<class CycleDataType>
238 }
239 
240 #endif // DO_PIPELINING
241 #endif // CPPPARSER
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.
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.
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataWriter when it elevates the pointer from read to wri...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
This template class calls PipelineCycler::read() in the constructor and PipelineCycler::release_read(...
A thread; that is, a lightweight process.
Definition: thread.h:51