00001 // Filename: deletedBufferChain.I 00002 // Created by: drose (20Jul07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: DeletedBufferChain::validate 00018 // Access: Public 00019 // Description: Returns true if the pointer is valid, false if it has 00020 // been deleted or if it was never a valid pointer. 00021 // 00022 // This is only meaningful in debug mode, where 00023 // USE_DELETEDCHAINFLAG is defined. If not, this 00024 // trivially returns true. 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE bool DeletedBufferChain:: 00027 validate(void *ptr) { 00028 TAU_PROFILE("bool DeletedBufferChain::validate(void *)", " ", TAU_USER); 00029 if (ptr == (void *)NULL) { 00030 return false; 00031 } 00032 00033 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN) 00034 const ObjectNode *obj = buffer_to_node(ptr); 00035 return AtomicAdjust::get(obj->_flag) == DCF_alive; 00036 #else 00037 return true; 00038 #endif // USE_DELETEDCHAINFLAG 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: DeletedBufferChain::get_buffer_size 00043 // Access: Public 00044 // Description: Returns the size of the buffer that is actually 00045 // returned at each request. 00046 //////////////////////////////////////////////////////////////////// 00047 INLINE size_t DeletedBufferChain:: 00048 get_buffer_size() const { 00049 return _buffer_size; 00050 } 00051 00052 //////////////////////////////////////////////////////////////////// 00053 // Function: DeletedBufferChain::node_to_buffer 00054 // Access: Private, Static 00055 // Description: Casts an ObjectNode* to a void* buffer. 00056 //////////////////////////////////////////////////////////////////// 00057 INLINE void *DeletedBufferChain:: 00058 node_to_buffer(DeletedBufferChain::ObjectNode *node) { 00059 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN) 00060 // In development mode, we increment the pointer so that the 00061 // returned data does not overlap our _flag member. 00062 return (void *)(((char *)node) + get_flag_reserved_bytes()); 00063 #else 00064 return (void *)node; 00065 #endif // NDEBUG 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: DeletedBufferChain::buffer_to_node 00070 // Access: Private, Static 00071 // Description: Casts a void* buffer to an ObjectNode* . 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE DeletedBufferChain::ObjectNode *DeletedBufferChain:: 00074 buffer_to_node(void *ptr) { 00075 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN) 00076 // In development mode, we decrement the pointer to undo the 00077 // increment we did above. 00078 return (ObjectNode *)(((char *)ptr) - get_flag_reserved_bytes()); 00079 #else 00080 return (ObjectNode *)ptr; 00081 #endif // NDEBUG 00082 } 00083 00084 //////////////////////////////////////////////////////////////////// 00085 // Function: DeletedBufferChain::get_flag_reserved_bytes 00086 // Access: Private, Static 00087 // Description: Returns the number of extra bytes reserved at the 00088 // beginning of each buffer for the _flag member. 00089 //////////////////////////////////////////////////////////////////// 00090 INLINE size_t DeletedBufferChain:: 00091 get_flag_reserved_bytes() { 00092 #ifndef USE_DELETEDCHAINFLAG 00093 // Without DELETEDCHAINFLAG, we don't even store the _flag member at 00094 // all, and this method is never called. 00095 static const size_t flag_reserved_bytes = 0; 00096 00097 #elif defined(LINMATH_ALIGN) 00098 // With SSE2 alignment, we need all 16 bytes to preserve alignment. 00099 static const size_t flag_reserved_bytes = 16; 00100 00101 #else 00102 // Otherwise, we only need enough space for the Integer itself. 00103 static const size_t flag_reserved_bytes = sizeof(AtomicAdjust::Integer); 00104 #endif // USE_DELETEDCHAINFLAG 00105 00106 return flag_reserved_bytes; 00107 }