From 79a4bedc3669dfd3a3845e78ede144b5d7be7d1c Mon Sep 17 00:00:00 2001 From: mydesktop Date: Wed, 30 Apr 2014 16:50:06 -0400 Subject: [PATCH] mac osx building fixes --- CMakeLists.txt | 21 ++++++++++++------- .../epee/include/net/abstract_tcp_server2.h | 4 ++-- .../epee/include/net/abstract_tcp_server2.inl | 4 ++-- .../epee/include/storages/portable_storage.h | 2 +- src/cryptonote_config.h | 2 +- src/cryptonote_core/miner.cpp | 11 +++++++--- src/cryptonote_core/miner.h | 2 +- src/daemon/daemon_commands_handler.h | 5 ++++- src/p2p/net_node.inl | 5 ++++- src/rpc/core_rpc_server.cpp | 5 ++++- tests/performance_tests/performance_utils.h | 2 +- 11 files changed, 41 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8510b3690..69f0ef3eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,20 +3,20 @@ cmake_minimum_required(VERSION 2.8.6) set(VERSION "0.1") # $Format:Packaged from commit %H%nset(COMMIT %h)%nset(REFS "%d")$ -function(set_static_flags) -if (NOT APPLE) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") -endif() -endfunction(set_static_flags) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_CONFIGURATION_TYPES "Debug;Release") enable_testing() +function(set_static_flags) + if (NOT APPLE) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") + endif() +endfunction(set_static_flags) + include_directories(src contrib/epee/include external "${CMAKE_BINARY_DIR}/version") if(APPLE) -include_directories(SYSTEM /usr/include/malloc) + include_directories(SYSTEM /usr/include/malloc) endif() set(STATIC ${MSVC} CACHE BOOL "Link libraries statically") @@ -61,6 +61,9 @@ else() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG}") + if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0") + endif() if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)) set(DEBUG_FLAGS "-g3 -Og") else() @@ -90,8 +93,10 @@ endif() include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) if(MINGW) set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock") -elseif(NOT MSVC) +elseif(APPLE) set(Boost_LIBRARIES "${Boost_LIBRARIES}") +elseif(NOT MSVC) + set(Boost_LIBRARIES "${Boost_LIBRARIES};rt") endif() set(COMMIT_ID_IN_VERSION ON CACHE BOOL "Include commit ID in version") diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index 29bf59a57..b8e291c32 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -153,7 +153,7 @@ namespace net_utils bool init_server(const std::string port, const std::string& address = "0.0.0.0"); /// Run the server's io_service loop. - bool run_server(size_t threads_count, bool wait = true); + bool run_server(size_t threads_count, bool wait = true, const boost::thread::attributes& attrs = boost::thread::attributes()); /// wait for service workers stop bool timed_wait_server_stop(uint64_t wait_mseconds); @@ -273,4 +273,4 @@ namespace net_utils #include "abstract_tcp_server2.inl" -#endif \ No newline at end of file +#endif diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 236bc1599..2a4b10e48 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -524,7 +524,7 @@ POP_WARNINGS } //--------------------------------------------------------------------------------- template - bool boosted_tcp_server::run_server(size_t threads_count, bool wait) + bool boosted_tcp_server::run_server(size_t threads_count, bool wait, const boost::thread::attributes& attrs) { TRY_ENTRY(); m_threads_count = threads_count; @@ -538,7 +538,7 @@ POP_WARNINGS for (std::size_t i = 0; i < threads_count; ++i) { boost::shared_ptr thread(new boost::thread( - boost::bind(&boosted_tcp_server::worker_thread, this))); + attrs, boost::bind(&boosted_tcp_server::worker_thread, this))); m_threads.push_back(thread); } CRITICAL_REGION_END(); diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h index 21904da9e..c244dac19 100644 --- a/contrib/epee/include/storages/portable_storage.h +++ b/contrib/epee/include/storages/portable_storage.h @@ -210,7 +210,7 @@ namespace epee template bool portable_storage::get_value(const std::string& value_name, t_value& val, hsection hparent_section) { - //BOOST_MPL_ASSERT(( boost::mpl::contains )); + BOOST_MPL_ASSERT(( boost::mpl::contains )); //TRY_ENTRY(); if(!hparent_section) hparent_section = &m_root; storage_entry* pentry = find_storage_entry(value_name, hparent_section); diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index b7c0170e3..34d053aa8 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -79,5 +79,5 @@ #define P2P_NET_DATA_FILENAME "p2pstate.bin" #define MINER_CONFIG_FILE_NAME "miner_conf.json" - +#define THREAD_STACK_SIZE 5 * 1024 * 1024 diff --git a/src/cryptonote_core/miner.cpp b/src/cryptonote_core/miner.cpp index 142c81f68..56b459d6e 100644 --- a/src/cryptonote_core/miner.cpp +++ b/src/cryptonote_core/miner.cpp @@ -193,7 +193,7 @@ namespace cryptonote return !m_stop; } //----------------------------------------------------------------------------------------------------- - bool miner::start(const account_public_address& adr, size_t threads_count) + bool miner::start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs) { m_mine_address = adr; m_threads_total = static_cast(threads_count); @@ -218,7 +218,9 @@ namespace cryptonote boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0); for(size_t i = 0; i != threads_count; i++) - m_threads.push_back(boost::thread(boost::bind(&miner::worker_thread, this))); + { + m_threads.push_back(boost::thread(attrs, boost::bind(&miner::worker_thread, this))); + } LOG_PRINT_L0("Mining has started with " << threads_count << " threads, good luck!" ) return true; @@ -269,7 +271,10 @@ namespace cryptonote { if(m_do_mining) { - start(m_mine_address, m_threads_total); + boost::thread::attributes attrs; + attrs.set_stack_size(THREAD_STACK_SIZE); + + start(m_mine_address, m_threads_total, attrs); } } //----------------------------------------------------------------------------------------------------- diff --git a/src/cryptonote_core/miner.h b/src/cryptonote_core/miner.h index 03f09509e..da4578b06 100644 --- a/src/cryptonote_core/miner.h +++ b/src/cryptonote_core/miner.h @@ -35,7 +35,7 @@ namespace cryptonote static void init_options(boost::program_options::options_description& desc); bool set_block_template(const block& bl, const difficulty_type& diffic, uint64_t height); bool on_block_chain_update(); - bool start(const account_public_address& adr, size_t threads_count); + bool start(const account_public_address& adr, size_t threads_count, const boost::thread::attributes& attrs); uint64_t get_speed(); void send_stop_signal(); bool stop(); diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 7695508c9..dca524f77 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -291,7 +291,10 @@ private: threads_count = (ok && 0 < threads_count) ? threads_count : 1; } - m_srv.get_payload_object().get_core().get_miner().start(adr, threads_count); + boost::thread::attributes attrs; + attrs.set_stack_size(THREAD_STACK_SIZE); + + m_srv.get_payload_object().get_core().get_miner().start(adr, threads_count, attrs); return true; } //-------------------------------------------------------------------------------- diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 4dafa2342..31d3e6597 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -278,9 +278,12 @@ namespace nodetool m_net_server.add_idle_handler(boost::bind(&node_server::idle_worker, this), 1000); m_net_server.add_idle_handler(boost::bind(&t_payload_net_handler::on_idle, &m_payload_handler), 1000); + boost::thread::attributes attrs; + attrs.set_stack_size(THREAD_STACK_SIZE); + //go to loop LOG_PRINT("Run net_service loop( " << thrds_count << " threads)...", LOG_LEVEL_0); - if(!m_net_server.run_server(thrds_count)) + if(!m_net_server.run_server(thrds_count, true, attrs)) { LOG_ERROR("Failed to run net tcp server!"); } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 311d2a145..4d78367b6 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -252,7 +252,10 @@ namespace cryptonote return true; } - if(!m_core.get_miner().start(adr, static_cast(req.threads_count))) + boost::thread::attributes attrs; + attrs.set_stack_size(THREAD_STACK_SIZE); + + if(!m_core.get_miner().start(adr, static_cast(req.threads_count), attrs)) { res.status = "Failed, mining not started"; return true; diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h index 45ca5b27b..fe1e1c7cd 100644 --- a/tests/performance_tests/performance_utils.h +++ b/tests/performance_tests/performance_utils.h @@ -14,7 +14,7 @@ void set_process_affinity(int core) { -#if defined (__APPLE__) +#if defined(__APPLE__) return; #elif defined(BOOST_WINDOWS) DWORD_PTR mask = 1;