Fix SYNC_QUEUE build issue on Boost < 1.56

Prior to Boost 1.56, boost::optional had no move constructor, preventing
use of std::unique_ptr inside it
This commit is contained in:
Chris Pavlina 2017-03-24 10:09:08 -04:00
parent 849b3c2a4b
commit 68853c988e
3 changed files with 25 additions and 20 deletions

View File

@ -235,12 +235,10 @@ public:
std::unique_ptr<IO_ERROR> PopError()
{
auto item = m_errors.pop();
std::unique_ptr<IO_ERROR> error;
if( item )
return std::move( *item );
else
return std::unique_ptr<IO_ERROR>();
m_errors.pop( error );
return error;
}
/**

View File

@ -20,7 +20,6 @@
#ifndef SYNC_QUEUE_H
#define SYNC_QUEUE_H
#include <boost/optional.hpp>
#include <mutex>
#include <queue>
@ -59,22 +58,24 @@ public:
}
/**
* Pop a value off the queue if there is one, returning it. If the queue is empty,
* return boost::none instead.
* Pop a value off the queue into the provided variable. If the queue is empty, the
* variable is not touched.
*
* @return true iff a value was popped.
*/
boost::optional<T> pop()
bool pop( T& aReceiver )
{
GUARD guard( m_mutex );
if( m_queue.empty() )
{
return boost::none;
return false;
}
else
{
T val = std::move( m_queue.front() );
aReceiver = std::move( m_queue.front() );
m_queue.pop();
return std::move( val );
return true;
}
}

View File

@ -98,11 +98,13 @@ bool FOOTPRINT_LIST_IMPL::CatchErrors( std::function<void()> aFunc )
void FOOTPRINT_LIST_IMPL::loader_job()
{
while( auto const nickname = m_queue_in.pop() )
wxString nickname;
while( m_queue_in.pop( nickname ) )
{
CatchErrors( [this, &nickname]() {
m_lib_table->PrefetchLib( *nickname );
m_queue_out.push( *nickname );
m_lib_table->PrefetchLib( nickname );
m_queue_out.push( nickname );
} );
m_count_finished.fetch_add( 1 );
@ -183,14 +185,16 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers()
for( size_t i = 0; i < std::thread::hardware_concurrency() + 1; ++i )
{
threads.push_back( std::thread( [this, &queue_parsed]() {
while( auto nickname = this->m_queue_out.pop() )
wxString nickname;
while( this->m_queue_out.pop( nickname ) )
{
CatchErrors( [this, &queue_parsed, &nickname]() {
wxArrayString fpnames = this->m_lib_table->FootprintEnumerate( *nickname );
wxArrayString fpnames = this->m_lib_table->FootprintEnumerate( nickname );
for( auto const& fpname : fpnames )
{
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, *nickname, fpname );
FOOTPRINT_INFO* fpinfo = new FOOTPRINT_INFO_IMPL( this, nickname, fpname );
queue_parsed.move_push( std::unique_ptr<FOOTPRINT_INFO>( fpinfo ) );
}
} );
@ -201,8 +205,10 @@ bool FOOTPRINT_LIST_IMPL::JoinWorkers()
for( auto& thr : threads )
thr.join();
while( auto fpi = queue_parsed.pop() )
m_list.push_back( std::move( *fpi ) );
std::unique_ptr<FOOTPRINT_INFO> fpi;
while( queue_parsed.pop( fpi ) )
m_list.push_back( std::move( fpi ) );
std::sort( m_list.begin(), m_list.end(),
[]( std::unique_ptr<FOOTPRINT_INFO> const& lhs,