diff --git a/cpp/ycm/ClangCompleter/ClangCompleter.cpp b/cpp/ycm/ClangCompleter/ClangCompleter.cpp index 141af8ac..d03684a7 100644 --- a/cpp/ycm/ClangCompleter/ClangCompleter.cpp +++ b/cpp/ycm/ClangCompleter/ClangCompleter.cpp @@ -23,7 +23,6 @@ #include "standard.h" #include "CandidateRepository.h" #include "CompletionData.h" -#include "ConcurrentLatestValue.h" #include "Utils.h" #include "ClangUtils.h" diff --git a/cpp/ycm/ClangCompleter/ClangCompleter.h b/cpp/ycm/ClangCompleter/ClangCompleter.h index 46281a4c..b69910be 100644 --- a/cpp/ycm/ClangCompleter/ClangCompleter.h +++ b/cpp/ycm/ClangCompleter/ClangCompleter.h @@ -18,8 +18,6 @@ #ifndef CLANGCOMPLETE_H_WLKDU0ZV #define CLANGCOMPLETE_H_WLKDU0ZV -#include "ConcurrentLatestValue.h" -#include "ConcurrentStack.h" #include "Future.h" #include "UnsavedFile.h" #include "Diagnostic.h" diff --git a/cpp/ycm/ClangCompleter/CompilationDatabase.cpp b/cpp/ycm/ClangCompleter/CompilationDatabase.cpp index 35444878..7a3b5f43 100644 --- a/cpp/ycm/ClangCompleter/CompilationDatabase.cpp +++ b/cpp/ycm/ClangCompleter/CompilationDatabase.cpp @@ -20,18 +20,14 @@ #include "standard.h" #include -#include #include #include +#include -using boost::bind; -using boost::make_shared; -using boost::packaged_task; +using boost::lock_guard; using boost::remove_pointer; using boost::shared_ptr; -using boost::thread; -using boost::unique_future; -using boost::function; +using boost::mutex; namespace YouCompleteMe { @@ -39,22 +35,9 @@ typedef shared_ptr < remove_pointer< CXCompileCommands >::type > CompileCommandsWrap; -void QueryThreadMain( CompilationDatabase::InfoTaskStack &info_task_stack ) { - while ( true ) { - try { - ( *info_task_stack.Pop() )(); - } catch ( boost::thread_interrupted & ) { - return; - } - } - -} - - CompilationDatabase::CompilationDatabase( const std::string &path_to_directory ) - : threading_enabled_( false ), - is_loaded_( false ) { + : is_loaded_( false ) { CXCompilationDatabase_Error status; compilation_database_ = clang_CompilationDatabase_fromDirectory( path_to_directory.c_str(), @@ -68,14 +51,6 @@ CompilationDatabase::~CompilationDatabase() { } -// We need this mostly so that we can not use it in tests. Apparently the -// GoogleTest framework goes apeshit on us if we enable threads by default. -void CompilationDatabase::EnableThreading() { - threading_enabled_ = true; - InitThreads(); -} - - bool CompilationDatabase::DatabaseSuccessfullyLoaded() { return is_loaded_; } @@ -88,7 +63,7 @@ CompilationInfoForFile CompilationDatabase::GetCompilationInfoForFile( if ( !is_loaded_ ) return info; - // TODO: mutex protect calls to getCompileCommands and getDirectory + lock_guard< mutex > lock( compilation_database_mutex_ ); CompileCommandsWrap commands( clang_CompilationDatabase_getCompileCommands( @@ -120,34 +95,5 @@ CompilationInfoForFile CompilationDatabase::GetCompilationInfoForFile( return info; } - -Future< AsyncCompilationInfoForFile > -CompilationDatabase::GetCompilationInfoForFileAsync( - const std::string &path_to_file ) { - // TODO: throw exception when threading is not enabled and this is called - if ( !threading_enabled_ ) - return Future< AsyncCompilationInfoForFile >(); - - function< CompilationInfoForFile() > functor = - boost::bind( &CompilationDatabase::GetCompilationInfoForFile, - boost::ref( *this ), - path_to_file ); - - InfoTask task = - make_shared< packaged_task< AsyncCompilationInfoForFile > >( - bind( ReturnValueAsShared< CompilationInfoForFile >, - functor ) ); - - unique_future< AsyncCompilationInfoForFile > future = task->get_future(); - info_task_stack_.Push( task ); - return Future< AsyncCompilationInfoForFile >( boost::move( future ) ); -} - - -void CompilationDatabase::InitThreads() { - info_thread_ = boost::thread( QueryThreadMain, - boost::ref( info_task_stack_ ) ); -} - } // namespace YouCompleteMe diff --git a/cpp/ycm/ClangCompleter/CompilationDatabase.h b/cpp/ycm/ClangCompleter/CompilationDatabase.h index 1205f9ce..e39bb6cd 100644 --- a/cpp/ycm/ClangCompleter/CompilationDatabase.h +++ b/cpp/ycm/ClangCompleter/CompilationDatabase.h @@ -25,8 +25,10 @@ #include #include #include +#include #include + namespace YouCompleteMe { struct CompilationInfoForFile { @@ -34,8 +36,6 @@ struct CompilationInfoForFile { std::string compiler_working_dir_; }; -typedef boost::shared_ptr< CompilationInfoForFile > -AsyncCompilationInfoForFile; class CompilationDatabase : boost::noncopyable { public: @@ -44,28 +44,14 @@ public: bool DatabaseSuccessfullyLoaded(); - void EnableThreading(); - CompilationInfoForFile GetCompilationInfoForFile( const std::string &path_to_file ); - Future< AsyncCompilationInfoForFile > GetCompilationInfoForFileAsync( - const std::string &path_to_file ); - - typedef boost::shared_ptr < - boost::packaged_task< AsyncCompilationInfoForFile > > InfoTask; - - typedef ConcurrentStack< InfoTask > InfoTaskStack; - private: - void InitThreads(); - bool threading_enabled_; bool is_loaded_; CXCompilationDatabase compilation_database_; - - boost::thread info_thread_; - InfoTaskStack info_task_stack_; + boost::mutex compilation_database_mutex_; }; } // namespace YouCompleteMe diff --git a/cpp/ycm/ClangCompleter/TranslationUnit.h b/cpp/ycm/ClangCompleter/TranslationUnit.h index 53baf989..3fe08671 100644 --- a/cpp/ycm/ClangCompleter/TranslationUnit.h +++ b/cpp/ycm/ClangCompleter/TranslationUnit.h @@ -18,7 +18,6 @@ #ifndef TRANSLATIONUNIT_H_XQ7I6SVA #define TRANSLATIONUNIT_H_XQ7I6SVA -#include "ConcurrentLatestValue.h" #include "Future.h" #include "UnsavedFile.h" #include "Diagnostic.h" diff --git a/cpp/ycm/ycm_core.cpp b/cpp/ycm/ycm_core.cpp index 5bb2214f..80626d63 100644 --- a/cpp/ycm/ycm_core.cpp +++ b/cpp/ycm/ycm_core.cpp @@ -17,7 +17,6 @@ #include "IdentifierCompleter.h" #include "PythonSupport.h" -#include "Future.h" #ifdef USE_CLANG_COMPLETER # include "ClangCompleter.h" @@ -77,14 +76,6 @@ BOOST_PYTHON_MODULE(ycm_core) #ifdef USE_CLANG_COMPLETER def( "ClangVersion", ClangVersion ); - // TODO: We may not need this at all anymore. Look into it. - class_< Future< AsyncCompilationInfoForFile > >( - "FutureCompilationInfoForFile" ) - .def( "ResultsReady", - &Future< AsyncCompilationInfoForFile >::ResultsReady ) - .def( "GetResults", - &Future< AsyncCompilationInfoForFile >::GetResults ); - // CAREFUL HERE! For filename and contents we are referring directly to // Python-allocated and -managed memory since we are accepting pointers to // data members of python objects. We need to ensure that those objects @@ -145,13 +136,10 @@ BOOST_PYTHON_MODULE(ycm_core) class_< CompilationDatabase, boost::noncopyable >( "CompilationDatabase", init< std::string >() ) - .def( "EnableThreading", &CompilationDatabase::EnableThreading ) .def( "DatabaseSuccessfullyLoaded", &CompilationDatabase::DatabaseSuccessfullyLoaded ) .def( "GetCompilationInfoForFile", - &CompilationDatabase::GetCompilationInfoForFile ) - .def( "GetCompilationInfoForFileAsync", - &CompilationDatabase::GetCompilationInfoForFileAsync ); + &CompilationDatabase::GetCompilationInfoForFile ); class_< CompilationInfoForFile, boost::shared_ptr< CompilationInfoForFile > >(