rippled
BasicApp.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/main/BasicApp.h>
21 #include <ripple/beast/core/CurrentThreadName.h>
22 
24 {
26  threads_.reserve(numberOfThreads);
27 
28  while (numberOfThreads--)
29  {
30  threads_.emplace_back([this, numberOfThreads]() {
32  "io svc #" + std::to_string(numberOfThreads));
33  this->io_service_.run();
34  });
35  }
36 }
37 
39 {
40  work_.reset();
41 
42  for (auto& t : threads_)
43  t.join();
44 }
BasicApp::work_
std::optional< boost::asio::io_service::work > work_
Definition: BasicApp.h:32
BasicApp::BasicApp
BasicApp(std::size_t numberOfThreads)
Definition: BasicApp.cpp:23
BasicApp::~BasicApp
~BasicApp()
Definition: BasicApp.cpp:38
std::vector::reserve
T reserve(T... args)
BasicApp::threads_
std::vector< std::thread > threads_
Definition: BasicApp.h:33
std::optional::emplace
T emplace(T... args)
std::optional::reset
T reset(T... args)
BasicApp::io_service_
boost::asio::io_service io_service_
Definition: BasicApp.h:34
std::to_string
T to_string(T... args)
beast::setCurrentThreadName
void setCurrentThreadName(std::string_view name)
Changes the name of the caller thread.
Definition: CurrentThreadName.cpp:119
std::vector::emplace_back
T emplace_back(T... args)
std::size_t