Skip to content

Commit

Permalink
反向复用stack,尽量减少cache miss
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed May 15, 2017
1 parent 5b659f9 commit 9462677
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/libcopp/stack/stack_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ namespace copp {
return;
}

// get from pool
// get from pool, in order to max reuse cache, we use FILO to allocate stack
if (!free_list_.empty()) {
typename std::list<stack_context>::iterator iter = free_list_.begin();
assert(iter != free_list_.end());
typename std::list<stack_context>::reverse_iterator iter = free_list_.rbegin();
assert(iter != free_list_.rend());

// free limit
if (likely(limits_.free_stack_number > 0)) {
Expand All @@ -139,7 +139,7 @@ namespace copp {
}

ctx = *iter;
free_list_.pop_front();
free_list_.pop_back();

// used limit
++limits_.used_stack_number;
Expand Down

0 comments on commit 9462677

Please sign in to comment.