| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- /**
- * PANDA 3D SOFTWARE
- * Copyright (c) Carnegie Mellon University. All rights reserved.
- *
- * All use of this software is subject to the terms of the revised BSD
- * license. You should have received a copy of this license along
- * with this source code in a file named "LICENSE."
- *
- * @file bufferContextChain.cxx
- * @author drose
- * @date 2006-03-16
- */
- #include "bufferContextChain.h"
- #include "bufferContext.h"
- #include "indent.h"
- #include "lightMutexHolder.h"
- /**
- * Returns the first BufferContext object stored in the tracker. You can walk
- * through the entire list of objects stored on the tracker by calling
- * get_next() on each returned object, until the return value is NULL.
- *
- * This does not grab the lock; make sure you are holding the lock while
- * iterating over the chain.
- */
- BufferContext *BufferContextChain::
- get_first() {
- // This method is declared non-inline so we can include bufferContext.h,
- // which is necessary for proper downcasting of the _next pointer.
- if (_next == this) {
- return nullptr;
- }
- return (BufferContext *)_next;
- }
- /**
- * Moves all of the BufferContexts from the other tracker onto this one.
- * The other chain must be locked.
- */
- void BufferContextChain::
- take_from(BufferContextChain &other) {
- LightMutexHolder holder(_lock);
- _total_size += other._total_size;
- _count += other._count;
- other._total_size = 0;
- other._count = 0;
- LinkedListNode *llnode = other._next;
- while (llnode != &other) {
- nassertv(((BufferContext *)llnode)->_owning_chain == &other);
- ((BufferContext *)llnode)->_owning_chain = this;
- llnode = ((BufferContext *)llnode)->_next;
- }
- take_list_from(&other);
- }
- /**
- *
- */
- void BufferContextChain::
- write(std::ostream &out, int indent_level) const {
- LightMutexHolder holder(_lock);
- indent(out, indent_level)
- << _count << " objects, consuming " << _total_size << " bytes:\n";
- LinkedListNode *llnode = _next;
- while (llnode != this) {
- ((BufferContext *)llnode)->write(out, indent_level + 2);
- llnode = ((BufferContext *)llnode)->_next;
- }
- }
|