Browse Source

Merge pull request #30 from subtly/master

updates for macos cmake build and threading
cl-refactor
Gav Wood 11 years ago
parent
commit
673bac9a25
  1. 4
      CMakeLists.txt
  2. 9
      alethzero/CMakeLists.txt
  3. 4
      eth/CMakeLists.txt
  4. 2
      libethereum/BlockChain.cpp
  5. 4
      libethereum/CMakeLists.txt
  6. 17
      libethereum/Client.cpp
  7. 6
      libethereum/Client.h
  8. 3
      libethereum/Common.cpp
  9. 14
      libethereum/Common.h
  10. 6
      libethereum/FileSystem.cpp
  11. 4
      secp256k1/CMakeLists.txt
  12. 4
      test/CMakeLists.txt

4
CMakeLists.txt

@ -77,6 +77,10 @@ mark_as_advanced(CRYPTOPP_INCLUDE_DIR CRYPTOPP_LIBRARIES)
include_directories(${CRYPTOPP_INCLUDE_DIR})
link_directories(${CRYPTOPP_LIBRARIES})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
link_directories(/usr/local/lib)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_subdirectory(secp256k1)
add_subdirectory(libethereum)
add_subdirectory(test)

9
alethzero/CMakeLists.txt

@ -6,6 +6,15 @@ aux_source_directory(. SRC_LIST)
include_directories(..)
link_directories(../libethereum)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
execute_process(
COMMAND brew info qt5 | grep Cellar | awk -F ' ' '{print $1}'
OUTPUT_VARIABLE osx_qt5
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_PREFIX_PATH /usr/local/Cellar/qt5/5.2.0)
include_directories(/usr/local/Cellar/qt5/5.2.0/include /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_package(Qt5Widgets REQUIRED)
add_executable(alethzero Main.ui ${SRC_LIST})

4
eth/CMakeLists.txt

@ -9,6 +9,10 @@ add_executable(eth ${SRC_LIST})
find_package(Threads REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(eth ethereum)
target_link_libraries(eth miniupnpc)
target_link_libraries(eth leveldb)

2
libethereum/BlockChain.cpp

@ -67,7 +67,7 @@ BlockChain::BlockChain(std::string _path, bool _killExisting)
{
if (_path.empty())
_path = Defaults::get()->m_dbPath;
boost::filesystem::create_directory(_path);
boost::filesystem::create_directories(_path);
if (_killExisting)
{
boost::filesystem::remove_all(_path + "/blocks");

4
libethereum/CMakeLists.txt

@ -17,6 +17,10 @@ target_link_libraries(ethereum boost_system)
target_link_libraries(ethereum boost_filesystem)
target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
message("Installation path: ${CMAKE_INSTALL_PREFIX}")
install( TARGETS ethereum ARCHIVE DESTINATION lib LIBRARY DESTINATION lib )

17
libethereum/Client.cpp

@ -41,7 +41,22 @@ Client::Client(std::string const& _clientVersion, Address _us, std::string const
m_s.sync(m_tq);
m_changed = true;
m_work = new thread([&](){ setThreadName("eth"); while (m_workState != Deleting) work(); m_workState = Deleted; });
static std::string thread_name = "eth";
#if defined(__APPLE__)
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
m_work = dispatch_queue_create(thread_name.c_str(), DISPATCH_QUEUE_SERIAL);
});
dispatch_async(m_work, ^{
#else
m_work = new thread([&](){
setThreadName(thread_name);
#endif
while (m_workState != Deleting) work(); m_workState = Deleted;
});
}
Client::~Client()

6
libethereum/Client.h

@ -120,7 +120,13 @@ private:
Overlay m_stateDB; ///< Acts as the central point for the state database, so multiple States can share it.
State m_s; ///< The present state of the client.
PeerServer* m_net = nullptr; ///< Should run in background and send us events when blocks found and allow us to send blocks as required.
#if defined(__APPLE__)
dispatch_queue_t m_work;
#else
std::thread* m_work; ///< The work thread.
#endif
std::mutex m_lock;
enum { Active = 0, Deleting, Deleted } m_workState = Active;
bool m_doMine = false; ///< Are we supposed to be mining?

3
libethereum/Common.cpp

@ -41,8 +41,11 @@ using namespace eth;
// Logging
int eth::g_logVerbosity = 8;
map<type_info const*, bool> eth::g_logOverride;
#if !defined(__APPLE__)
thread_local std::string eth::t_logThreadName = "???";
static std::string g_mainThreadName = (eth::t_logThreadName = "main");
#endif
void eth::simpleDebugOut(std::string const& _s, char const*)
{

14
libethereum/Common.h

@ -41,6 +41,11 @@
#include <boost/multiprecision/cpp_int.hpp>
#include "vector_ref.h"
// OSX likes GCD whichs runs threads within queues
#if defined(__APPLE__)
#include <dispatch/dispatch.h>
#endif
namespace eth
{
@ -151,9 +156,11 @@ public:
};
extern std::map<std::type_info const*, bool> g_logOverride;
extern thread_local std::string t_logThreadName;
#if !defined(__APPLE__)
extern thread_local std::string t_logThreadName;
inline void setThreadName(std::string const& _n) { t_logThreadName = _n; }
#endif
struct LogChannel { static const char constexpr* name = " "; static const int verbosity = 1; };
struct LeftChannel: public LogChannel { static const char constexpr* name = "<<<"; };
@ -180,7 +187,12 @@ public:
time_t rawTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char buf[9];
strftime(buf, 9, "%X", localtime(&rawTime));
#if defined(__APPLE__)
sstr << Id::name << " [ " << buf << " | " << dispatch_queue_get_label(dispatch_get_current_queue()) << (_term ? " ] " : "");
#else
sstr << Id::name << " [ " << buf << " | " << t_logThreadName << (_term ? " ] " : "");
#endif
}
}
~LogOutputStream() { if (Id::verbosity <= g_logVerbosity) g_logPost(sstr.str(), Id::name); }

6
libethereum/FileSystem.cpp

@ -48,10 +48,10 @@ std::string eth::getDataDir()
dataDirPath = boost::filesystem::path("/");
else
dataDirPath = boost::filesystem::path(homeDir);
#if defined(__APPLE__) && defined(__MACH__)
dataDirPath /= "Library" / "Application Support";
boost::filesystem::create_directory(dataDirPath);
return (dataDirPath / "Ethereum").string();
// This eventually needs to be put in proper wrapper (to support sandboxing)
return (dataDirPath / "Library/Application Support/Ethereum").string();
#else
return (dataDirPath / ".ethereum").string();
#endif

4
secp256k1/CMakeLists.txt

@ -10,4 +10,6 @@ add_library(secp256k1 secp256k1.c field_5x52_asm.asm)
set(CMAKE_C_FLAGS "-std=c99 -DUSE_FIELD_GMP -DUSE_NUM_GMP -DUSE_FIELD_INV_NUM")
target_link_libraries(secp256k1 gmp)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

4
test/CMakeLists.txt

@ -10,6 +10,10 @@ add_executable(testeth ${SRC_LIST})
find_package(Threads REQUIRED)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
include_directories(/usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
target_link_libraries(testeth ethereum)
target_link_libraries(testeth secp256k1)
target_link_libraries(testeth miniupnpc)

Loading…
Cancel
Save