Refactored the task building code for simplicity

This commit is contained in:
Strahinja Val Markovic 2012-07-16 20:23:17 -07:00
parent c9e1706fa1
commit bcb65ec43f
2 changed files with 28 additions and 18 deletions

View File

@ -227,36 +227,45 @@ Future< AsyncResults > ClangCompleter::CandidatesForQueryAndLocationInFileAsync(
boost::lock_guard< boost::mutex > lock( clang_data_ready_mutex_ ); boost::lock_guard< boost::mutex > lock( clang_data_ready_mutex_ );
clang_data_ready_ = false; clang_data_ready_ = false;
} }
// Needed to "reset" the sorting threads to the start of their loop. This
// way any threads blocking on a read in sorting_task_.Get() are reset to
// wait on the clang_data_ready_condition_variable_.
sorting_threads_.interrupt_all(); sorting_threads_.interrupt_all();
} }
// the sorting task needs to be set before the clang task (if any) just in // the sorting task needs to be set before the clang task (if any) just in
// case the clang task finishes (and therefore notifies a sorting thread to // case the clang task finishes (and therefore notifies a sorting thread to
// consume a sorting task) before the sorting task is set // consume a sorting task) before the sorting task is set
FunctionReturnsStringVector sort_candidates_for_query_functor =
bind( &ClangCompleter::SortCandidatesForQuery,
boost::ref( *this ),
query,
boost::cref( latest_clang_results_ ) );
shared_ptr< packaged_task< AsyncResults > > task = shared_ptr< packaged_task< AsyncResults > > task =
make_shared< packaged_task< AsyncResults > >( make_shared< packaged_task< AsyncResults > >(
bind( ReturnValueAsShared< std::vector< std::string > >, bind( ReturnValueAsShared< std::vector< std::string > >,
static_cast< FunctionReturnsStringVector >( sort_candidates_for_query_functor ) );
bind( &ClangCompleter::SortCandidatesForQuery,
boost::ref( *this ),
query,
boost::cref( latest_clang_results_ ) ) ) ) );
unique_future< AsyncResults > future = task->get_future(); unique_future< AsyncResults > future = task->get_future();
sorting_task_.Set( task ); sorting_task_.Set( task );
if ( query.empty() ) if ( query.empty() )
{ {
FunctionReturnsStringVector candidates_for_location_in_file_functor =
bind( &ClangCompleter::CandidatesForLocationInFile,
boost::ref( *this ),
filename,
line,
column,
unsaved_files );
shared_ptr< packaged_task< AsyncResults > > task = shared_ptr< packaged_task< AsyncResults > > task =
make_shared< packaged_task< AsyncResults > >( make_shared< packaged_task< AsyncResults > >(
bind( ReturnValueAsShared< std::vector< std::string > >, bind( ReturnValueAsShared< std::vector< std::string > >,
static_cast< FunctionReturnsStringVector >( sort_candidates_for_query_functor ) );
bind( &ClangCompleter::CandidatesForLocationInFile,
boost::ref( *this ),
filename,
line,
column,
unsaved_files ) ) ) );
clang_task_.Set( task ); clang_task_.Set( task );
} }

View File

@ -143,16 +143,17 @@ Future< AsyncResults > IdentifierCompleter::CandidatesForQueryAndTypeAsync(
if ( !threading_enabled_ ) if ( !threading_enabled_ )
return Future< AsyncResults >(); return Future< AsyncResults >();
FunctionReturnsStringVector functor =
bind( &IdentifierCompleter::CandidatesForQueryAndType,
boost::cref( *this ),
query,
filetype );
// Try not to look at this too hard, it may burn your eyes. // Try not to look at this too hard, it may burn your eyes.
// TODO: refactor this so it's more readable
shared_ptr< packaged_task< AsyncResults > > task = shared_ptr< packaged_task< AsyncResults > > task =
make_shared< packaged_task< AsyncResults > >( make_shared< packaged_task< AsyncResults > >(
bind( ReturnValueAsShared< std::vector< std::string > >, bind( ReturnValueAsShared< std::vector< std::string > >,
static_cast< FunctionReturnsStringVector >( functor ) );
bind( &IdentifierCompleter::CandidatesForQueryAndType,
boost::cref( *this ),
query,
filetype ) ) ) );
unique_future< AsyncResults > future = task->get_future(); unique_future< AsyncResults > future = task->get_future();