diff --git a/cpp/ycm/Completer.cpp b/cpp/ycm/Completer.cpp index f2a0a813..d0a22e9d 100644 --- a/cpp/ycm/Completer.cpp +++ b/cpp/ycm/Completer.cpp @@ -39,14 +39,14 @@ namespace YouCompleteMe namespace { -const unsigned int MAX_ASYNC_THREADS = 4; -const unsigned int MIN_ASYNC_THREADS = 2; +const unsigned int MAX_ASYNC_THREADS = 1; +const unsigned int MIN_ASYNC_THREADS = 1; void ThreadMain( TaskStack &task_stack ) { while ( true ) { - ( *task_stack.Pop() )(); + ( *task_stack.Get() )(); } } @@ -167,7 +167,7 @@ Future Completer::CandidatesForQueryAndTypeAsync( unique_future< AsyncResults > future = task->get_future(); - task_stack_.Push( task ); + task_stack_.Set( task ); return Future( move( future ) ); } diff --git a/cpp/ycm/ConcurrentStack.h b/cpp/ycm/ConcurrentStack.h index 6198f1d8..a4f133d7 100644 --- a/cpp/ycm/ConcurrentStack.h +++ b/cpp/ycm/ConcurrentStack.h @@ -30,32 +30,38 @@ class ConcurrentStack : boost::noncopyable { public: - void Push( const T& data ) + // TODO: rename this class, it's not a stack anymore + ConcurrentStack() : empty_( true ) {} + + void Set( const T& data ) { { boost::unique_lock< boost::mutex > lock( mutex_ ); - stack_.push( data ); + latest_ = data; + empty_ = false; } condition_variable_.notify_one(); } - T Pop() + T Get() { boost::unique_lock< boost::mutex > lock( mutex_ ); - while ( stack_.empty() ) + while ( empty_ ) { condition_variable_.wait( lock ); } - T result = stack_.top(); - stack_.pop(); - return result; + empty_ = true; + return latest_; } + private: - std::stack stack_; + // std::stack< T > stack_; + T latest_; + bool empty_; boost::mutex mutex_; boost::condition_variable condition_variable_;