Skip to content

Commit

Permalink
Increased number of messages for BackgroundLogger test, updated concu…
Browse files Browse the repository at this point in the history
…rrent_queue implementation
  • Loading branch information
AndrewD committed Sep 26, 2011
1 parent 204f97b commit df35760
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions concurrent_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ class concurrent_queue
public:
void push(Data const& data)
{
boost::mutex::scoped_lock lock(the_mutex);
boost::lock_guard<boost::mutex> lock(the_mutex);
the_queue.push(data);
lock.unlock();
the_condition_variable.notify_one();
}

bool empty() const
{
boost::mutex::scoped_lock lock(the_mutex);
boost::lock_guard lock(the_mutex);
return the_queue.empty();
}

bool try_pop(Data& popped_value)
{
boost::mutex::scoped_lock lock(the_mutex);
if(the_queue.empty())
boost::unique_lock<boost::mutex> lock(the_mutex);
if( the_queue.empty() )
{
return false;
}

popped_value=the_queue.front();
popped_value = the_queue.front();
the_queue.pop();
return true;
}

void wait_and_pop(Data& popped_value)
{
boost::mutex::scoped_lock lock(the_mutex);
while(the_queue.empty())
boost::unique_lock<boost::mutex> lock(the_mutex);

while( the_queue.empty() )
{
the_condition_variable.wait(lock);
}

popped_value=the_queue.front();
popped_value = the_queue.front();
the_queue.pop();
}

Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int TestBackgroundLoggerConcurrency()
{
int failed = 0;
CountingLogger clog;
const int numMessages = 10000;
const int numMessages = 100000;

cout << "Testing BackgroundLogger for consistency... " << flush;

Expand Down

0 comments on commit df35760

Please sign in to comment.