summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-04-13 16:06:59 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-04-13 16:06:59 +0000
commit91e7127396a3dbb91f7eb46020182e8f7ebd5065 (patch)
tree74bb0c88f71f1bcd482df47ff961743098b29184
parent7e22cc38bbb415a65c9b852316cd6b4c2d1edd4b (diff)
2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Implemented clock_gettime() using mach_absolute_time in Mac OS X. * configure.ac * src/Makefile.am * src/a2time.h * src/clock_gettime_osx.cc * src/clock_gettime_osx.h
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure44
-rw-r--r--configure.ac11
-rw-r--r--src/Makefile.am6
-rw-r--r--src/Makefile.in15
-rw-r--r--src/a2time.h4
-rw-r--r--src/clock_gettime_osx.cc50
-rw-r--r--src/clock_gettime_osx.h41
8 files changed, 165 insertions, 9 deletions
diff --git a/config.h.in b/config.h.in
index 8fcec06e..ff5564ad 100644
--- a/config.h.in
+++ b/config.h.in
@@ -253,6 +253,9 @@
/* Define to 1 if the system has the type `long long int'. */
#undef HAVE_LONG_LONG_INT
+/* Define to 1 if you have the `mach_absolute_time' function. */
+#undef HAVE_MACH_ABSOLUTE_TIME
+
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
diff --git a/configure b/configure
index 87814249..23cabcb1 100755
--- a/configure
+++ b/configure
@@ -602,6 +602,8 @@ am__EXEEXT_TRUE
LTLIBOBJS
HAVE_TIMEGETTIME_FALSE
HAVE_TIMEGETTIME_TRUE
+HAVE_MACH_ABSOLUTE_TIME_FALSE
+HAVE_MACH_ABSOLUTE_TIME_TRUE
HAVE_DAEMON_FALSE
HAVE_DAEMON_TRUE
HAVE_TIMEGM_FALSE
@@ -15004,6 +15006,28 @@ fi
done
+if test "x$have_clock_gettime" != "xyes"; then
+ for ac_func in mach_absolute_time
+do :
+ ac_fn_cxx_check_func "$LINENO" "mach_absolute_time" "ac_cv_func_mach_absolute_time"
+if test "x$ac_cv_func_mach_absolute_time" = x""yes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_MACH_ABSOLUTE_TIME 1
+_ACEOF
+ have_mach_absolute_time=yes
+fi
+done
+
+fi
+ if test "x$have_mach_absolute_time" = "xyes"; then
+ HAVE_MACH_ABSOLUTE_TIME_TRUE=
+ HAVE_MACH_ABSOLUTE_TIME_FALSE='#'
+else
+ HAVE_MACH_ABSOLUTE_TIME_TRUE='#'
+ HAVE_MACH_ABSOLUTE_TIME_FALSE=
+fi
+
+
case "$target" in
*mingw*)
if true; then
@@ -15023,7 +15047,7 @@ else
fi
if test "x$have_clock_gettime" != "xyes"; then
- if true; then
+ if true; then
HAVE_TIMEGETTIME_TRUE=
HAVE_TIMEGETTIME_FALSE='#'
else
@@ -15033,6 +15057,16 @@ fi
fi
;;
+ *)
+ if false; then
+ HAVE_TIMEGETTIME_TRUE=
+ HAVE_TIMEGETTIME_FALSE='#'
+else
+ HAVE_TIMEGETTIME_TRUE='#'
+ HAVE_TIMEGETTIME_FALSE=
+fi
+
+ ;;
esac
ac_fn_cxx_check_member "$LINENO" "struct sockaddr_in" "sin_len" "ac_cv_member_struct_sockaddr_in_sin_len" "#include <netinet/in.h>
@@ -15361,6 +15395,10 @@ if test -z "${HAVE_DAEMON_TRUE}" && test -z "${HAVE_DAEMON_FALSE}"; then
as_fn_error "conditional \"HAVE_DAEMON\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${HAVE_MACH_ABSOLUTE_TIME_TRUE}" && test -z "${HAVE_MACH_ABSOLUTE_TIME_FALSE}"; then
+ as_fn_error "conditional \"HAVE_MACH_ABSOLUTE_TIME\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
if test -z "${HAVE_GETADDRINFO_TRUE}" && test -z "${HAVE_GETADDRINFO_FALSE}"; then
as_fn_error "conditional \"HAVE_GETADDRINFO\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
@@ -15373,6 +15411,10 @@ if test -z "${HAVE_TIMEGETTIME_TRUE}" && test -z "${HAVE_TIMEGETTIME_FALSE}"; th
as_fn_error "conditional \"HAVE_TIMEGETTIME\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
+if test -z "${HAVE_TIMEGETTIME_TRUE}" && test -z "${HAVE_TIMEGETTIME_FALSE}"; then
+ as_fn_error "conditional \"HAVE_TIMEGETTIME\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
: ${CONFIG_STATUS=./config.status}
ac_write_fail=0
diff --git a/configure.ac b/configure.ac
index 025732ff..4df00780 100644
--- a/configure.ac
+++ b/configure.ac
@@ -387,6 +387,12 @@ AM_CONDITIONAL([HAVE_DAEMON], [test "x$have_daemon" = "xyes"])
AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes])
+if test "x$have_clock_gettime" != "xyes"; then
+ AC_CHECK_FUNCS([mach_absolute_time], [have_mach_absolute_time=yes])
+fi
+AM_CONDITIONAL([HAVE_MACH_ABSOLUTE_TIME],
+ [test "x$have_mach_absolute_time" = "xyes"])
+
case "$target" in
*mingw*)
dnl defined in ws2tcpip.h, but only if _WIN32_WINNT >= 0x0501
@@ -394,9 +400,12 @@ case "$target" in
dnl defined in ws2tcpip.h, but missing in C:\mingw\lib\libws2_32.a
AM_CONDITIONAL([HAVE_GAI_STRERROR], false)
if test "x$have_clock_gettime" != "xyes"; then
- AM_CONDITIONAL([HAVE_TIMEGETTIME], true)
+ AM_CONDITIONAL([HAVE_TIMEGETTIME], true)
fi
;;
+ *)
+ AM_CONDITIONAL([HAVE_TIMEGETTIME], false)
+ ;;
esac
AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
diff --git a/src/Makefile.am b/src/Makefile.am
index 581efbef..c33dccd1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -519,7 +519,11 @@ endif # !HAVE_DAEMON
if HAVE_TIMEGETTIME
SRCS += clock_gettime_mingw.cc clock_gettime_mingw.h
-endif # !HAVE_TIMEGETTIME
+endif # HAVE_TIMEGETTIME
+
+if HAVE_MACH_ABSOLUTE_TIME
+SRCS += clock_gettime_osx.cc clock_gettime_osx.h
+endif # HAVE_MACH_ABSOLUTE_TIME
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
diff --git a/src/Makefile.in b/src/Makefile.in
index 1d65ced3..34882b66 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -278,6 +278,7 @@ bin_PROGRAMS = aria2c$(EXEEXT)
@HAVE_TIMEGM_FALSE@am__append_25 = timegm.c timegm.h
@HAVE_DAEMON_FALSE@am__append_26 = daemon.cc daemon.h
@HAVE_TIMEGETTIME_TRUE@am__append_27 = clock_gettime_mingw.cc clock_gettime_mingw.h
+@HAVE_MACH_ABSOLUTE_TIME_TRUE@am__append_28 = clock_gettime_osx.cc clock_gettime_osx.h
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in alloca.c
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -604,7 +605,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
gai_strerror.h gettimeofday.c gettimeofday.h inet_aton.c \
inet_aton.h localtime_r.c localtime_r.h strptime.c strptime.h \
timegm.c timegm.h daemon.cc daemon.h clock_gettime_mingw.cc \
- clock_gettime_mingw.h
+ clock_gettime_mingw.h clock_gettime_osx.cc clock_gettime_osx.h
@ENABLE_XML_RPC_TRUE@am__objects_1 = \
@ENABLE_XML_RPC_TRUE@ XmlRpcRequestParserController.$(OBJEXT) \
@ENABLE_XML_RPC_TRUE@ XmlRpcRequestParserStateMachine.$(OBJEXT) \
@@ -783,7 +784,9 @@ am__objects_6 =
@HAVE_TIMEGM_FALSE@am__objects_25 = timegm.$(OBJEXT)
@HAVE_DAEMON_FALSE@am__objects_26 = daemon.$(OBJEXT)
@HAVE_TIMEGETTIME_TRUE@am__objects_27 = clock_gettime_mingw.$(OBJEXT)
-am__objects_28 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
+@HAVE_MACH_ABSOLUTE_TIME_TRUE@am__objects_28 = \
+@HAVE_MACH_ABSOLUTE_TIME_TRUE@ clock_gettime_osx.$(OBJEXT)
+am__objects_29 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
AbstractCommand.$(OBJEXT) \
InitiateConnectionCommandFactory.$(OBJEXT) \
DownloadCommand.$(OBJEXT) \
@@ -870,8 +873,8 @@ am__objects_28 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
$(am__objects_18) $(am__objects_19) $(am__objects_20) \
$(am__objects_21) $(am__objects_22) $(am__objects_23) \
$(am__objects_24) $(am__objects_25) $(am__objects_26) \
- $(am__objects_27)
-am_libaria2c_a_OBJECTS = $(am__objects_28)
+ $(am__objects_27) $(am__objects_28)
+am_libaria2c_a_OBJECTS = $(am__objects_29)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
@@ -1206,7 +1209,8 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
$(am__append_16) $(am__append_17) $(am__append_18) \
$(am__append_19) $(am__append_20) $(am__append_21) \
$(am__append_22) $(am__append_23) $(am__append_24) \
- $(am__append_25) $(am__append_26) $(am__append_27)
+ $(am__append_25) $(am__append_26) $(am__append_27) \
+ $(am__append_28)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -1609,6 +1613,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitfield.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittorrent_helper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clock_gettime_mingw.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clock_gettime_osx.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/daemon.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/download_helper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gai_strerror.Po@am__quote@
diff --git a/src/a2time.h b/src/a2time.h
index 093b2ed3..0576fdb4 100644
--- a/src/a2time.h
+++ b/src/a2time.h
@@ -67,7 +67,9 @@
#ifndef HAVE_CLOCK_GETTIME
# ifdef __MINGW32__
# include "clock_gettime_mingw.h"
-# else // !__MINGW32__
+# elif HAVE_MACH_ABSOLUTE_TIME
+# include "clock_gettime_osx.h"
+# else
# include "timespec.h"
# define clock_gettime(ID, TP) (-1)
# endif // !__MINGW32__
diff --git a/src/clock_gettime_osx.cc b/src/clock_gettime_osx.cc
new file mode 100644
index 00000000..4d2dbcae
--- /dev/null
+++ b/src/clock_gettime_osx.cc
@@ -0,0 +1,50 @@
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "clock_gettime_osx.h"
+
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+
+int clock_gettime(int dummyid, struct timespec* tp)
+{
+ uint64_t mt = mach_absolute_time();
+ static mach_timebase_info_data_t baseinfo;
+ if(baseinfo.denom == 0) {
+ mach_timebase_info(&baseinfo);
+ }
+ uint64_t t = mt*baseinfo.numer/baseinfo.denom;
+ tp->tv_sec = t/1000000000+2678400; // 1month offset(24*3600*31)
+ tp->tv_nsec = t%1000000000;
+ return 1;
+}
diff --git a/src/clock_gettime_osx.h b/src/clock_gettime_osx.h
new file mode 100644
index 00000000..8ede9b27
--- /dev/null
+++ b/src/clock_gettime_osx.h
@@ -0,0 +1,41 @@
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_CLOCK_GETTIME_OSX_H_
+#define _D_CLOCK_GETTIME_OSX_H_
+
+#include "timespec.h"
+
+int clock_gettime(int dummyid, struct timespec* tp);
+
+#endif // _D_CLOCK_GETTIME_OSX_H_