| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // Filename: deletedBufferChain.I
- // Created by: drose (20Jul07)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
- //
- // All use of this software is subject to the terms of the Panda 3d
- // Software license. You should have received a copy of this license
- // along with this source code; you will also find a current copy of
- // the license at http://etc.cmu.edu/panda3d/docs/license/ .
- //
- // To contact the maintainers of this program write to
- // [email protected] .
- //
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- // Function: DeletedBufferChain::validate
- // Access: Public
- // Description: Returns true if the pointer is valid, false if it has
- // been deleted or if it was never a valid pointer.
- //
- // This is only meaningful in debug mode, where
- // USE_DELETEDCHAINFLAG is defined. If not, this
- // trivially returns true.
- ////////////////////////////////////////////////////////////////////
- INLINE bool DeletedBufferChain::
- validate(void *ptr) {
- TAU_PROFILE("bool DeletedBufferChain::validate(void *)", " ", TAU_USER);
- if (ptr == (void *)NULL) {
- return false;
- }
- #ifdef USE_DELETEDCHAINFLAG
- const ObjectNode *obj = buffer_to_node(ptr);
- return AtomicAdjust::get(obj->_flag) == DCF_alive;
- #else
- return true;
- #endif // USE_DELETEDCHAINFLAG
- }
- ////////////////////////////////////////////////////////////////////
- // Function: DeletedBufferChain::get_buffer_size
- // Access: Public
- // Description: Returns the size of the buffer that is actually
- // returned at each request.
- ////////////////////////////////////////////////////////////////////
- INLINE size_t DeletedBufferChain::
- get_buffer_size() const {
- return _buffer_size;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: DeletedBufferChain::node_to_buffer
- // Access: Private, Static
- // Description: Casts an ObjectNode* to a void* buffer.
- ////////////////////////////////////////////////////////////////////
- INLINE void *DeletedBufferChain::
- node_to_buffer(DeletedBufferChain::ObjectNode *node) {
- #ifdef USE_DELETEDCHAINFLAG
- // In development mode, we increment the pointer so that the
- // returned data does not overlap our _flag member.
- return (void *)(((AtomicAdjust::Integer *)node) + 1);
- #else
- return (void *)node;
- #endif // NDEBUG
- }
- ////////////////////////////////////////////////////////////////////
- // Function: DeletedBufferChain::buffer_to_node
- // Access: Private, Static
- // Description: Casts a void* buffer to an ObjectNode* .
- ////////////////////////////////////////////////////////////////////
- INLINE DeletedBufferChain::ObjectNode *DeletedBufferChain::
- buffer_to_node(void *ptr) {
- #ifdef USE_DELETEDCHAINFLAG
- // In development mode, we decrement the pointer to undo the
- // increment we did above.
- return (ObjectNode *)(((AtomicAdjust::Integer *)ptr) - 1);
- #else
- return (ObjectNode *)ptr;
- #endif // NDEBUG
- }
|