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