00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PIPELINECYCLER_H
00016 #define PIPELINECYCLER_H
00017
00018 #include "pandabase.h"
00019 #include "pipelineCyclerBase.h"
00020 #include "cyclerHolder.h"
00021 #include "thread.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 template<class CycleDataType>
00054 struct PipelineCycler : public PipelineCyclerBase {
00055 public:
00056 INLINE PipelineCycler(Pipeline *pipeline = NULL);
00057 INLINE PipelineCycler(const PipelineCycler<CycleDataType> ©);
00058 INLINE void operator = (const PipelineCycler<CycleDataType> ©);
00059
00060 INLINE const CycleDataType *read_unlocked(Thread *current_thread) const;
00061 INLINE const CycleDataType *read(Thread *current_thread) const;
00062 INLINE CycleDataType *write(Thread *current_thread);
00063 INLINE CycleDataType *write_upstream(bool force_to_0, Thread *current_thread);
00064 INLINE CycleDataType *elevate_read(const CycleDataType *pointer, Thread *current_thread);
00065 INLINE CycleDataType *elevate_read_upstream(const CycleDataType *pointer, bool force_to_0, Thread *current_thread);
00066
00067 INLINE const CycleDataType *read_stage_unlocked(int pipeline_stage) const;
00068 INLINE const CycleDataType *read_stage(int pipeline_stage, Thread *current_thread) const;
00069 INLINE CycleDataType *elevate_read_stage(int pipeline_stage, const CycleDataType *pointer, Thread *current_thread);
00070 INLINE CycleDataType *elevate_read_stage_upstream(int pipeline_stage, const CycleDataType *pointer, bool force_to_0, Thread *current_thread);
00071 INLINE CycleDataType *write_stage_upstream(int pipeline_stage, bool force_to_0, Thread *current_thread);
00072 INLINE CycleDataType *write_stage(int pipeline_stage, Thread *current_thread);
00073
00074 INLINE CycleDataType *cheat() const;
00075
00076 #ifndef DO_PIPELINING
00077 private:
00078
00079
00080 CycleDataType _typed_data;
00081 #endif // !DO_PIPELINING
00082 };
00083
00084
00085
00086
00087
00088
00089
00090 #ifdef DO_PIPELINING
00091
00092
00093
00094 #define OPEN_ITERATE_UPSTREAM_ONLY(cycler, current_thread) { \
00095 CyclerHolder cholder(cycler); \
00096 int pipeline_stage; \
00097 for (pipeline_stage = current_thread->get_pipeline_stage() - 1; \
00098 pipeline_stage >= 0; \
00099 --pipeline_stage)
00100
00101 #define CLOSE_ITERATE_UPSTREAM_ONLY(cycler) \
00102 }
00103
00104
00105
00106 #define OPEN_ITERATE_CURRENT_AND_UPSTREAM(cycler, current_thread) { \
00107 CyclerHolder cholder(cycler); \
00108 int pipeline_stage; \
00109 for (pipeline_stage = current_thread->get_pipeline_stage(); \
00110 pipeline_stage >= 0; \
00111 --pipeline_stage)
00112
00113 #define CLOSE_ITERATE_CURRENT_AND_UPSTREAM(cycler) \
00114 }
00115
00116
00117 #define OPEN_ITERATE_CURRENT_AND_UPSTREAM_NOLOCK(cycler, current_thread) { \
00118 int pipeline_stage; \
00119 for (pipeline_stage = current_thread->get_pipeline_stage(); \
00120 pipeline_stage >= 0; \
00121 --pipeline_stage)
00122
00123 #define CLOSE_ITERATE_CURRENT_AND_UPSTREAM_NOLOCK(cycler) \
00124 }
00125
00126
00127 #define OPEN_ITERATE_ALL_STAGES(cycler) { \
00128 int pipeline_stage; \
00129 for (pipeline_stage = (cycler).get_num_stages() - 1; \
00130 pipeline_stage >= 0; \
00131 --pipeline_stage)
00132
00133 #define CLOSE_ITERATE_ALL_STAGES(cycler) \
00134 }
00135
00136 #else // DO_PIPELINING
00137
00138
00139
00140
00141 #define OPEN_ITERATE_UPSTREAM_ONLY(cycler, current_thread) \
00142 if (false) { \
00143 const int pipeline_stage = -1;
00144
00145 #define CLOSE_ITERATE_UPSTREAM_ONLY(cycler) \
00146 }
00147
00148 #define OPEN_ITERATE_CURRENT_AND_UPSTREAM(cycler, current_thread) { \
00149 const int pipeline_stage = 0; \
00150
00151 #define CLOSE_ITERATE_CURRENT_AND_UPSTREAM(cycler) \
00152 }
00153
00154 #define OPEN_ITERATE_CURRENT_AND_UPSTREAM_NOLOCK(cycler, current_thread) { \
00155 const int pipeline_stage = 0; \
00156
00157 #define CLOSE_ITERATE_CURRENT_AND_UPSTREAM_NOLOCK(cycler) \
00158 }
00159
00160 #define OPEN_ITERATE_ALL_STAGES(cycler) { \
00161 const int pipeline_stage = 0; \
00162
00163 #define CLOSE_ITERATE_ALL_STAGES(cycler) \
00164 }
00165
00166 #endif // DO_PIPELINING
00167
00168 #include "pipelineCycler.I"
00169
00170 #endif
00171