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:
parent
6c53bad58f
commit
46360219f8
@ -23,7 +23,6 @@
|
||||
#include "standard.h"
|
||||
#include "CandidateRepository.h"
|
||||
#include "CompletionData.h"
|
||||
#include "ConcurrentLatestValue.h"
|
||||
#include "Utils.h"
|
||||
#include "ClangUtils.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"
|
||||
|
@ -20,18 +20,14 @@
|
||||
#include "standard.h"
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/type_traits/remove_pointer.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
||||
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
|
||||
|
||||
|
@ -25,8 +25,10 @@
|
||||
#include <string>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <clang-c/CXCompilationDatabase.h>
|
||||
|
||||
|
||||
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
|
||||
|
@ -18,7 +18,6 @@
|
||||
#ifndef TRANSLATIONUNIT_H_XQ7I6SVA
|
||||
#define TRANSLATIONUNIT_H_XQ7I6SVA
|
||||
|
||||
#include "ConcurrentLatestValue.h"
|
||||
#include "Future.h"
|
||||
#include "UnsavedFile.h"
|
||||
#include "Diagnostic.h"
|
||||
|
@ -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 > >(
|
||||
|
Loading…
Reference in New Issue
Block a user