Panda3D
 All Classes Functions Variables Enumerations
pipelineCyclerLinks.I
1 // Filename: pipelineCyclerLinks.I
2 // Created by: drose (16Feb06)
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 #ifdef THREADED_PIPELINE
17 ////////////////////////////////////////////////////////////////////
18 // Function: PipelineCyclerLinks::Constructor
19 // Access: Protected
20 // Description:
21 ////////////////////////////////////////////////////////////////////
22 INLINE PipelineCyclerLinks::
23 PipelineCyclerLinks() {
24 #ifndef NDEBUG
25  _next = NULL;
26  _prev = NULL;
27 #endif
28 }
29 #endif // THREADED_PIPELINE
30 
31 #ifdef THREADED_PIPELINE
32 ////////////////////////////////////////////////////////////////////
33 // Function: PipelineCyclerLinks::Destructor
34 // Access: Protected
35 // Description:
36 ////////////////////////////////////////////////////////////////////
37 INLINE PipelineCyclerLinks::
38 ~PipelineCyclerLinks() {
39  nassertv(_next == NULL && _prev == NULL);
40 }
41 #endif // THREADED_PIPELINE
42 
43 #ifdef THREADED_PIPELINE
44 ////////////////////////////////////////////////////////////////////
45 // Function: PipelineCyclerLinks::make_head
46 // Access: Protected
47 // Description: When called on an empty object, sets it up to be the
48 // head of a linked list.
49 ////////////////////////////////////////////////////////////////////
50 INLINE void PipelineCyclerLinks::
51 make_head() {
52  nassertv(_next == NULL && _prev == NULL);
53  _next = this;
54  _prev = this;
55 }
56 #endif // THREADED_PIPELINE
57 
58 #ifdef THREADED_PIPELINE
59 ////////////////////////////////////////////////////////////////////
60 // Function: PipelineCyclerLinks::clear_head
61 // Access: Protected
62 // Description: When called on the head of an empty linked list,
63 // resets it to an empty object, for safe destruction.
64 ////////////////////////////////////////////////////////////////////
65 INLINE void PipelineCyclerLinks::
66 clear_head() {
67  nassertv(_next == this && _prev == this);
68 #ifndef NDEBUG
69  _next = NULL;
70  _prev = NULL;
71 #endif
72 }
73 #endif // THREADED_PIPELINE
74 
75 #ifdef THREADED_PIPELINE
76 ////////////////////////////////////////////////////////////////////
77 // Function: PipelineCyclerLinks::remove_from_list
78 // Access: Protected
79 // Description: Removes a PipelineCyclerLinks record from the
80 // doubly-linked list.
81 ////////////////////////////////////////////////////////////////////
82 INLINE void PipelineCyclerLinks::
83 remove_from_list() {
84  nassertv(_prev->_next == this && _next->_prev == this);
85  _prev->_next = _next;
86  _next->_prev = _prev;
87 #ifndef NDEBUG
88  _next = NULL;
89  _prev = NULL;
90 #endif
91 }
92 #endif // THREADED_PIPELINE
93 
94 #ifdef THREADED_PIPELINE
95 ////////////////////////////////////////////////////////////////////
96 // Function: PipelineCyclerLinks::insert_before
97 // Access: Protected
98 // Description: Adds a PipelineCyclerLinks record before the indicated
99 // node in the doubly-linked list.
100 ////////////////////////////////////////////////////////////////////
101 INLINE void PipelineCyclerLinks::
102 insert_before(PipelineCyclerLinks *node) {
103  nassertv(node->_prev->_next == node && node->_next->_prev == node);
104  nassertv(_prev == (PipelineCyclerLinks *)NULL &&
105  _next == (PipelineCyclerLinks *)NULL);
106  _prev = node->_prev;
107  _next = node;
108  _prev->_next = this;
109  node->_prev = this;
110 }
111 #endif // THREADED_PIPELINE
112 
113 #ifdef THREADED_PIPELINE
114 ////////////////////////////////////////////////////////////////////
115 // Function: PipelineCyclerLinks::take_list
116 // Access: Protected
117 // Description: When called on the head of an empty list, takes all
118 // of the leemnts from the indicated list and moves them
119 // to this list.
120 ////////////////////////////////////////////////////////////////////
121 INLINE void PipelineCyclerLinks::
122 take_list(PipelineCyclerLinks &other) {
123  nassertv(_next == this && _prev == this);
124  if (other._next == &other && other._prev == &other) {
125  // The other list is empty; this is a no-op.
126  return;
127  }
128 
129  other._next->_prev = this;
130  other._prev->_next = this;
131  _next = other._next;
132  _prev = other._prev;
133 
134  other._next = &other;
135  other._prev = &other;
136 }
137 #endif // THREADED_PIPELINE