{"thread":{"id":"31464","subject":"RE: [PATCH v3] Support for setitimer() on platforms lacking it","startedAt":"2012-09-07T09:55:29Z","lastAt":"2012-09-07T18:29:01Z","messageCount":3,"participants":["Joachim Schmitz","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"198511","messageId":"002201cd8cde$ea7cacc0$bf760640$@schmitz-digital.de","threadId":"31464","inReplyTo":null,"subject":"RE: [PATCH v3] Support for setitimer() on platforms lacking it","fromName":"Joachim Schmitz","fromEmail":"jojo@schmitz-digital.de","sentAt":"2012-09-07T09:55:29Z","receivedAt":"2012-09-07T09:55:29Z","isPatch":true,"sender":{"key":"jojo@schmitz-digital.de","avatar":"https://avatars.githubusercontent.com/u/1786669?v=4"},"body":"HP NonStop (currently) doesn't have setitimer(). The previous attempt of an\nemulation (reverted by this commit) was not a real substitute for a recurring\nitimer (as here we also don't have SA_RESTART, so can't re-arm the timer).\nAs setitimer() is only used in cases of perceived latency and it doesn't affect\ncorrectness, it now gets disabled entirely, if NO_SETITIMER is set.\nHP NonStop does provide struct itimerval, but other platforms may not, so this\nis taken care of in this commit too, by setting NO_STRUCT_ITIMERVAL.\n\nSigned-off-by: Joachim Schmitz <jojo@schmitz-digital.de>\n---\n Makefile          |  5 +++++\n compat/itimer.c   | 50 --------------------------------------------------\n git-compat-util.h | 11 +++++++++--\n 3 files changed, 14 insertions(+), 52 deletions(-)\n delete mode 100644 compat/itimer.c\n\ndiff --git a/Makefile b/Makefile\nindex ac49320..7be555b 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -157,6 +157,11 @@ all::\n # Define NO_PREAD if you have a problem with pread() system call (e.g.\n # cygwin1.dll before v1.5.22).\n #\n+# Define NO_SETITIMER if you don't have setitimer()\n+#\n+# Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval\n+# This also implies NO_SETITIMER\n+#\n # Define NO_THREAD_SAFE_PREAD if your pread() implementation is not\n # thread-safe. (e.g. compat/pread.c or cygwin)\n #\ndiff --git a/compat/itimer.c b/compat/itimer.c\ndeleted file mode 100644\nindex 713f1ff..0000000\n--- a/compat/itimer.c\n+++ /dev/null\n@@ -1,50 +0,0 @@\n-#include \"../git-compat-util.h\"\n-\n-static int git_getitimer(int which, struct itimerval *value)\n-{\n-\tint ret = 0;\n-\n-\tswitch (which) {\n-\t\tcase ITIMER_REAL:\n-\t\t\tvalue->it_value.tv_usec = 0;\n-\t\t\tvalue->it_value.tv_sec = alarm(0);\n-\t\t\tret = 0; /* if alarm() fails, we get a SIGLIMIT */\n-\t\t\tbreak;\n-\t\tcase ITIMER_VIRTUAL: /* FALLTHRU */\n-\t\tcase ITIMER_PROF: errno = ENOTSUP; ret = -1; break;\n-\t\tdefault: errno = EINVAL; ret = -1;\n-\t}\n-\treturn ret;\n-}\n-\n-int git_setitimer(int which, const struct itimerval *value,\n-\t\t\t\tstruct itimerval *ovalue)\n-{\n-\tint ret = 0;\n-\n-\tif (!value\n-\t\t|| value->it_value.tv_usec < 0\n-\t\t|| value->it_value.tv_usec > 1000000\n-\t\t|| value->it_value.tv_sec < 0) {\n-\t\terrno = EINVAL;\n-\t\treturn -1;\n-\t}\n-\n-\telse if (ovalue)\n-\t\tif (!git_getitimer(which, ovalue))\n-\t\t\treturn -1; /* errno set in git_getitimer() */\n-\n-\telse\n-\tswitch (which) {\n-\t\tcase ITIMER_REAL:\n-\t\t\talarm(value->it_value.tv_sec +\n-\t\t\t\t(value->it_value.tv_usec > 0) ? 1 : 0);\n-\t\t\tret = 0; /* if alarm() fails, we get a SIGLIMIT */\n-\t\t\tbreak;\n-\t\tcase ITIMER_VIRTUAL: /* FALLTHRU */\n-\t\tcase ITIMER_PROF: errno = ENOTSUP; ret = -1; break;\n-\t\tdefault: errno = EINVAL; ret = -1;\n-\t}\n-\n-\treturn ret;\n-}\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 18089f0..4628d7a 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -162,9 +162,16 @@\n #define probe_utf8_pathname_composition(a,b)\n #endif\n \n+#ifdef NO_STRUCT_ITIMERVAL\n+struct itimerval {\n+\tstruct timeval it_interval;\n+\tstruct timeval it_value;\n+}\n+#define NO_SETITIMER\n+#endif\n+\n #ifdef NO_SETITIMER\n-#define setitimer(a,b,c) git_setitimer((a),(b),(c))\n-extern int git_setitimer(int, const struct itimerval *, struct itimerval *);\n+#define setitimer(which,value,ovalue)\n #endif\n \n #ifdef MKDIR_WO_TRAILING_SLASH\n-- \n1.7.12\n"},{"id":"198529","messageId":"7va9x1zszj.fsf@alter.siamese.dyndns.org","threadId":"31464","inReplyTo":"002201cd8cde$ea7cacc0$bf760640$@schmitz-digital.de","subject":"Re: [PATCH v3] Support for setitimer() on platforms lacking it","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-09-07T16:40:32Z","receivedAt":"2012-09-07T16:40:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Joachim Schmitz\" <jojo@schmitz-digital.de> writes:\n\n> HP NonStop (currently) doesn't have setitimer(). The previous attempt of an\n> emulation (reverted by this commit) was not a real substitute for a recurring\n> itimer (as here we also don't have SA_RESTART, so can't re-arm the timer).\n> As setitimer() is only used in cases of perceived latency and it doesn't affect\n> correctness, it now gets disabled entirely, if NO_SETITIMER is set.\n> HP NonStop does provide struct itimerval, but other platforms may not, so this\n> is taken care of in this commit too, by setting NO_STRUCT_ITIMERVAL.\n>\n> Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>\n\nThe end-result looks simple and nice (thanks for NO_STRUCT_ITIMERVAL).\n\nAs we are not going to include the earlier failed attempt in our\nlonger-term history (i.e. 'master', that never rewinds), however,\nI would prefer to see a replacement patch (as opposed to this one\nthat incrementally updates the previous failed attempt).  I could\nsquash this into the previous one myself though ;-)\n\nThanks.\n\n> ---\n>  Makefile          |  5 +++++\n>  compat/itimer.c   | 50 --------------------------------------------------\n>  git-compat-util.h | 11 +++++++++--\n>  3 files changed, 14 insertions(+), 52 deletions(-)\n>  delete mode 100644 compat/itimer.c\n>\n> diff --git a/Makefile b/Makefile\n> index ac49320..7be555b 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -157,6 +157,11 @@ all::\n>  # Define NO_PREAD if you have a problem with pread() system call (e.g.\n>  # cygwin1.dll before v1.5.22).\n>  #\n> +# Define NO_SETITIMER if you don't have setitimer()\n> +#\n> +# Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval\n> +# This also implies NO_SETITIMER\n> +#\n>  # Define NO_THREAD_SAFE_PREAD if your pread() implementation is not\n>  # thread-safe. (e.g. compat/pread.c or cygwin)\n>  #\n> diff --git a/compat/itimer.c b/compat/itimer.c\n> deleted file mode 100644\n> index 713f1ff..0000000\n> --- a/compat/itimer.c\n> +++ /dev/null\n> @@ -1,50 +0,0 @@\n> -#include \"../git-compat-util.h\"\n> -\n> -static int git_getitimer(int which, struct itimerval *value)\n> -{\n> -\tint ret = 0;\n> -\n> -\tswitch (which) {\n> -\t\tcase ITIMER_REAL:\n> -\t\t\tvalue->it_value.tv_usec = 0;\n> -\t\t\tvalue->it_value.tv_sec = alarm(0);\n> -\t\t\tret = 0; /* if alarm() fails, we get a SIGLIMIT */\n> -\t\t\tbreak;\n> -\t\tcase ITIMER_VIRTUAL: /* FALLTHRU */\n> -\t\tcase ITIMER_PROF: errno = ENOTSUP; ret = -1; break;\n> -\t\tdefault: errno = EINVAL; ret = -1;\n> -\t}\n> -\treturn ret;\n> -}\n> -\n> -int git_setitimer(int which, const struct itimerval *value,\n> -\t\t\t\tstruct itimerval *ovalue)\n> -{\n> -\tint ret = 0;\n> -\n> -\tif (!value\n> -\t\t|| value->it_value.tv_usec < 0\n> -\t\t|| value->it_value.tv_usec > 1000000\n> -\t\t|| value->it_value.tv_sec < 0) {\n> -\t\terrno = EINVAL;\n> -\t\treturn -1;\n> -\t}\n> -\n> -\telse if (ovalue)\n> -\t\tif (!git_getitimer(which, ovalue))\n> -\t\t\treturn -1; /* errno set in git_getitimer() */\n> -\n> -\telse\n> -\tswitch (which) {\n> -\t\tcase ITIMER_REAL:\n> -\t\t\talarm(value->it_value.tv_sec +\n> -\t\t\t\t(value->it_value.tv_usec > 0) ? 1 : 0);\n> -\t\t\tret = 0; /* if alarm() fails, we get a SIGLIMIT */\n> -\t\t\tbreak;\n> -\t\tcase ITIMER_VIRTUAL: /* FALLTHRU */\n> -\t\tcase ITIMER_PROF: errno = ENOTSUP; ret = -1; break;\n> -\t\tdefault: errno = EINVAL; ret = -1;\n> -\t}\n> -\n> -\treturn ret;\n> -}\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 18089f0..4628d7a 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -162,9 +162,16 @@\n>  #define probe_utf8_pathname_composition(a,b)\n>  #endif\n>  \n> +#ifdef NO_STRUCT_ITIMERVAL\n> +struct itimerval {\n> +\tstruct timeval it_interval;\n> +\tstruct timeval it_value;\n> +}\n> +#define NO_SETITIMER\n> +#endif\n> +\n>  #ifdef NO_SETITIMER\n> -#define setitimer(a,b,c) git_setitimer((a),(b),(c))\n> -extern int git_setitimer(int, const struct itimerval *, struct itimerval *);\n> +#define setitimer(which,value,ovalue)\n>  #endif\n>  \n>  #ifdef MKDIR_WO_TRAILING_SLASH\n"},{"id":"198540","messageId":"004701cd8d26$a7710cd0$f6532670$@schmitz-digital.de","threadId":"31464","inReplyTo":"7va9x1zszj.fsf@alter.siamese.dyndns.org","subject":"RE: [PATCH v3] Support for setitimer() on platforms lacking it","fromName":"Joachim Schmitz","fromEmail":"jojo@schmitz-digital.de","sentAt":"2012-09-07T18:29:01Z","receivedAt":"2012-09-07T18:29:01Z","isPatch":true,"sender":{"key":"jojo@schmitz-digital.de","avatar":"https://avatars.githubusercontent.com/u/1786669?v=4"},"body":"> From: Junio C Hamano [mailto:gitster@pobox.com]\n> Sent: Friday, September 07, 2012 6:41 PM\n> To: Joachim Schmitz\n> Cc: git@vger.kernel.org\n> Subject: Re: [PATCH v3] Support for setitimer() on platforms lacking it\n> \n> \"Joachim Schmitz\" <jojo@schmitz-digital.de> writes:\n> \n> > HP NonStop (currently) doesn't have setitimer(). The previous attempt of an\n> > emulation (reverted by this commit) was not a real substitute for a recurring\n> > itimer (as here we also don't have SA_RESTART, so can't re-arm the timer).\n> > As setitimer() is only used in cases of perceived latency and it doesn't affect\n> > correctness, it now gets disabled entirely, if NO_SETITIMER is set.\n> > HP NonStop does provide struct itimerval, but other platforms may not, so this\n> > is taken care of in this commit too, by setting NO_STRUCT_ITIMERVAL.\n> >\n> > Signed-off-by: Joachim Schmitz <jojo@schmitz-digital.de>\n> \n> The end-result looks simple and nice (thanks for NO_STRUCT_ITIMERVAL).\n> \n> As we are not going to include the earlier failed attempt in our\n> longer-term history (i.e. 'master', that never rewinds), however,\n> I would prefer to see a replacement patch (as opposed to this one\n> that incrementally updates the previous failed attempt).  I could\n> squash this into the previous one myself though ;-)\n\nYes, please ;-)\n\nBye, Jojo\n"}]}