Panda3D
 All Classes Functions Variables Enumerations
deletedBufferChain.I
1 // Filename: deletedBufferChain.I
2 // Created by: drose (20Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: DeletedBufferChain::validate
18 // Access: Public
19 // Description: Returns true if the pointer is valid, false if it has
20 // been deleted or if it was never a valid pointer.
21 //
22 // This is only meaningful in debug mode, where
23 // USE_DELETEDCHAINFLAG is defined. If not, this
24 // trivially returns true.
25 ////////////////////////////////////////////////////////////////////
26 INLINE bool DeletedBufferChain::
27 validate(void *ptr) {
28  TAU_PROFILE("bool DeletedBufferChain::validate(void *)", " ", TAU_USER);
29  if (ptr == (void *)NULL) {
30  return false;
31  }
32 
33 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
34  const ObjectNode *obj = buffer_to_node(ptr);
35  return AtomicAdjust::get(obj->_flag) == DCF_alive;
36 #else
37  return true;
38 #endif // USE_DELETEDCHAINFLAG
39 }
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 ////////////////////////////////////////////////////////////////////
53 // Function: DeletedBufferChain::node_to_buffer
54 // Access: Private, Static
55 // Description: Casts an ObjectNode* to a void* buffer.
56 ////////////////////////////////////////////////////////////////////
57 INLINE void *DeletedBufferChain::
58 node_to_buffer(DeletedBufferChain::ObjectNode *node) {
59 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
60  // In development mode, we increment the pointer so that the
61  // returned data does not overlap our _flag member.
62  return (void *)(((char *)node) + flag_reserved_bytes);
63 #else
64  return (void *)node;
65 #endif // NDEBUG
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: DeletedBufferChain::buffer_to_node
70 // Access: Private, Static
71 // Description: Casts a void* buffer to an ObjectNode* .
72 ////////////////////////////////////////////////////////////////////
73 INLINE DeletedBufferChain::ObjectNode *DeletedBufferChain::
74 buffer_to_node(void *ptr) {
75 #if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
76  // In development mode, we decrement the pointer to undo the
77  // increment we did above.
78  return (ObjectNode *)(((char *)ptr) - flag_reserved_bytes);
79 #else
80  return (ObjectNode *)ptr;
81 #endif // NDEBUG
82 }
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
bool validate(void *ptr)
Returns true if the pointer is valid, false if it has been deleted or if it was never a valid pointer...
size_t get_buffer_size() const
Returns the size of the buffer that is actually returned at each request.