Mercurial > hg > svcore
comparison base/Scavenger.h @ 14:b101cc2ae1ab
* Introduce potentially-separate read and write ring buffers, so we can swap
in a new set when something changes -- thus allowing us to respond quickly
when something changes during playback, without losing the long buffers
* Some fixes for display & editing
author | Chris Cannam |
---|---|
date | Fri, 27 Jan 2006 18:04:07 +0000 |
parents | d86891498eef |
children | 2fb933f88604 |
comparison
equal
deleted
inserted
replaced
13:1fa7cc0d008b | 14:b101cc2ae1ab |
---|---|
46 | 46 |
47 /** | 47 /** |
48 * Call from a non-RT thread. | 48 * Call from a non-RT thread. |
49 * Only one thread should be calling this on any given scavenger. | 49 * Only one thread should be calling this on any given scavenger. |
50 */ | 50 */ |
51 void scavenge(); | 51 void scavenge(bool clearNow = false); |
52 | 52 |
53 protected: | 53 protected: |
54 typedef std::pair<T *, int> ObjectTimePair; | 54 typedef std::pair<T *, int> ObjectTimePair; |
55 typedef std::vector<ObjectTimePair> ObjectTimeList; | 55 typedef std::vector<ObjectTimePair> ObjectTimeList; |
56 ObjectTimeList m_objects; | 56 ObjectTimeList m_objects; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 template <typename T> | 122 template <typename T> |
123 void | 123 void |
124 Scavenger<T>::scavenge() | 124 Scavenger<T>::scavenge(bool clearNow) |
125 { | 125 { |
126 // std::cerr << "Scavenger::scavenge: scavenged " << m_scavenged << ", claimed " << m_claimed << std::endl; | 126 // std::cerr << "Scavenger::scavenge: scavenged " << m_scavenged << ", claimed " << m_claimed << std::endl; |
127 | 127 |
128 if (m_scavenged >= m_claimed) return; | 128 if (m_scavenged >= m_claimed) return; |
129 | 129 |
131 (void)gettimeofday(&tv, 0); | 131 (void)gettimeofday(&tv, 0); |
132 int sec = tv.tv_sec; | 132 int sec = tv.tv_sec; |
133 | 133 |
134 for (size_t i = 0; i < m_objects.size(); ++i) { | 134 for (size_t i = 0; i < m_objects.size(); ++i) { |
135 ObjectTimePair &pair = m_objects[i]; | 135 ObjectTimePair &pair = m_objects[i]; |
136 if (pair.first != 0 && pair.second + m_sec < sec) { | 136 if (clearNow || |
137 (pair.first != 0 && pair.second + m_sec < sec)) { | |
137 T *ot = pair.first; | 138 T *ot = pair.first; |
138 pair.first = 0; | 139 pair.first = 0; |
139 delete ot; | 140 delete ot; |
140 ++m_scavenged; | 141 ++m_scavenged; |
141 } | 142 } |