Wrapping boost threads in scoped_ptr

Boost.Thread deprecated the copy ctor for threads; this is a better approach.
This commit is contained in:
Strahinja Val Markovic 2013-02-16 11:15:07 -08:00
parent 9dfa2f4e11
commit 30d5a3b8a5
4 changed files with 13 additions and 11 deletions

View File

@ -101,8 +101,8 @@ ClangCompleter::~ClangCompleter() {
sorting_threads_.interrupt_all();
sorting_threads_.join_all();
clang_thread_.interrupt();
clang_thread_.join();
clang_thread_->interrupt();
clang_thread_->join();
}
@ -449,8 +449,8 @@ void ClangCompleter::InitThreads() {
boost::ref( *this ) ) );
}
clang_thread_ = thread( &ClangCompleter::ClangThreadMain,
boost::ref( *this ) );
clang_thread_.reset( new thread( &ClangCompleter::ClangThreadMain,
boost::ref( *this ) ) );
}

View File

@ -25,6 +25,7 @@
#include "ClangResultsCache.h"
#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread/future.hpp>
#include <boost/unordered_map.hpp>
@ -174,7 +175,7 @@ private:
// access it. Only one thread at a time is allowed to access any single
// translation unit. Currently we only use one thread to access clang and that
// is the thread represented by clang_thread_.
boost::thread clang_thread_;
boost::scoped_ptr< boost::thread > clang_thread_;
boost::thread_group sorting_threads_;

View File

@ -103,8 +103,8 @@ IdentifierCompleter::~IdentifierCompleter() {
query_threads_.interrupt_all();
query_threads_.join_all();
buffer_identifiers_thread_.interrupt();
buffer_identifiers_thread_.join();
buffer_identifiers_thread_->interrupt();
buffer_identifiers_thread_->join();
}
@ -283,9 +283,9 @@ void IdentifierCompleter::InitThreads() {
boost::ref( latest_query_task_ ) ) );
}
buffer_identifiers_thread_ = boost::thread(
BufferIdentifiersThreadMain,
boost::ref( buffer_identifiers_task_stack_ ) );
buffer_identifiers_thread_.reset(
new boost::thread( BufferIdentifiersThreadMain,
boost::ref( buffer_identifiers_task_stack_ ) ) );
}

View File

@ -25,6 +25,7 @@
#include <boost/utility.hpp>
#include <boost/unordered_map.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <vector>
#include <string>
@ -125,7 +126,7 @@ private:
boost::thread_group query_threads_;
boost::thread buffer_identifiers_thread_;
boost::scoped_ptr< boost::thread > buffer_identifiers_thread_;
mutable LatestQueryTask latest_query_task_;