Panda3D

Loading...
Searching...
No Matches
pipelineCyclerTrueImpl.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 pipelineCyclerTrueImpl.h
10 * @author drose
11 * @date 2006-01-31
12 */
13
14#ifndef PIPELINECYCLERTRUEIMPL_H
15#define PIPELINECYCLERTRUEIMPL_H
16
17#include "pandabase.h"
18#include "selectThreadImpl.h" // for THREADED_PIPELINE definition
19
20#ifdef THREADED_PIPELINE
21
22#include "pipelineCyclerLinks.h"
23#include "cycleData.h"
24#include "pointerTo.h"
25#include "nodePointerTo.h"
26#include "thread.h"
27#include "reMutex.h"
28#include "reMutexHolder.h"
29
30 class Pipeline;
31
32/**
33 * This is the true, threaded implementation of PipelineCyclerBase. It is
34 * only compiled when threading is available and DO_PIPELINING is defined.
35 *
36 * This implementation is designed to do the actual work of cycling the data
37 * through a pipeline, and returning the actual CycleData appropriate to the
38 * current thread's pipeline stage.
39 *
40 * This is defined as a struct instead of a class, mainly to be consistent
41 * with PipelineCyclerTrivialImpl.
42 */
43 struct EXPCL_PANDA_PIPELINE PipelineCyclerTrueImpl : public PipelineCyclerLinks {
44 private:
45 PipelineCyclerTrueImpl();
46 public:
47 PipelineCyclerTrueImpl(CycleData *initial_data, Pipeline *pipeline = nullptr);
48 PipelineCyclerTrueImpl(const PipelineCyclerTrueImpl &copy);
49 void operator = (const PipelineCyclerTrueImpl &copy);
50 ~PipelineCyclerTrueImpl();
51
52 INLINE void acquire();
53 INLINE void acquire(Thread *current_thread);
54 INLINE void release();
55
56 INLINE const CycleData *read_unlocked(Thread *current_thread) const;
57
58 INLINE const CycleData *read(Thread *current_thread) const;
59 INLINE void increment_read(const CycleData *pointer) const;
60 INLINE void release_read(const CycleData *pointer) const;
61
62 INLINE CycleData *write(Thread *current_thread);
63 INLINE CycleData *write_upstream(bool force_to_0, Thread *current_thread);
64 INLINE CycleData *elevate_read(const CycleData *pointer, Thread *current_thread);
65 INLINE CycleData *elevate_read_upstream(const CycleData *pointer, bool force_to_0, Thread *current_thread);
66 INLINE void increment_write(CycleData *pointer) const;
67 INLINE void release_write(CycleData *pointer);
68
69 INLINE int get_num_stages();
70 INLINE const CycleData *read_stage_unlocked(int pipeline_stage) const;
71 INLINE const CycleData *read_stage(int pipeline_stage, Thread *current_thread) const;
72 INLINE void release_read_stage(int pipeline_stage, const CycleData *pointer) const;
73 CycleData *write_stage(int pipeline_stage, Thread *current_thread);
74 CycleData *write_stage_upstream(int pipeline_stage, bool force_to_0,
75 Thread *current_thread);
76 INLINE CycleData *elevate_read_stage(int pipeline_stage, const CycleData *pointer,
77 Thread *current_thread);
78 INLINE CycleData *elevate_read_stage_upstream(int pipeline_stage, const CycleData *pointer,
79 bool force_to_0, Thread *current_thread);
80 INLINE void release_write_stage(int pipeline_stage, CycleData *pointer);
81
82 INLINE TypeHandle get_parent_type() const;
83
84 INLINE CycleData *cheat() const;
85 INLINE int get_read_count() const;
86 INLINE int get_write_count() const;
87
88 public:
89 // We redefine the ReMutex class, solely so we can define the output()
90 // operator. This is only useful for debugging, but does no harm in the
91 // production case.
92 class CyclerMutex : public ReMutex {
93 public:
94 INLINE CyclerMutex(PipelineCyclerTrueImpl *cycler);
95
96#ifdef DEBUG_THREADS
97 virtual void output(std::ostream &out) const;
98 PipelineCyclerTrueImpl *_cycler;
99#endif // DEBUG_THREADS
100 };
101
102 private:
103 PT(CycleData) cycle();
104 INLINE PT(CycleData) cycle_2();
105 INLINE PT(CycleData) cycle_3();
106 void set_num_stages(int num_stages);
107
108 private:
109 Pipeline *_pipeline;
110
111 // An array of PT(CycleData) objects representing the different copies of
112 // the cycled data, one for each stage.
113 class CycleDataNode : public MemoryBase {
114 public:
115 INLINE CycleDataNode();
116 INLINE CycleDataNode(const CycleDataNode &copy);
117 INLINE ~CycleDataNode();
118 INLINE void operator = (const CycleDataNode &copy);
119
120 NPT(CycleData) _cdata;
121 int _writes_outstanding;
122 };
123 CycleDataNode *_data;
124 int _num_stages;
125
126 // This is 0 if it's clean, or set to Pipeline::_next_cycle_seq if it's
127 // scheduled to be cycled during the next cycle() call.
128 unsigned int _dirty;
129
130 CyclerMutex _lock;
131
132 friend class Pipeline;
133};
134
135#include "pipelineCyclerTrueImpl.I"
136
137#endif // THREADED_PIPELINE
138
139#endif
PipelineCyclerLinks
This just stores the pointers to implement a doubly-linked list of PipelineCyclers for a particular P...
Definition pipelineCyclerLinks.h:30
Pipeline
This class manages a staged pipeline of data, for instance the render pipeline, so that each stage of...
Definition pipeline.h:38
cycleData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
nodePointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pipelineCyclerLinks.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pipelineCyclerTrueImpl.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
reMutexHolder.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
reMutex.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
selectThreadImpl.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
thread.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.