From 78bc2698327069aa69ff7460b9314cbe45bd4d66 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 30 Apr 2016 20:09:02 -0400 Subject: [PATCH] use std::chrono and not boost::chrono --- CMakeLists.txt | 5 +- Jamfile | 15 +-- configure.ac | 10 +- examples/Makefile.am | 2 +- examples/cmake/FindLibtorrentRasterbar.cmake | 7 +- include/libtorrent/time.hpp | 41 +------ m4/ax_boost_chrono.m4 | 119 ------------------- test/Makefile.am | 3 +- 8 files changed, 20 insertions(+), 182 deletions(-) delete mode 100644 m4/ax_boost_chrono.m4 diff --git a/CMakeLists.txt b/CMakeLists.txt index cf6a8dc7b..a21008a16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,13 +255,14 @@ endif() # Boost if(NOT DEFINED Boost_INCLUDE_DIR OR NOT DEFINED Boost_LIBRARIES) - FIND_PACKAGE(Boost REQUIRED COMPONENTS system chrono) + FIND_PACKAGE(Boost REQUIRED COMPONENTS system) endif() include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(torrent-rasterbar ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) # this works around a bug in asio in boost-1.39 -#add_definitions(-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -D__USE_W32_SOCKETS -DWIN32_LEAN_AND_MEAN ) +add_definitions(-DBOOST_ASIO_HASH_MAP_BUCKETS=1021 ) +add_definitions(-DBOOST_ASIO_HAS_STD_CHRONO=1 ) if (WIN32) target_link_libraries(torrent-rasterbar wsock32 ws2_32 Iphlpapi) diff --git a/Jamfile b/Jamfile index a0e524b43..9ee39df66 100644 --- a/Jamfile +++ b/Jamfile @@ -22,7 +22,6 @@ if $(BOOST_ROOT) ECHO "building boost from source directory: " $(BOOST_ROOT) ; use-project /boost : $(BOOST_ROOT) ; - alias boost_chrono : /boost/chrono//boost_chrono : : : $(BOOST_ROOT) ; alias boost_system : /boost/system//boost_system : : : $(BOOST_ROOT) ; } else @@ -42,13 +41,9 @@ else ; # the names are decorated in MacPorts - lib boost_chrono : : darwin boost_chrono-mt $(boost-lib-search-path) - : : $(boost-include-path) ; lib boost_system : : darwin boost_system-mt $(boost-lib-search-path) : : $(boost-include-path) ; - lib boost_chrono : : boost_chrono $(boost-lib-search-path) - : : $(boost-include-path) ; lib boost_system : : boost_system $(boost-lib-search-path) : : $(boost-include-path) ; } @@ -173,12 +168,10 @@ rule linking ( properties * ) # library, so that it properly exports its symbols result += BOOST_ALL_DYN_LINK ; result += boost_system/static/BOOST_ALL_DYN_LINK ; - result += boost_chrono/static/BOOST_ALL_DYN_LINK ; } else { result += boost_system/static ; - result += boost_chrono/static ; } if gcc in $(properties) @@ -192,12 +185,10 @@ rule linking ( properties * ) else if shared in $(properties) { result += boost_system/shared ; - result += boost_chrono/shared ; } else { result += boost_system ; - result += boost_chrono ; } result += BOOST_ALL_NO_LIB @@ -708,6 +699,10 @@ local usage-requirements = BOOST_EXCEPTION_DISABLE # enable cancel support in asio BOOST_ASIO_ENABLE_CANCELIO +# make sure asio uses std::chrono + BOOST_ASIO_HAS_STD_CHRONO +# this works around a bug in asio in boost-1.39 + BOOST_ASIO_HASH_MAP_BUCKETS=1021 @linking # these compiler settings just makes the compiler standard conforming msvc:/Zc:wchar_t @@ -718,8 +713,6 @@ local usage-requirements = $(CXXFLAGS) $(LDFLAGS) -# this works around a bug in asio in boost-1.39 - BOOST_ASIO_HASH_MAP_BUCKETS=1021 ; project torrent ; diff --git a/configure.ac b/configure.ac index 13b6ca8da..cb023505e 100644 --- a/configure.ac +++ b/configure.ac @@ -123,13 +123,9 @@ AX_BOOST_SYSTEM() AS_IF([test -z "$BOOST_SYSTEM_LIB"], [AC_MSG_ERROR(Boost.System library not found. Try using --with-boost-system=lib)]) -AX_BOOST_CHRONO() -AS_IF([test -z "$BOOST_CHRONO_LIB"], - [AC_MSG_ERROR(Boost.Chrono library not found. Try using --with-boost-chrono=lib)]) - CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS" LDFLAGS="$BOOST_LDFLAGS $LDFLAGS" -LIBS="$BOOST_CHRONO_LIB $BOOST_SYSTEM_LIB $LIBS" +LIBS="$BOOST_SYSTEM_LIB $LIBS" ############################################################################### # Checking for functions and other stuffs @@ -532,6 +528,9 @@ AM_CONDITIONAL([WITH_OPENSSL], [test "x$ARG_ENABLE_ENCRYPTION" = "xyes" -o "x$AR AC_DEFINE([BOOST_ASIO_HASH_MAP_BUCKETS],[1021],[Define to fix a wrong behavior in boost 1.39.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 " +AC_DEFINE([BOOST_ASIO_HAS_STD_CHRONO],[1],[Define to make sure asio uses std::chrono.]) +COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_ASIO_HAS_STD_CHRONO=1 " + AC_DEFINE([BOOST_EXCEPTION_DISABLE],[1],[Define to disable the boost.exception features.]) COMPILETIME_OPTIONS="$COMPILETIME_OPTIONS -DBOOST_EXCEPTION_DISABLE " @@ -640,7 +639,6 @@ Boost libraries: CPPFlags: ${BOOST_CPPFLAGS} LDFlags: ${BOOST_LDFLAGS} boost.system: ${BOOST_SYSTEM_LIB} - boost.chrono: ${BOOST_CHRONO_LIB} END AS_IF([test "x$ARG_ENABLE_PYTHON_BINDING" = "xyes"], [ diff --git a/examples/Makefile.am b/examples/Makefile.am index 4ced3561c..ad0daad8a 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -30,5 +30,5 @@ LDADD = $(top_builddir)/src/libtorrent-rasterbar.la AM_CPPFLAGS = -ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ -AM_LDFLAGS = @BOOST_SYSTEM_LIB@ @BOOST_CHRONO_LIB@ @BOOST_RANDOM_LIB@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ +AM_LDFLAGS = @BOOST_SYSTEM_LIB@ @BOOST_RANDOM_LIB@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ diff --git a/examples/cmake/FindLibtorrentRasterbar.cmake b/examples/cmake/FindLibtorrentRasterbar.cmake index 1edeab971..cbf188df4 100644 --- a/examples/cmake/FindLibtorrentRasterbar.cmake +++ b/examples/cmake/FindLibtorrentRasterbar.cmake @@ -42,7 +42,7 @@ else() if(NOT LibtorrentRasterbar_USE_STATIC_LIBS) list(APPEND LibtorrentRasterbar_DEFINITIONS -DTORRENT_LINKING_SHARED - -DBOOST_SYSTEM_DYN_LINK -DBOOST_CHRONO_DYN_LINK) + -DBOOST_SYSTEM_DYN_LINK) endif() endif() @@ -62,8 +62,8 @@ endif() set(LibtorrentRasterbar_LIBRARIES ${LibtorrentRasterbar_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) set(LibtorrentRasterbar_INCLUDE_DIRS ${LibtorrentRasterbar_INCLUDE_DIR}) -if(NOT Boost_SYSTEM_FOUND OR NOT Boost_CHRONO_FOUND OR NOT Boost_RANDOM_FOUND) - find_package(Boost REQUIRED COMPONENTS system chrono random) +if(NOT Boost_SYSTEM_FOUND OR NOT Boost_RANDOM_FOUND) + find_package(Boost REQUIRED COMPONENTS system random) set(LibtorrentRasterbar_LIBRARIES ${LibtorrentRasterbar_LIBRARIES} ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) set(LibtorrentRasterbar_INCLUDE_DIRS @@ -85,7 +85,6 @@ find_package_handle_standard_args(LibtorrentRasterbar DEFAULT_MSG LibtorrentRasterbar_LIBRARY LibtorrentRasterbar_INCLUDE_DIR Boost_SYSTEM_FOUND - Boost_CHRONO_FOUND Boost_RANDOM_FOUND) mark_as_advanced(LibtorrentRasterbar_INCLUDE_DIR LibtorrentRasterbar_LIBRARY diff --git a/include/libtorrent/time.hpp b/include/libtorrent/time.hpp index a63cefd34..5d5702b8b 100644 --- a/include/libtorrent/time.hpp +++ b/include/libtorrent/time.hpp @@ -39,11 +39,7 @@ POSSIBILITY OF SUCH DAMAGE. #include -#if defined BOOST_ASIO_HAS_STD_CHRONO #include -#else -#include -#endif #if defined TORRENT_BUILD_SIMULATOR #include "simulator/simulator.hpp" @@ -54,31 +50,20 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { #if defined TORRENT_BUILD_SIMULATOR - typedef sim::chrono::high_resolution_clock clock_type; -#elif defined BOOST_ASIO_HAS_STD_CHRONO - typedef std::chrono::high_resolution_clock clock_type; + using clock_type = sim::chrono::high_resolution_clock; #else - typedef boost::chrono::high_resolution_clock clock_type; + using clock_type = std::chrono::high_resolution_clock; #endif - typedef clock_type::time_point time_point; - typedef clock_type::duration time_duration; + using time_point = clock_type::time_point; + using time_duration = clock_type::duration; -#if defined BOOST_ASIO_HAS_STD_CHRONO using std::chrono::seconds; using std::chrono::milliseconds; using std::chrono::microseconds; using std::chrono::minutes; using std::chrono::hours; using std::chrono::duration_cast; -#else - using boost::chrono::seconds; - using boost::chrono::milliseconds; - using boost::chrono::microseconds; - using boost::chrono::minutes; - using boost::chrono::hours; - using boost::chrono::duration_cast; -#endif // internal inline time_point min_time() { return (time_point::min)(); } @@ -98,24 +83,6 @@ namespace libtorrent { boost::int64_t total_microseconds(T td) { return duration_cast(td).count(); } -#ifndef TORRENT_NO_DEPRECATE - - TORRENT_DEPRECATED - time_point time_now(); - - TORRENT_DEPRECATED - time_point time_now_hires(); - - inline time_point time_now() - { return clock_type::now(); } - - inline time_point time_now_hires() - { return clock_type::now(); } - - typedef time_point ptime; - -#endif - } #endif // TORRENT_TIME_HPP_INCLUDED diff --git a/m4/ax_boost_chrono.m4 b/m4/ax_boost_chrono.m4 deleted file mode 100644 index 5d065e240..000000000 --- a/m4/ax_boost_chrono.m4 +++ /dev/null @@ -1,119 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_boost_chrono.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_BOOST_CHRONO -# -# DESCRIPTION -# -# Test for System library from the Boost C++ libraries. The macro requires -# a preceding call to AX_BOOST_BASE. Further documentation is available at -# . -# -# This macro calls: -# -# AC_SUBST(BOOST_CHRONO_LIB) -# -# And sets: -# -# HAVE_BOOST_CHRONO -# -# LICENSE -# -# Copyright (c) 2012 Xiyue Deng -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 1 - -AC_DEFUN([AX_BOOST_CHRONO], -[ - AC_ARG_WITH([boost-chrono], - AS_HELP_STRING([--with-boost-chrono@<:@=special-lib@:>@], - [use the Chrono library from boost - it is possible to specify a certain library for the linker - e.g. --with-boost-chrono=boost_chrono-gcc-mt ]), - [ - if test "$withval" = "no"; then - want_boost="no" - elif test "$withval" = "yes"; then - want_boost="yes" - ax_boost_user_chrono_lib="" - else - want_boost="yes" - ax_boost_user_chrono_lib="$withval" - fi - ], - [want_boost="yes"] - ) - - if test "x$want_boost" = "xyes"; then - AC_REQUIRE([AC_PROG_CC]) - AC_REQUIRE([AC_CANONICAL_BUILD]) - CPPFLAGS_SAVED="$CPPFLAGS" - CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" - export CPPFLAGS - - LDFLAGS_SAVED="$LDFLAGS" - LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" - export LDFLAGS - - AC_CACHE_CHECK(whether the Boost::Chrono library is available, - ax_cv_boost_chrono, - [AC_LANG_PUSH([C++]) - CXXFLAGS_SAVE=$CXXFLAGS - - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include ]], - [[boost::chrono::system_clock::time_point time;]])], - ax_cv_boost_chrono=yes, ax_cv_boost_chrono=no) - CXXFLAGS=$CXXFLAGS_SAVE - AC_LANG_POP([C++]) - ]) - if test "x$ax_cv_boost_chrono" = "xyes"; then - AC_SUBST(BOOST_CPPFLAGS) - - AC_DEFINE(HAVE_BOOST_CHRONO,,[define if the Boost::Chrono library is available]) - BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` - - LDFLAGS_SAVE=$LDFLAGS - if test "x$ax_boost_user_chrono_lib" = "x"; then - for libextension in `ls $BOOSTLIBDIR/libboost_chrono*.so* $BOOSTLIBDIR/libboost_chrono*.dylib* $BOOSTLIBDIR/libboost_chrono*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_chrono.*\)\.so.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_chrono.*\)\.a.*$;\1;'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break], - [link_chrono="no"]) - done - if test "x$link_chrono" != "xyes"; then - for libextension in `ls $BOOSTLIBDIR/boost_chrono*.dll* $BOOSTLIBDIR/boost_chrono*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_chrono.*\)\.dll.*$;\1;' -e 's;^\(boost_chrono.*\)\.a.*$;\1;'` ; do - ax_lib=${libextension} - AC_CHECK_LIB($ax_lib, exit, - [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break], - [link_chrono="no"]) - done - fi - - else - for ax_lib in $ax_boost_user_chrono_lib boost_chrono-$ax_boost_user_chrono_lib; do - AC_CHECK_LIB($ax_lib, exit, - [BOOST_CHRONO_LIB="-l$ax_lib"; AC_SUBST(BOOST_CHRONO_LIB) link_chrono="yes"; break], - [link_chrono="no"]) - done - - fi - if test "x$ax_lib" = "x"; then - AC_MSG_ERROR(Could not find a version of the library!) - fi - if test "x$link_chrono" = "xno"; then - AC_MSG_ERROR(Could not link against $ax_lib !) - fi - fi - - CPPFLAGS="$CPPFLAGS_SAVED" - LDFLAGS="$LDFLAGS_SAVED" - fi -]) - diff --git a/test/Makefile.am b/test/Makefile.am index f8523492d..42c1a26c4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -231,6 +231,5 @@ LDADD = libtest.la $(top_builddir)/src/libtorrent-rasterbar.la #AM_CXXFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include -I$(top_srcdir)/include/libtorrent @DEBUGFLAGS@ @PTHREAD_CFLAGS@ AM_CPPFLAGS=-ftemplate-depth-50 -I$(top_srcdir)/include @DEBUGFLAGS@ -AM_LDFLAGS=@BOOST_SYSTEM_LIB@ @PTHREAD_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@ \ - @BOOST_CHRONO_LIB@ +AM_LDFLAGS=@BOOST_SYSTEM_LIB@ @PTHREAD_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@