Refactored the task building code for simplicity
This commit is contained in:
parent
c9e1706fa1
commit
bcb65ec43f
@ -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
|
||||||
shared_ptr< packaged_task< AsyncResults > > task =
|
|
||||||
make_shared< packaged_task< AsyncResults > >(
|
FunctionReturnsStringVector sort_candidates_for_query_functor =
|
||||||
bind( ReturnValueAsShared< std::vector< std::string > >,
|
|
||||||
static_cast< FunctionReturnsStringVector >(
|
|
||||||
bind( &ClangCompleter::SortCandidatesForQuery,
|
bind( &ClangCompleter::SortCandidatesForQuery,
|
||||||
boost::ref( *this ),
|
boost::ref( *this ),
|
||||||
query,
|
query,
|
||||||
boost::cref( latest_clang_results_ ) ) ) ) );
|
boost::cref( latest_clang_results_ ) );
|
||||||
|
|
||||||
|
shared_ptr< packaged_task< AsyncResults > > task =
|
||||||
|
make_shared< packaged_task< AsyncResults > >(
|
||||||
|
bind( ReturnValueAsShared< std::vector< std::string > >,
|
||||||
|
sort_candidates_for_query_functor ) );
|
||||||
|
|
||||||
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() )
|
||||||
{
|
{
|
||||||
shared_ptr< packaged_task< AsyncResults > > task =
|
FunctionReturnsStringVector candidates_for_location_in_file_functor =
|
||||||
make_shared< packaged_task< AsyncResults > >(
|
|
||||||
bind( ReturnValueAsShared< std::vector< std::string > >,
|
|
||||||
static_cast< FunctionReturnsStringVector >(
|
|
||||||
bind( &ClangCompleter::CandidatesForLocationInFile,
|
bind( &ClangCompleter::CandidatesForLocationInFile,
|
||||||
boost::ref( *this ),
|
boost::ref( *this ),
|
||||||
filename,
|
filename,
|
||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
unsaved_files ) ) ) );
|
unsaved_files );
|
||||||
|
|
||||||
|
shared_ptr< packaged_task< AsyncResults > > task =
|
||||||
|
make_shared< packaged_task< AsyncResults > >(
|
||||||
|
bind( ReturnValueAsShared< std::vector< std::string > >,
|
||||||
|
sort_candidates_for_query_functor ) );
|
||||||
|
|
||||||
clang_task_.Set( task );
|
clang_task_.Set( task );
|
||||||
}
|
}
|
||||||
|
@ -143,16 +143,17 @@ Future< AsyncResults > IdentifierCompleter::CandidatesForQueryAndTypeAsync(
|
|||||||
if ( !threading_enabled_ )
|
if ( !threading_enabled_ )
|
||||||
return Future< AsyncResults >();
|
return Future< AsyncResults >();
|
||||||
|
|
||||||
// Try not to look at this too hard, it may burn your eyes.
|
FunctionReturnsStringVector functor =
|
||||||
// TODO: refactor this so it's more readable
|
|
||||||
shared_ptr< packaged_task< AsyncResults > > task =
|
|
||||||
make_shared< packaged_task< AsyncResults > >(
|
|
||||||
bind( ReturnValueAsShared< std::vector< std::string > >,
|
|
||||||
static_cast< FunctionReturnsStringVector >(
|
|
||||||
bind( &IdentifierCompleter::CandidatesForQueryAndType,
|
bind( &IdentifierCompleter::CandidatesForQueryAndType,
|
||||||
boost::cref( *this ),
|
boost::cref( *this ),
|
||||||
query,
|
query,
|
||||||
filetype ) ) ) );
|
filetype );
|
||||||
|
|
||||||
|
// Try not to look at this too hard, it may burn your eyes.
|
||||||
|
shared_ptr< packaged_task< AsyncResults > > task =
|
||||||
|
make_shared< packaged_task< AsyncResults > >(
|
||||||
|
bind( ReturnValueAsShared< std::vector< std::string > >,
|
||||||
|
functor ) );
|
||||||
|
|
||||||
unique_future< AsyncResults > future = task->get_future();
|
unique_future< AsyncResults > future = task->get_future();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user