Skip to content

Commit

Permalink
Merge pull request #33 from ywy2090/main
Browse files Browse the repository at this point in the history
sync code from hsm branch
  • Loading branch information
ywy2090 authored Apr 10, 2023
2 parents 7401140 + 3ad75a9 commit afe8c0f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})

# install dependencies
hunter_add_package(Boost COMPONENTS all)
if(NOT MSVC)
hunter_add_package(range-v3)
find_package(range-v3 CONFIG REQUIRED)
endif()
# for compile
set(BCOS_UTILITIES_TARGET "bcos-utilities")
add_subdirectory(bcos-utilities)

if (TESTS)
if (TESTS)
enable_testing()
set(CTEST_OUTPUT_ON_FAILURE TRUE)
add_subdirectory(tests)
Expand Down
17 changes: 13 additions & 4 deletions bcos-cmake-scripts/CompilerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
endif()
endif ()
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")

# Only support visual studio 2017 and visual studio 2019
set(MSVC_MIN_VERSION "1914") # VS2017 15.7, for full-ish C++17 support
set(MSVC_MIN_VERSION "1914") # VS2017 15.7, for full-ish C++20 support

message(STATUS "Compile On Windows, MSVC_TOOLSET_VERSION: ${MSVC_TOOLSET_VERSION}")

if (MSVC_TOOLSET_VERSION EQUAL 141)
Expand All @@ -152,7 +152,16 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
message(FATAL_ERROR "Unsupported Visual Studio, supported list: [2017, 2019]. Current MSVC_TOOLSET_VERSION: ${MSVC_TOOLSET_VERSION}")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
add_definitions(-DUSE_STD_RANGES)
add_compile_options(/std:c++latest)
add_compile_options(-bigobj)

# # MSVC only support static build
# set(CMAKE_CXX_FLAGS_DEBUG "/MTd /DEBUG")
# set(CMAKE_CXX_FLAGS_MINSIZEREL "/MT /Os")
# set(CMAKE_CXX_FLAGS_RELEASE "/MT")
# set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MT /DEBUG")
link_libraries(ws2_32 Crypt32 userenv)
else ()
message(WARNING "Your compiler is not tested, if you run into any issues, we'd welcome any patches.")
endif ()
Expand Down
28 changes: 12 additions & 16 deletions bcos-utilities/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,33 @@ bytes const NullBytes;
/// get utc time(ms)
uint64_t utcTime()
{
#if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN32_)
return std::chrono::steady_clock::now().time_since_epoch().count() / 1000000;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
#endif
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
}

// getSteadyTime(ms)
uint64_t utcSteadyTime()
{
// trans (ns) into (ms)
return std::chrono::steady_clock::now().time_since_epoch().count() / 1000000;
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
}

/// get utc time(us)
uint64_t utcTimeUs()
{
#if defined(WIN32) || defined(WIN64) || defined(_WIN32) || defined(_WIN32_)
return std::chrono::steady_clock::now().time_since_epoch().count() / 1000;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000000 + tv.tv_usec;
#endif
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();
}

uint64_t utcSteadyTimeUs()
{
return std::chrono::steady_clock::now().time_since_epoch().count() / 1000;
return std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now().time_since_epoch())
.count();
}

std::string getCurrentDateTime()
Expand Down
14 changes: 13 additions & 1 deletion bcos-utilities/IOServicePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#pragma once
#include "Log.h"
#include <boost/asio.hpp>
#include <memory>
namespace bcos
Expand Down Expand Up @@ -59,7 +60,18 @@ class IOServicePool
// one io_context per thread
for (size_t i = 0; i < m_ioServices.size(); ++i)
{
m_threads.emplace_back([this, i]() { (m_ioServices[i])->run(); });
auto ioService = m_ioServices[i];
m_threads.emplace_back([ioService]() {
try
{
ioService->run();
}
catch (std::exception const& e)
{
BCOS_LOG(WARNING) << LOG_DESC("IOServicePool: ioService run exception")
<< LOG_KV("msg", boost::diagnostic_information(e));
}
});
}
}

Expand Down

0 comments on commit afe8c0f

Please sign in to comment.