2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-12 12:02:54 +00:00

optimize queues : from Nat Goodspeed

This commit is contained in:
Oliver Kowalke
2014-11-22 11:23:18 +01:00
parent ea709758cb
commit ba3c0bb806
2 changed files with 11 additions and 21 deletions

View File

@@ -93,7 +93,7 @@ private:
state_t state_;
std::size_t count_;
typename node_type::ptr head_;
typename node_type::ptr tail_;
typename node_type::ptr * tail_;
mutable mutex mtx_;
condition not_empty_cond_;
condition not_full_cond_;
@@ -171,13 +171,8 @@ private:
void push_tail_( typename node_type::ptr new_node)
{
if ( is_empty_() )
head_ = tail_ = new_node;
else
{
tail_->next = new_node;
tail_ = new_node;
}
*tail_ = new_node;
tail_ = &new_node->next;
++count_;
}
@@ -210,7 +205,7 @@ private:
{
typename node_type::ptr old_head = head_;
head_ = old_head->next;
if ( 0 == head_) tail_ = 0;
if ( 0 == head_) tail_ = &head_;
old_head->next = 0;
return old_head;
}
@@ -222,7 +217,7 @@ public:
state_( OPEN),
count_( 0),
head_(),
tail_( head_),
tail_( &head_),
mtx_(),
not_empty_cond_(),
not_full_cond_(),
@@ -240,7 +235,7 @@ public:
state_( OPEN),
count_( 0),
head_(),
tail_( head_),
tail_( &head_),
mtx_(),
not_empty_cond_(),
not_full_cond_(),

View File

@@ -90,7 +90,7 @@ private:
state state_;
typename node_type::ptr head_;
typename node_type::ptr tail_;
typename node_type::ptr * tail_;
mutable mutex mtx_;
condition not_empty_cond_;
@@ -132,13 +132,8 @@ private:
void push_tail_( typename node_type::ptr new_node)
{
if ( is_empty_() )
head_ = tail_ = new_node;
else
{
tail_->next = new_node;
tail_ = new_node;
}
*tail_ = new_node;
tail_ = &new_node->next;
}
value_type value_pop_()
@@ -161,7 +156,7 @@ private:
{
typename node_type::ptr old_head = head_;
head_ = old_head->next;
if ( 0 == head_) tail_ = 0;
if ( 0 == head_) tail_ = &head_;
old_head->next = 0;
return old_head;
}
@@ -170,7 +165,7 @@ public:
unbounded_queue() :
state_( OPEN),
head_(),
tail_( head_),
tail_( &head_),
mtx_(),
not_empty_cond_()
{}