Permalink
Browse files

fix ringbuffer size decrease

  • Loading branch information...
1 parent 74baf86 commit 3dfb45ff64efdc6739d393e4c6b20fc6178130fa @mind04 mind04 committed with mind04 Aug 26, 2013
Showing with 17 additions and 15 deletions.
  1. +17 −15 pdns/statbag.cc
View
@@ -189,26 +189,28 @@ void StatRing::resize(unsigned int newsize)
return;
Lock l(d_lock);
- if(newsize>d_size) {
- d_size=newsize;
- d_items.resize(d_size);
- return;
- }
-
// this is the hard part, shrink
- int startpos=d_pos-newsize;
- int rpos;
- vector<string>newring;
- for(unsigned int i=startpos;i<d_pos;++i) {
- rpos= i;
+ if(newsize<d_size) {
+ unsigned int startpos=0;
+ if (d_pos>newsize)
+ startpos=d_pos-newsize;
+
+ vector<string>newring;
+ for(unsigned int i=startpos;i<d_pos;++i) {
+ newring.push_back(d_items[i%d_size]);
+ }
- newring.push_back(d_items[rpos%d_size]);
+ d_items=newring;
+ d_size=newring.size();
+ d_pos=min(d_pos,newsize);
}
- d_items=newring;
- d_size=newsize;
- d_pos=d_size-1;
+ if(newsize>d_size) {
+ d_size=newsize;
+ d_items.resize(d_size);
+ }
}
+
StatRing::~StatRing()
{
// do not clean up d_lock, it is shared

0 comments on commit 3dfb45f

Please sign in to comment.