Panda3D
 All Classes Functions Variables Enumerations
pipelineCyclerTrueImpl.h
1 // Filename: pipelineCyclerTrueImpl.h
2 // Created by: drose (31Jan06)
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 PIPELINECYCLERTRUEIMPL_H
16 #define PIPELINECYCLERTRUEIMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h" // for THREADED_PIPELINE definition
20 
21 #ifdef THREADED_PIPELINE
22 
23 #include "pipelineCyclerLinks.h"
24 #include "cycleData.h"
25 #include "pointerTo.h"
26 #include "nodePointerTo.h"
27 #include "thread.h"
28 #include "reMutex.h"
29 #include "reMutexHolder.h"
30 
31 class Pipeline;
32 
33 ////////////////////////////////////////////////////////////////////
34 // Class : PipelineCyclerTrueImpl
35 // Description : This is the true, threaded implementation of
36 // PipelineCyclerBase. It is only compiled when
37 // threading is available and DO_PIPELINING is defined.
38 //
39 // This implementation is designed to do the actual work
40 // of cycling the data through a pipeline, and returning
41 // the actual CycleData appropriate to the current
42 // thread's pipeline stage.
43 //
44 // This is defined as a struct instead of a class,
45 // mainly to be consistent with
46 // PipelineCyclerTrivialImpl.
47 ////////////////////////////////////////////////////////////////////
48 struct EXPCL_PANDA_PIPELINE PipelineCyclerTrueImpl : public PipelineCyclerLinks {
49 private:
50  PipelineCyclerTrueImpl();
51 public:
52  PipelineCyclerTrueImpl(CycleData *initial_data, Pipeline *pipeline = NULL);
53  PipelineCyclerTrueImpl(const PipelineCyclerTrueImpl &copy);
54  void operator = (const PipelineCyclerTrueImpl &copy);
55  ~PipelineCyclerTrueImpl();
56 
57  INLINE void acquire();
58  INLINE void acquire(Thread *current_thread);
59  INLINE void release();
60 
61  INLINE const CycleData *read_unlocked(Thread *current_thread) const;
62 
63  INLINE const CycleData *read(Thread *current_thread) const;
64  INLINE void increment_read(const CycleData *pointer) const;
65  INLINE void release_read(const CycleData *pointer) const;
66 
67  INLINE CycleData *write(Thread *current_thread);
68  INLINE CycleData *write_upstream(bool force_to_0, Thread *current_thread);
69  INLINE CycleData *elevate_read(const CycleData *pointer, Thread *current_thread);
70  INLINE CycleData *elevate_read_upstream(const CycleData *pointer, bool force_to_0, Thread *current_thread);
71  INLINE void increment_write(CycleData *pointer) const;
72  INLINE void release_write(CycleData *pointer);
73 
74  INLINE int get_num_stages();
75  INLINE const CycleData *read_stage_unlocked(int pipeline_stage) const;
76  INLINE const CycleData *read_stage(int pipeline_stage, Thread *current_thread) const;
77  INLINE void release_read_stage(int pipeline_stage, const CycleData *pointer) const;
78  CycleData *write_stage(int pipeline_stage, Thread *current_thread);
79  CycleData *write_stage_upstream(int pipeline_stage, bool force_to_0,
80  Thread *current_thread);
81  INLINE CycleData *elevate_read_stage(int pipeline_stage, const CycleData *pointer,
82  Thread *current_thread);
83  INLINE CycleData *elevate_read_stage_upstream(int pipeline_stage, const CycleData *pointer,
84  bool force_to_0, Thread *current_thread);
85  INLINE void release_write_stage(int pipeline_stage, CycleData *pointer);
86 
87  INLINE TypeHandle get_parent_type() const;
88 
89  INLINE CycleData *cheat() const;
90  INLINE int get_read_count() const;
91  INLINE int get_write_count() const;
92 
93 public:
94  // We redefine the ReMutex class, solely so we can define the
95  // output() operator. This is only useful for debugging, but does
96  // no harm in the production case.
97  class CyclerMutex : public ReMutex {
98  public:
99  INLINE CyclerMutex(PipelineCyclerTrueImpl *cycler);
100 
101 #ifdef DEBUG_THREADS
102  virtual void output(ostream &out) const;
103  PipelineCyclerTrueImpl *_cycler;
104 #endif // DEBUG_THREADS
105  };
106 
107 private:
108  PT(CycleData) cycle();
109  INLINE PT(CycleData) cycle_2();
110  INLINE PT(CycleData) cycle_3();
111  void set_num_stages(int num_stages);
112 
113 private:
114  Pipeline *_pipeline;
115 
116  // An array of PT(CycleData) objects representing the different
117  // copies of the cycled data, one for each stage.
118  class CycleDataNode : public MemoryBase {
119  public:
120  INLINE CycleDataNode();
121  INLINE CycleDataNode(const CycleDataNode &copy);
122  INLINE ~CycleDataNode();
123  INLINE void operator = (const CycleDataNode &copy);
124 
125  NPT(CycleData) _cdata;
126  int _writes_outstanding;
127  };
128  CycleDataNode *_data;
129  int _num_stages;
130  bool _dirty;
131 
132  CyclerMutex _lock;
133 
134  friend class Pipeline;
135 };
136 
137 #include "pipelineCyclerTrueImpl.I"
138 
139 #endif // THREADED_PIPELINE
140 
141 #endif
142 
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
This class is intended to be the base class of all objects in Panda that might be allocated and delet...
Definition: memoryBase.h:73
This class manages a staged pipeline of data, for instance the render pipeline, so that each stage of...
Definition: pipeline.h:41
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A reentrant mutex.
Definition: reMutex.h:36