Panda3D
Loading...
Searching...
No Matches
deletedBufferChain.I
Go to the documentation of this file.
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 deletedBufferChain.I
10 * @author drose
11 * @date 2007-07-20
12 */
13
14/**
15 * Returns true if the pointer is valid, false if it has been deleted or if it
16 * was never a valid pointer.
17 *
18 * This is only meaningful in debug mode, where USE_DELETEDCHAINFLAG is
19 * defined. If not, this trivially returns true.
20 */
22validate(void *ptr) {
23 TAU_PROFILE("bool DeletedBufferChain::validate(void *)", " ", TAU_USER);
24 if (ptr == nullptr) {
25 return false;
26 }
27
28#if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
29 const ObjectNode *obj = buffer_to_node(ptr);
30 return AtomicAdjust::get(obj->_flag) == DCF_alive;
31#else
32 return true;
33#endif // USE_DELETEDCHAINFLAG
34}
35
36/**
37 * Returns the size of the buffer that is actually returned at each request.
38 */
40get_buffer_size() const {
41 return _buffer_size;
42}
43
44/**
45 * Casts an ObjectNode* to a void* buffer.
46 */
47INLINE void *DeletedBufferChain::
48node_to_buffer(DeletedBufferChain::ObjectNode *node) {
49#if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
50 // In development mode, we increment the pointer so that the returned data
51 // does not overlap our _flag member.
52 return (void *)(((char *)node) + flag_reserved_bytes);
53#else
54 return (void *)node;
55#endif // NDEBUG
56}
57
58/**
59 * Casts a void* buffer to an ObjectNode* .
60 */
61INLINE DeletedBufferChain::ObjectNode *DeletedBufferChain::
62buffer_to_node(void *ptr) {
63#if defined(USE_DELETEDCHAINFLAG) && defined(USE_DELETED_CHAIN)
64 // In development mode, we decrement the pointer to undo the increment we
65 // did above.
66 return (ObjectNode *)(((char *)ptr) - flag_reserved_bytes);
67#else
68 return (ObjectNode *)ptr;
69#endif // NDEBUG
70}
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
size_t get_buffer_size() const
Returns the size of the buffer that is actually returned at each request.
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...