2
0

bufferContextChain.cxx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 bufferContextChain.cxx
  10. * @author drose
  11. * @date 2006-03-16
  12. */
  13. #include "bufferContextChain.h"
  14. #include "bufferContext.h"
  15. #include "indent.h"
  16. #include "lightMutexHolder.h"
  17. /**
  18. * Returns the first BufferContext object stored in the tracker. You can walk
  19. * through the entire list of objects stored on the tracker by calling
  20. * get_next() on each returned object, until the return value is NULL.
  21. *
  22. * This does not grab the lock; make sure you are holding the lock while
  23. * iterating over the chain.
  24. */
  25. BufferContext *BufferContextChain::
  26. get_first() {
  27. // This method is declared non-inline so we can include bufferContext.h,
  28. // which is necessary for proper downcasting of the _next pointer.
  29. if (_next == this) {
  30. return nullptr;
  31. }
  32. return (BufferContext *)_next;
  33. }
  34. /**
  35. * Moves all of the BufferContexts from the other tracker onto this one.
  36. * The other chain must be locked.
  37. */
  38. void BufferContextChain::
  39. take_from(BufferContextChain &other) {
  40. LightMutexHolder holder(_lock);
  41. _total_size += other._total_size;
  42. _count += other._count;
  43. other._total_size = 0;
  44. other._count = 0;
  45. LinkedListNode *llnode = other._next;
  46. while (llnode != &other) {
  47. nassertv(((BufferContext *)llnode)->_owning_chain == &other);
  48. ((BufferContext *)llnode)->_owning_chain = this;
  49. llnode = ((BufferContext *)llnode)->_next;
  50. }
  51. take_list_from(&other);
  52. }
  53. /**
  54. *
  55. */
  56. void BufferContextChain::
  57. write(std::ostream &out, int indent_level) const {
  58. LightMutexHolder holder(_lock);
  59. indent(out, indent_level)
  60. << _count << " objects, consuming " << _total_size << " bytes:\n";
  61. LinkedListNode *llnode = _next;
  62. while (llnode != this) {
  63. ((BufferContext *)llnode)->write(out, indent_level + 2);
  64. llnode = ((BufferContext *)llnode)->_next;
  65. }
  66. }