pipelineCyclerTrivialImpl.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 pipelineCyclerTrivialImpl.h
  10. * @author drose
  11. * @date 2006-01-31
  12. */
  13. #ifndef PIPELINECYCLERTRIVIALIMPL_H
  14. #define PIPELINECYCLERTRIVIALIMPL_H
  15. #include "pandabase.h"
  16. #ifndef DO_PIPELINING
  17. #include "thread.h"
  18. #include "cycleData.h"
  19. class Pipeline;
  20. /**
  21. * This is the trivial, non-threaded implementation of PipelineCyclerBase. It
  22. * is only compiled when DO_PIPELINING is not defined (which usually implies
  23. * that threading is not available).
  24. *
  25. * This implementation is designed to do as little as possible, and to compile
  26. * to nothing, or almost nothing. It doesn't actually support pipelining in
  27. * any way. It doesn't even perform any sanity checks to speak of. It's
  28. * designed for a strictly single-threaded application, and its purpose is to
  29. * be as low-overhead as possible.
  30. *
  31. * We define this as a struct instead of a class to emphasize the importance
  32. * of byte placement within the object, so that the inherited struct's data is
  33. * likely to be placed by the compiler at the "this" pointer.
  34. */
  35. struct EXPCL_PANDA_PIPELINE PipelineCyclerTrivialImpl {
  36. public:
  37. INLINE PipelineCyclerTrivialImpl(CycleData *initial_data, Pipeline *pipeline = nullptr);
  38. PipelineCyclerTrivialImpl(const PipelineCyclerTrivialImpl &copy) = delete;
  39. ~PipelineCyclerTrivialImpl() = default;
  40. PipelineCyclerTrivialImpl &operator = (const PipelineCyclerTrivialImpl &copy) = delete;
  41. INLINE void acquire(Thread *current_thread = nullptr);
  42. INLINE void release();
  43. INLINE const CycleData *read_unlocked(Thread *current_thread) const;
  44. INLINE const CycleData *read(Thread *current_thread) const;
  45. INLINE void increment_read(const CycleData *pointer) const;
  46. INLINE void release_read(const CycleData *pointer) const;
  47. INLINE CycleData *write(Thread *current_thread);
  48. INLINE CycleData *write_upstream(bool force_to_0, Thread *current_thread);
  49. INLINE CycleData *elevate_read(const CycleData *pointer, Thread *current_thread);
  50. INLINE CycleData *elevate_read_upstream(const CycleData *pointer, bool force_to_0,
  51. Thread *current_thread);
  52. INLINE void increment_write(CycleData *pointer) const;
  53. INLINE void release_write(CycleData *pointer);
  54. INLINE int get_num_stages();
  55. INLINE const CycleData *read_stage_unlocked(int pipeline_stage) const;
  56. INLINE const CycleData *read_stage(int pipeline_stage, Thread *current_thread) const;
  57. INLINE void release_read_stage(int pipeline_stage, const CycleData *pointer) const;
  58. INLINE CycleData *write_stage(int pipeline_stage, Thread *current_thread);
  59. INLINE CycleData *write_stage_upstream(int pipeline_stage, bool force_to_0,
  60. Thread *current_thread);
  61. INLINE CycleData *elevate_read_stage(int pipeline_stage, const CycleData *pointer,
  62. Thread *current_thread);
  63. INLINE CycleData *elevate_read_stage_upstream(int pipeline_stage, const CycleData *pointer,
  64. bool force_to_0, Thread *current_thread);
  65. INLINE void release_write_stage(int pipeline_stage, CycleData *pointer);
  66. INLINE TypeHandle get_parent_type() const;
  67. INLINE CycleData *cheat() const;
  68. INLINE int get_read_count() const;
  69. INLINE int get_write_count() const;
  70. // In a trivial implementation, we only need to store the CycleData pointer.
  71. // Actually, we don't even need to do that, if we're lucky and the compiler
  72. // doesn't do anything funny with the struct layout.
  73. #ifndef SIMPLE_STRUCT_POINTERS
  74. CycleData *_data;
  75. #endif // SIMPLE_STRUCT_POINTERS
  76. };
  77. #include "pipelineCyclerTrivialImpl.I"
  78. #endif // !DO_PIPELINING
  79. #endif