Panda3D
cycleDataLockedReader.h
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.h
10  * @author drose
11  * @date 2006-04-30
12  */
13 
14 #ifndef CYCLEDATALOCKEDREADER_H
15 #define CYCLEDATALOCKEDREADER_H
16 
17 #include "pandabase.h"
18 
19 #include "cycleData.h"
20 #include "pipelineCycler.h"
21 #include "thread.h"
22 
23 /**
24  * This template class calls PipelineCycler::read() in the constructor and
25  * PipelineCycler::release_read() in the destructor. In the interim, it
26  * provides a transparent read-only access to the CycleData.
27  *
28  * Since a lock is held on the data while the instance of this class exists,
29  * no other thread may modify any stage of the pipeline during that time.
30  * Thus, this class is appropriate to use for cases in which you might want to
31  * read and then modify the data. It is possible to pass an instance of
32  * CycleDataLockedReader to the CycleDataWriter constructor, which
33  * automatically elevates the read lock into a write lock.
34  *
35  * It exists as a syntactic convenience to access the data in the CycleData.
36  * It also allows the whole system to compile down to nothing if DO_PIPELINING
37  * is not defined.
38  */
39 template<class CycleDataType>
41 public:
42  // By hiding this template from interrogate, we improve compile-time speed
43  // and memory utilization.
44 #ifndef CPPPARSER
46  Thread *current_thread = Thread::get_current_thread());
49 
50  INLINE void operator = (const CycleDataLockedReader<CycleDataType> &copy);
51  INLINE void operator = (CycleDataLockedReader<CycleDataType> &&from) noexcept;
52 
53  INLINE ~CycleDataLockedReader();
54 
55  INLINE const CycleDataType *operator -> () const;
56  INLINE operator const CycleDataType * () const;
57 
58  INLINE const CycleDataType *take_pointer();
59  INLINE Thread *get_current_thread() const;
60 
61 private:
62 #ifdef DO_PIPELINING
63  // This is the data stored for a real pipelining implementation.
64  const PipelineCycler<CycleDataType> *_cycler;
65  Thread *_current_thread;
66  const CycleDataType *_pointer;
67  CycleDataType *_write_pointer;
68 #else // !DO_PIPELINING
69  // This is all we need for the trivial, do-nothing implementation.
70  const CycleDataType *_pointer;
71 #endif // DO_PIPELINING
72 #endif // CPPPARSER
73 };
74 
75 #include "cycleDataLockedReader.I"
76 
77 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class maintains different copies of a page of data between stages of the graphics pipeline (or a...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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