Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7017 from EOSIO/std_thread_mongo_plugin
Browse files Browse the repository at this point in the history
[XC 10.2] Remove boost::thread usage from mongo plugin
  • Loading branch information
spoonincode committed Mar 31, 2019
2 parents f6c9d81 + cc0eb5b commit d5b9911
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions plugins/mongo_db_plugin/mongo_db_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
#include <boost/algorithm/string.hpp>
#include <boost/chrono.hpp>
#include <boost/signals2/connection.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>

#include <queue>
#include <thread>
#include <mutex>

#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/document.hpp>
Expand Down Expand Up @@ -164,9 +163,9 @@ class mongo_db_plugin_impl {
std::deque<chain::block_state_ptr> block_state_process_queue;
std::deque<chain::block_state_ptr> irreversible_block_state_queue;
std::deque<chain::block_state_ptr> irreversible_block_state_process_queue;
boost::mutex mtx;
boost::condition_variable condition;
boost::thread consume_thread;
std::mutex mtx;
std::condition_variable condition;
std::thread consume_thread;
std::atomic_bool done{false};
std::atomic_bool startup{true};
fc::optional<chain::chain_id_type> chain_id;
Expand Down Expand Up @@ -292,15 +291,15 @@ bool mongo_db_plugin_impl::filter_include( const transaction& trx ) const

template<typename Queue, typename Entry>
void mongo_db_plugin_impl::queue( Queue& queue, const Entry& e ) {
boost::mutex::scoped_lock lock( mtx );
std::unique_lock<std::mutex> lock( mtx );
auto queue_size = queue.size();
if( queue_size > max_queue_size ) {
lock.unlock();
condition.notify_one();
queue_sleep_time += 10;
if( queue_sleep_time > 1000 )
wlog("queue size: ${q}", ("q", queue_size));
boost::this_thread::sleep_for( boost::chrono::milliseconds( queue_sleep_time ));
std::this_thread::sleep_for( std::chrono::milliseconds( queue_sleep_time ));
lock.lock();
} else {
queue_sleep_time -= 10;
Expand Down Expand Up @@ -408,7 +407,7 @@ void mongo_db_plugin_impl::consume_blocks() {
_account_controls = mongo_conn[db_name][account_controls_col];

while (true) {
boost::mutex::scoped_lock lock(mtx);
std::unique_lock<std::mutex> lock(mtx);
while ( transaction_metadata_queue.empty() &&
transaction_trace_queue.empty() &&
block_state_queue.empty() &&
Expand Down Expand Up @@ -1528,7 +1527,7 @@ void mongo_db_plugin_impl::init() {

ilog("starting db plugin thread");

consume_thread = boost::thread([this] { consume_blocks(); });
consume_thread = std::thread([this] { consume_blocks(); });

startup = false;
}
Expand Down

0 comments on commit d5b9911

Please sign in to comment.