fix some bugs in SharedBufferStack::resize

added buffers should now be labeled properly.

Change-Id: I28aa753fbe89ab89134e7753575319478934c7fa
This commit is contained in:
Mathias Agopian 2010-05-17 17:27:26 -07:00
parent 2ac44f9a8c
commit d6297f7d09
2 changed files with 9 additions and 6 deletions

View File

@ -295,7 +295,8 @@ private:
friend class BufferList; friend class BufferList;
uint32_t mask, curr; uint32_t mask, curr;
const_iterator(uint32_t mask) : const_iterator(uint32_t mask) :
mask(mask), curr(31 - __builtin_clz(mask)) { } mask(mask), curr(__builtin_clz(mask)) {
}
public: public:
inline bool operator == (const const_iterator& rhs) const { inline bool operator == (const const_iterator& rhs) const {
return mask == rhs.mask; return mask == rhs.mask;
@ -304,9 +305,9 @@ private:
return mask != rhs.mask; return mask != rhs.mask;
} }
inline int operator *() const { return curr; } inline int operator *() const { return curr; }
inline const const_iterator& operator ++(int) { inline const const_iterator& operator ++() {
mask &= ~curr; mask &= ~(1<<(31-curr));
curr = 31 - __builtin_clz(mask); curr = __builtin_clz(mask);
return *this; return *this;
} }
}; };

View File

@ -560,6 +560,7 @@ status_t SharedBufferServer::resize(int newNumBuffers)
int base = numBuffers; int base = numBuffers;
int32_t avail = stack.available; int32_t avail = stack.available;
int tail = head - avail + 1; int tail = head - avail + 1;
if (tail >= 0) { if (tail >= 0) {
int8_t* const index = const_cast<int8_t*>(stack.index); int8_t* const index = const_cast<int8_t*>(stack.index);
const int nb = numBuffers - head; const int nb = numBuffers - head;
@ -573,8 +574,9 @@ status_t SharedBufferServer::resize(int newNumBuffers)
// fill the new free space with unused buffers // fill the new free space with unused buffers
BufferList::const_iterator curr(mBufferList.free_begin()); BufferList::const_iterator curr(mBufferList.free_begin());
for (int i=0 ; i<extra ; i++) { for (int i=0 ; i<extra ; i++) {
stack.index[base+i] = *curr++; stack.index[base+i] = *curr;
mBufferList.add(stack.index[base+i]); mBufferList.add(*curr);
++curr;
} }
mNumBuffers = newNumBuffers; mNumBuffers = newNumBuffers;