Permalink
Browse files

Merge remote-tracking branch 'anh/develop' into various_features

  • Loading branch information...
apathyboy committed Mar 5, 2013
2 parents 143d326 + 3cff6eb commit 9711ea050f238213b35a8c3c471a79b7b0a6c499
Showing with 136 additions and 108 deletions.
  1. +4 −0 CMakeLists.txt
  2. +3 −1 src/swganh/app/kernel_interface.h
  3. +51 −23 src/swganh/app/swganh_app.cc
  4. +3 −3 src/swganh/app/swganh_app.h
  5. +12 −5 src/swganh/app/swganh_kernel.cc
  6. +9 −4 src/swganh/app/swganh_kernel.h
  7. +2 −2 src/swganh/network/soe/session.cc
  8. +1 −1 src/swganh/network/soe/session.h
  9. +1 −1 src/swganh/tre/iff/iff.cc
  10. +3 −2 src/swganh/tre/resource_manager.cc
  11. +1 −1 src/swganh/tre/visitors/objects/object_visitor-intl.h
  12. +1 −1 src/swganh_core/combat/buff_manager.cc
  13. +1 −1 src/swganh_core/combat/combat_service.cc
  14. +2 −2 src/swganh_core/command/command_queue.cc
  15. +2 −2 src/swganh_core/connection/connection_client.cc
  16. +1 −1 src/swganh_core/connection/connection_client.h
  17. +2 −2 src/swganh_core/connection/connection_client_interface.h
  18. +3 −3 src/swganh_core/connection/connection_service.cc
  19. +1 −1 src/swganh_core/connection/connection_service_interface.h
  20. +1 −1 src/swganh_core/galaxy/galaxy_service.cc
  21. +2 −2 src/swganh_core/login/login_client.cc
  22. +1 −1 src/swganh_core/login/login_client.h
  23. +2 −2 src/swganh_core/login/login_client_interface.h
  24. +5 −5 src/swganh_core/login/login_service.cc
  25. +1 −1 src/swganh_core/object/object.h
  26. +1 −1 src/swganh_core/object/object_manager.cc
  27. +1 −1 src/swganh_core/player/player_service.cc
  28. +16 −35 src/swganh_core/simulation/simulation_service_objects.cc
  29. +1 −1 src/swganh_core/spawn/spawn_service.cc
  30. +1 −1 src/swganh_core/static/static_service.cc
  31. +1 −1 src/swganh_core/weather/weather_service.cc
