Panda3D
 All Classes Functions Variables Enumerations
cycleDataLockedReader.h
1 // Filename: cycleDataLockedReader.h
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 CYCLEDATALOCKEDREADER_H
16 #define CYCLEDATALOCKEDREADER_H
17 
18 #include "pandabase.h"
19 
20 #include "cycleData.h"
21 #include "pipelineCycler.h"
22 #include "thread.h"
23 
24 ////////////////////////////////////////////////////////////////////
25 // Class : CycleDataLockedReader
26 // Description : This template class calls PipelineCycler::read() in
27 // the constructor and PipelineCycler::release_read() in
28 // the destructor. In the interim, it provides a
29 // transparent read-only access to the CycleData.
30 //
31 // Since a lock is held on the data while the instance
32 // of this class exists, no other thread may modify any
33 // stage of the pipeline during that time. Thus, this
34 // class is appropriate to use for cases in which you
35 // might want to read and then modify the data. It is
36 // possible to pass an instance of CycleDataLockedReader
37 // to the CycleDataWriter constructor, which
38 // automatically elevates the read lock into a write
39 // lock.
40 //
41 // It exists as a syntactic convenience to access the
42 // data in the CycleData. It also allows the whole
43 // system to compile down to nothing if
44 // DO_PIPELINING is not defined.
45 ////////////////////////////////////////////////////////////////////
46 template<class CycleDataType>
48 public:
49  // By hiding this template from interrogate, we improve compile-time
50  // speed and memory utilization.
51 #ifndef CPPPARSER
53  Thread *current_thread = Thread::get_current_thread());
54  INLINE CycleDataLockedReader(const CycleDataLockedReader<CycleDataType> &copy);
55  INLINE void operator = (const CycleDataLockedReader<CycleDataType> &copy);
56 
57  INLINE ~CycleDataLockedReader();
58 
59  INLINE const CycleDataType *operator -> () const;
60  INLINE operator const CycleDataType * () const;
61 
62  INLINE const CycleDataType *take_pointer();
63  INLINE Thread *get_current_thread() const;
64 
65 private:
66 #ifdef DO_PIPELINING
67  // This is the data stored for a real pipelining implementation.
68  const PipelineCycler<CycleDataType> *_cycler;
69  Thread *_current_thread;
70  const CycleDataType *_pointer;
71  CycleDataType *_write_pointer;
72 #else // !DO_PIPELINING
73  // This is all we need for the trivial, do-nothing implementation.
74  const CycleDataType *_pointer;
75 #endif // DO_PIPELINING
76 #endif // CPPPARSER
77 };
78 
79 #include "cycleDataLockedReader.I"
80 
81 #endif
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
const CycleDataType * take_pointer()
This is intended to be called only from CycleDataWriter when it elevates the pointer from read to wri...
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:51