Removed threads & async API in CompilationDatabase

This is not needed anymore; the server request merely blocks when waiting for
flags.
This commit is contained in:
Strahinja Val Markovic 2013-09-30 17:30:46 -07:00
parent 6c53bad58f
commit 46360219f8
6 changed files with 9 additions and 93 deletions

View File

@ -23,7 +23,6 @@
#include "standard.h" #include "standard.h"
#include "CandidateRepository.h" #include "CandidateRepository.h"
#include "CompletionData.h" #include "CompletionData.h"
#include "ConcurrentLatestValue.h"
#include "Utils.h" #include "Utils.h"
#include "ClangUtils.h" #include "ClangUtils.h"

View File

@ -18,8 +18,6 @@
#ifndef CLANGCOMPLETE_H_WLKDU0ZV #ifndef CLANGCOMPLETE_H_WLKDU0ZV
#define CLANGCOMPLETE_H_WLKDU0ZV #define CLANGCOMPLETE_H_WLKDU0ZV
#include "ConcurrentLatestValue.h"
#include "ConcurrentStack.h"
#include "Future.h" #include "Future.h"
#include "UnsavedFile.h" #include "UnsavedFile.h"
#include "Diagnostic.h" #include "Diagnostic.h"

View File

@ -20,18 +20,14 @@
#include "standard.h" #include "standard.h"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/type_traits/remove_pointer.hpp> #include <boost/type_traits/remove_pointer.hpp>
#include <boost/thread/locks.hpp>
using boost::bind; using boost::lock_guard;
using boost::make_shared;
using boost::packaged_task;
using boost::remove_pointer; using boost::remove_pointer;
using boost::shared_ptr; using boost::shared_ptr;
using boost::thread; using boost::mutex;
using boost::unique_future;
using boost::function;
namespace YouCompleteMe { namespace YouCompleteMe {
@ -39,22 +35,9 @@ typedef shared_ptr <
remove_pointer< CXCompileCommands >::type > CompileCommandsWrap; 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( CompilationDatabase::CompilationDatabase(
const std::string &path_to_directory ) const std::string &path_to_directory )
: threading_enabled_( false ), : is_loaded_( false ) {
is_loaded_( false ) {
CXCompilationDatabase_Error status; CXCompilationDatabase_Error status;
compilation_database_ = clang_CompilationDatabase_fromDirectory( compilation_database_ = clang_CompilationDatabase_fromDirectory(
path_to_directory.c_str(), 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() { bool CompilationDatabase::DatabaseSuccessfullyLoaded() {
return is_loaded_; return is_loaded_;
} }
@ -88,7 +63,7 @@ CompilationInfoForFile CompilationDatabase::GetCompilationInfoForFile(
if ( !is_loaded_ ) if ( !is_loaded_ )
return info; return info;
// TODO: mutex protect calls to getCompileCommands and getDirectory lock_guard< mutex > lock( compilation_database_mutex_ );
CompileCommandsWrap commands( CompileCommandsWrap commands(
clang_CompilationDatabase_getCompileCommands( clang_CompilationDatabase_getCompileCommands(
@ -120,34 +95,5 @@ CompilationInfoForFile CompilationDatabase::GetCompilationInfoForFile(
return info; 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 } // namespace YouCompleteMe

View File

@ -25,8 +25,10 @@
#include <string> #include <string>
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <clang-c/CXCompilationDatabase.h> #include <clang-c/CXCompilationDatabase.h>
namespace YouCompleteMe { namespace YouCompleteMe {
struct CompilationInfoForFile { struct CompilationInfoForFile {
@ -34,8 +36,6 @@ struct CompilationInfoForFile {
std::string compiler_working_dir_; std::string compiler_working_dir_;
}; };
typedef boost::shared_ptr< CompilationInfoForFile >
AsyncCompilationInfoForFile;
class CompilationDatabase : boost::noncopyable { class CompilationDatabase : boost::noncopyable {
public: public:
@ -44,28 +44,14 @@ public:
bool DatabaseSuccessfullyLoaded(); bool DatabaseSuccessfullyLoaded();
void EnableThreading();
CompilationInfoForFile GetCompilationInfoForFile( CompilationInfoForFile GetCompilationInfoForFile(
const std::string &path_to_file ); 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: private:
void InitThreads();
bool threading_enabled_;
bool is_loaded_; bool is_loaded_;
CXCompilationDatabase compilation_database_; CXCompilationDatabase compilation_database_;
boost::mutex compilation_database_mutex_;
boost::thread info_thread_;
InfoTaskStack info_task_stack_;
}; };
} // namespace YouCompleteMe } // namespace YouCompleteMe

View File

@ -18,7 +18,6 @@
#ifndef TRANSLATIONUNIT_H_XQ7I6SVA #ifndef TRANSLATIONUNIT_H_XQ7I6SVA
#define TRANSLATIONUNIT_H_XQ7I6SVA #define TRANSLATIONUNIT_H_XQ7I6SVA
#include "ConcurrentLatestValue.h"
#include "Future.h" #include "Future.h"
#include "UnsavedFile.h" #include "UnsavedFile.h"
#include "Diagnostic.h" #include "Diagnostic.h"

View File

@ -17,7 +17,6 @@
#include "IdentifierCompleter.h" #include "IdentifierCompleter.h"
#include "PythonSupport.h" #include "PythonSupport.h"
#include "Future.h"
#ifdef USE_CLANG_COMPLETER #ifdef USE_CLANG_COMPLETER
# include "ClangCompleter.h" # include "ClangCompleter.h"
@ -77,14 +76,6 @@ BOOST_PYTHON_MODULE(ycm_core)
#ifdef USE_CLANG_COMPLETER #ifdef USE_CLANG_COMPLETER
def( "ClangVersion", ClangVersion ); 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 // CAREFUL HERE! For filename and contents we are referring directly to
// Python-allocated and -managed memory since we are accepting pointers to // Python-allocated and -managed memory since we are accepting pointers to
// data members of python objects. We need to ensure that those objects // 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 >( class_< CompilationDatabase, boost::noncopyable >(
"CompilationDatabase", init< std::string >() ) "CompilationDatabase", init< std::string >() )
.def( "EnableThreading", &CompilationDatabase::EnableThreading )
.def( "DatabaseSuccessfullyLoaded", .def( "DatabaseSuccessfullyLoaded",
&CompilationDatabase::DatabaseSuccessfullyLoaded ) &CompilationDatabase::DatabaseSuccessfullyLoaded )
.def( "GetCompilationInfoForFile", .def( "GetCompilationInfoForFile",
&CompilationDatabase::GetCompilationInfoForFile ) &CompilationDatabase::GetCompilationInfoForFile );
.def( "GetCompilationInfoForFileAsync",
&CompilationDatabase::GetCompilationInfoForFileAsync );
class_< CompilationInfoForFile, class_< CompilationInfoForFile,
boost::shared_ptr< CompilationInfoForFile > >( boost::shared_ptr< CompilationInfoForFile > >(