deletedBufferChain.I 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Filename: deletedBufferChain.I
  2. // Created by: drose (20Jul07)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. ////////////////////////////////////////////////////////////////////
  19. // Function: DeletedBufferChain::validate
  20. // Access: Public
  21. // Description: Returns true if the pointer is valid, false if it has
  22. // been deleted or if it was never a valid pointer.
  23. //
  24. // This is only meaningful in debug mode, where
  25. // USE_DELETEDCHAINFLAG is defined. If not, this
  26. // trivially returns true.
  27. ////////////////////////////////////////////////////////////////////
  28. INLINE bool DeletedBufferChain::
  29. validate(void *ptr) {
  30. TAU_PROFILE("bool DeletedBufferChain::validate(void *)", " ", TAU_USER);
  31. if (ptr == (void *)NULL) {
  32. return false;
  33. }
  34. #ifdef USE_DELETEDCHAINFLAG
  35. const ObjectNode *obj = buffer_to_node(ptr);
  36. return AtomicAdjust::get(obj->_flag) == DCF_alive;
  37. #else
  38. return true;
  39. #endif // USE_DELETEDCHAINFLAG
  40. }
  41. ////////////////////////////////////////////////////////////////////
  42. // Function: DeletedBufferChain::get_buffer_size
  43. // Access: Public
  44. // Description: Returns the size of the buffer that is actually
  45. // returned at each request.
  46. ////////////////////////////////////////////////////////////////////
  47. INLINE size_t DeletedBufferChain::
  48. get_buffer_size() const {
  49. return _buffer_size;
  50. }
  51. ////////////////////////////////////////////////////////////////////
  52. // Function: DeletedBufferChain::node_to_buffer
  53. // Access: Private, Static
  54. // Description: Casts an ObjectNode* to a void* buffer.
  55. ////////////////////////////////////////////////////////////////////
  56. INLINE void *DeletedBufferChain::
  57. node_to_buffer(DeletedBufferChain::ObjectNode *node) {
  58. #ifdef USE_DELETEDCHAINFLAG
  59. // In development mode, we increment the pointer so that the
  60. // returned data does not overlap our _flag member.
  61. return (void *)(((AtomicAdjust::Integer *)node) + 1);
  62. #else
  63. return (void *)node;
  64. #endif // NDEBUG
  65. }
  66. ////////////////////////////////////////////////////////////////////
  67. // Function: DeletedBufferChain::buffer_to_node
  68. // Access: Private, Static
  69. // Description: Casts a void* buffer to an ObjectNode* .
  70. ////////////////////////////////////////////////////////////////////
  71. INLINE DeletedBufferChain::ObjectNode *DeletedBufferChain::
  72. buffer_to_node(void *ptr) {
  73. #ifdef USE_DELETEDCHAINFLAG
  74. // In development mode, we decrement the pointer to undo the
  75. // increment we did above.
  76. return (ObjectNode *)(((AtomicAdjust::Integer *)ptr) - 1);
  77. #else
  78. return (ObjectNode *)ptr;
  79. #endif // NDEBUG
  80. }