View
@@ -88,6 +88,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
set(AdditionalBoostLibs chrono regex)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-virtual-dtor")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-parentheses")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-return-type")
+
find_library(PTHREAD_LIBRARY NAMES pthread)
endif()
@@ -62,7 +62,9 @@ class KernelInterface {
virtual swganh::database::DatabaseManager* GetDatabaseManager() = 0;
- virtual boost::asio::io_service& GetIoService() = 0;
+ virtual boost::asio::io_service& GetIoThreadPool() = 0;
+
+ virtual boost::asio::io_service& GetCpuThreadPool() = 0;
// also add entity manager, blah blah.
};
@@ -58,8 +58,8 @@ options_description AppConfig::BuildConfigDescription() {
desc.add_options()
("help,h", "Display help message and config options")
- ("server_mode", boost::program_options::value<std::string>(&server_mode)->default_value("all"),
- "Specifies the service configuration mode to run the server in.")
+ ("server_mode", boost::program_options::value<std::string>(&server_mode)->default_value("all"),
+ "Specifies the service configuration mode to run the server in.")
("plugin,p", boost::program_options::value<std::vector<std::string>>(&plugins),
"Only used when single_server_mode is disabled, loads a module of the specified name")
@@ -81,6 +81,12 @@ options_description AppConfig::BuildConfigDescription() {
("db_threads", value<uint32_t>(&db_threads)->default_value(2),
"Total number of threads to allocate for database management")
+ ("io_threads", value<uint32_t>(&io_threads)->default_value(2),
+ "Total number of threads to allocate for pulling threads off the wire")
+
+ ("cpu_threads", value<uint32_t>(&cpu_threads)->default_value(boost::thread::hardware_concurrency()),
+ "Total number of threads to allocate for processing.")
+
("db.galaxy_manager.host", boost::program_options::value<std::string>(&galaxy_manager_db.host),
"Host address for the galaxy_manager datastore")
("db.galaxy_manager.schema", boost::program_options::value<std::string>(&galaxy_manager_db.schema),
@@ -140,10 +146,12 @@ options_description AppConfig::BuildConfigDescription() {
}
SwganhApp::SwganhApp(int argc, char* argv[])
- : io_service_()
- , io_work_(new boost::asio::io_service::work(io_service_))
+ : io_pool_()
+ , cpu_pool_()
+ , io_work_(new boost::asio::io_service::work(io_pool_))
+ , cpu_work_(new boost::asio::io_service::work(cpu_pool_))
{
- kernel_ = make_shared<SwganhKernel>(io_service_);
+ kernel_ = make_shared<SwganhKernel>(io_pool_, cpu_pool_);
running_ = false;
initialized_ = false;
@@ -158,9 +166,11 @@ SwganhApp::~SwganhApp()
kernel_->Shutdown();
io_work_.reset();
+ cpu_work_.reset();
// join the threadpool threads until each one has exited.
for_each(io_threads_.begin(), io_threads_.end(), std::mem_fn(&boost::thread::join));
+ for_each(cpu_threads_.begin(), cpu_threads_.end(), std::mem_fn(&boost::thread::join));
kernel_.reset();
}
@@ -244,28 +254,46 @@ void SwganhApp::Start() {
running_ = true;
- // Start up a threadpool for running io_service based tasks/active objects
- // The increment starts at 2 because the main thread of execution already counts
- // as thread in use as does the console thread.
- for (uint32_t i = 1; i < boost::thread::hardware_concurrency(); ++i) {
- boost::thread t([this] () {
- try
- {
- io_service_.run();
- }
- catch(...)
+ //Create a number of threads to pull packets off the wire.
+ for (uint32_t i = 0; i < kernel_->GetAppConfig().io_threads; ++i) {
+ boost::thread t([this] () {
+ //Continue looping despite errors.
+ //If we successfully leave the run method we return.
+ while(true)
{
- LOG(severity_level::error) << "A near fatal exception has occurred.";
+ try
+ {
+ io_pool_.run();
+ return;
+ }
+ catch(...)
+ {
+ LOG(severity_level::error) << "A near fatal exception has occurred.";
+ }
}
-
- });
-
-#ifdef _WIN32
- SetPriorityClass(t.native_handle(), REALTIME_PRIORITY_CLASS);
-#endif
-
+ });
io_threads_.push_back(move(t));
}
+
+ for (uint32_t i = 0; i < kernel_->GetAppConfig().cpu_threads; ++i) {
+ boost::thread t([this] () {
+ //Continue looping despite errors.
+ //If we successfully leave the run method we return.
+ while(true)
+ {
+ try
+ {
+ cpu_pool_.run();
+ return;
+ }
+ catch(...)
+ {
+ LOG(severity_level::error) << "A near fatal exception has occurred.";
+ }
+ }
+ });
+ cpu_threads_.push_back(move(t));
+ }
kernel_->GetServiceManager()->Start();
@@ -78,9 +78,9 @@ class SwganhApp : public swganh::app::AppInterface, private boost::noncopyable {
void SetupLogging_();
- boost::asio::io_service io_service_;
- std::unique_ptr<boost::asio::io_service::work> io_work_;
- std::vector<boost::thread> io_threads_;
+ boost::asio::io_service io_pool_, cpu_pool_;
+ std::unique_ptr<boost::asio::io_service::work> io_work_, cpu_work_;
+ std::vector<boost::thread> io_threads_, cpu_threads_;
std::shared_ptr<SwganhKernel> kernel_;
std::atomic<bool> running_;
bool initialized_;
@@ -29,8 +29,9 @@ using swganh::service::ServiceManager;
using std::make_shared;
using std::shared_ptr;
-SwganhKernel::SwganhKernel(boost::asio::io_service& io_service)
- : io_service_(io_service)
+SwganhKernel::SwganhKernel(boost::asio::io_service& io_pool, boost::asio::io_service& cpu_pool)
+ : io_pool_(io_pool)
+ , cpu_pool_(cpu_pool)
{
version_.major = VERSION_MAJOR;
version_.minor = VERSION_MINOR;
@@ -76,7 +77,7 @@ DatabaseManager* SwganhKernel::GetDatabaseManager() {
swganh::EventDispatcher* SwganhKernel::GetEventDispatcher() {
if (!event_dispatcher_) {
- event_dispatcher_.reset(new swganh::EventDispatcher(GetIoService()));
+ event_dispatcher_.reset(new swganh::EventDispatcher(GetCpuThreadPool()));
}
return event_dispatcher_.get();
@@ -112,8 +113,14 @@ ServiceDirectoryInterface* SwganhKernel::GetServiceDirectory() {
return service_directory_.get();
}
-boost::asio::io_service& SwganhKernel::GetIoService() {
- return io_service_;
+boost::asio::io_service& SwganhKernel::GetIoThreadPool()
+{
+ return io_pool_;
+}
+
+boost::asio::io_service& SwganhKernel::GetCpuThreadPool()
+{
+ return cpu_pool_;
}
swganh::tre::ResourceManager* SwganhKernel::GetResourceManager()
@@ -33,7 +33,10 @@ struct AppConfig {
std::string galaxy_name;
std::string tre_config;
uint32_t resource_cache_size;
- uint32_t db_threads;
+
+ uint32_t io_threads;
+ uint32_t cpu_threads;
+ uint32_t db_threads;
/*!
* @Brief Contains information about the database config"
@@ -69,7 +72,7 @@ struct AppConfig {
class SwganhKernel : public swganh::app::KernelInterface {
public:
- explicit SwganhKernel(boost::asio::io_service& io_service);
+ explicit SwganhKernel(boost::asio::io_service& io_pool, boost::asio::io_service& cpu_pool);
virtual ~SwganhKernel();
void Shutdown();
@@ -88,7 +91,9 @@ class SwganhKernel : public swganh::app::KernelInterface {
swganh::service::ServiceDirectoryInterface* GetServiceDirectory();
- boost::asio::io_service& GetIoService();
+ boost::asio::io_service& GetIoThreadPool();
+
+ boost::asio::io_service& GetCpuThreadPool();
swganh::tre::ResourceManager* GetResourceManager();
@@ -104,7 +109,7 @@ class SwganhKernel : public swganh::app::KernelInterface {
std::unique_ptr<swganh::service::ServiceDirectoryInterface> service_directory_;
std::unique_ptr<swganh::tre::ResourceManager> resource_manager_;
- boost::asio::io_service& io_service_;
+ boost::asio::io_service &io_pool_, &cpu_pool_;
};
}} // namespace swganh::app
@@ -17,11 +17,11 @@ using namespace swganh::network;
using namespace swganh::network::soe;
using namespace std;
-Session::Session(ServerInterface* server, boost::asio::io_service& io_service, boost::asio::ip::udp::endpoint remote_endpoint)
+Session::Session(ServerInterface* server, boost::asio::io_service& cpu_pool, boost::asio::ip::udp::endpoint remote_endpoint)
: std::enable_shared_from_this<Session>()
, remote_endpoint_(remote_endpoint)
, server_(server)
- , strand_(io_service)
+ , strand_(cpu_pool)
, connected_(false)
, crc_seed_(0xDEADBABE)
, last_acknowledged_sequence_(0)
@@ -47,7 +47,7 @@ class Session : public std::enable_shared_from_this<Session> {
/**
* Adds itself to the Session Manager.
*/
- Session(ServerInterface* server, boost::asio::io_service& io_service, boost::asio::ip::udp::endpoint remote_endpoint);
+ Session(ServerInterface* server, boost::asio::io_service& cpu_pool, boost::asio::ip::udp::endpoint remote_endpoint);
~Session();
/**
@@ -123,4 +123,4 @@ bool iff_file::isFolderNode_(std::string& name)
return true;
}
return false;
-}
+}
@@ -17,10 +17,11 @@ ResourceManager::ResourceManager(std::shared_ptr<TreArchive> archive)
void ResourceManager::LoadResourceByName(const std::string& name, std::shared_ptr<VisitorInterface> type, bool is_cached)
{
- iff_file::loadIFF(archive_->GetResource(name), type);
+ auto resource = archive_->GetResource(name);
+ iff_file::loadIFF(resource, type);
if(is_cached)
{
boost::lock_guard<boost::mutex> lock(resource_mutex_);
loadedResources_.insert(ResourceCache::value_type(name, type));
}
-}
+}
@@ -1,7 +1,7 @@
// This file is part of SWGANH which is released under the MIT license.
// See file LICENSE or go to http://swganh.com/LICENSE
#pragma once
-
+#include<stdexcept>
namespace swganh
{
namespace tre
@@ -21,7 +21,7 @@ using namespace std;
BuffManager::BuffManager(swganh::app::SwganhKernel* kernel)
: kernel_(kernel)
- , timer_(kernel_->GetIoService())
+ , timer_(kernel_->GetCpuThreadPool())
{}
void BuffManager::Start()
@@ -60,7 +60,7 @@ using swganh::app::SwganhKernel;
CombatService::CombatService(SwganhKernel* kernel)
: generator_(1, 100)
-, active_(kernel->GetIoService())
+, active_(kernel->GetCpuThreadPool())
, kernel_(kernel)
, buff_manager_(kernel)
{
@@ -30,10 +30,10 @@ using swganh::object::Tangible;
CommandQueue::CommandQueue(
swganh::app::SwganhKernel* kernel)
: kernel_(kernel)
- , timer_(kernel->GetIoService())
+ , timer_(kernel->GetCpuThreadPool())
, processing_(false)
, default_command_(nullptr)
- , active_(kernel->GetIoService())
+ , active_(kernel->GetCpuThreadPool())
{
command_service_ = kernel->GetServiceManager()->GetService<CommandService>("CommandService");
}
@@ -14,8 +14,8 @@ using namespace swganh::connection;
using namespace swganh::object;
using namespace swganh::observer;
-ConnectionClient::ConnectionClient(ServerInterface* server, boost::asio::io_service& io_service, boost::asio::ip::udp::endpoint remote_endpoint)
- : ConnectionClientInterface(server, io_service, remote_endpoint)
+ConnectionClient::ConnectionClient(ServerInterface* server, boost::asio::io_service& cpu_pool, boost::asio::ip::udp::endpoint remote_endpoint)
+ : ConnectionClientInterface(server, cpu_pool, remote_endpoint)
{}
ConnectionClient::State ConnectionClient::GetState() const
@@ -19,7 +19,7 @@ class ConnectionClient : public swganh::connection::ConnectionClientInterface
/**
* Creates a new instance
*/
- ConnectionClient(swganh::network::soe::ServerInterface* server, boost::asio::io_service& io_service, boost::asio::ip::udp::endpoint remote_endpoint);
+ ConnectionClient(swganh::network::soe::ServerInterface* server, boost::asio::io_service& cpu_pool, boost::asio::ip::udp::endpoint remote_endpoint);
/**
* @return the current state of this remote client
@@ -26,9 +26,9 @@ class ConnectionClientInterface : public swganh::network::soe::Session
DISCONNECTING
};
- ConnectionClientInterface(swganh::network::soe::ServerInterface* server, boost::asio::io_service& io_service,
+ ConnectionClientInterface(swganh::network::soe::ServerInterface* server, boost::asio::io_service& cpu_pool,
boost::asio::ip::udp::endpoint remote_endpoint)
- : Session(server, io_service, remote_endpoint)
+ : Session(server, cpu_pool, remote_endpoint)
{
}
@@ -53,7 +53,7 @@ ConnectionService::ConnectionService(
: ConnectionServiceInterface(kernel)
, kernel_(kernel)
, ping_server_(nullptr)
- , active_(kernel->GetIoService())
+ , active_(kernel->GetIoThreadPool())
, listen_address_(listen_address)
, listen_port_(listen_port)
, ping_port_(ping_port)
@@ -85,7 +85,7 @@ ServiceDescription ConnectionService::GetServiceDescription() {
}
void ConnectionService::Startup() {
- ping_server_ = make_shared<PingServer>(kernel_->GetIoService(), ping_port_);
+ ping_server_ = make_shared<PingServer>(kernel_->GetIoThreadPool(), ping_port_);
character_service_ = kernel_->GetServiceManager()->GetService<CharacterServiceInterface>("CharacterService");
login_service_ = kernel_->GetServiceManager()->GetService<LoginServiceInterface>("LoginService");
@@ -128,7 +128,7 @@ shared_ptr<Session> ConnectionService::CreateSession(const udp::endpoint& endpoi
boost::lock_guard<boost::mutex> lg(session_map_mutex_);
if (session_map_.find(endpoint) == session_map_.end())
{
- session = make_shared<ConnectionClient>(this, kernel_->GetIoService(), endpoint);
+ session = make_shared<ConnectionClient>(this, kernel_->GetCpuThreadPool(), endpoint);
session_map_.insert(make_pair(endpoint, session));
LOG(info) << "Created Connection Service Session for " << endpoint.address().to_string();
}
@@ -50,7 +50,7 @@ class ConnectionServiceInterface : public swganh::service::ServiceInterface, pub
public:
ConnectionServiceInterface(swganh::app::SwganhKernel* kernel)
- : swganh::network::BaseSwgServer(kernel->GetIoService())
+ : swganh::network::BaseSwgServer(kernel->GetIoThreadPool())
{
}
@@ -55,7 +55,7 @@ uint64_t GalaxyService::GetGalaxyTimeInMilliseconds()
}
void GalaxyService::Startup()
{
- galaxy_timer_ = std::make_shared<boost::asio::deadline_timer>(kernel_->GetIoService(), boost::posix_time::seconds(10));
+ galaxy_timer_ = std::make_shared<boost::asio::deadline_timer>(kernel_->GetCpuThreadPool(), boost::posix_time::seconds(10));
galaxy_timer_->async_wait(boost::bind(&GalaxyService::GalaxyStatusTimerHandler_, this, boost::asio::placeholders::error, 10));
}
Oops, something went wrong.

0 comments on commit 9711ea0

Please sign in to comment.