time: remove xpause() and related dependency 56/21056/3
Clément DAVID [Wed, 24 Jul 2019 13:03:04 +0000 (15:03 +0200)]
POSIX.1-2008 nanosleep() is used for other functionnalities. This remove
POSIX.1-2001 sleep() and usleep() usage on Scilab codebase.

Change-Id: I60c3a7fc98bf059f9bc177c5f087738dc583e8fb

15 files changed:
scilab/configure
scilab/configure.ac
scilab/modules/core/includes/machine.h.in
scilab/modules/tclsci/src/c/TCL_Command.c
scilab/modules/time/Makefile.am
scilab/modules/time/Makefile.in
scilab/modules/time/help/en_US/sleep.xml
scilab/modules/time/help/fr_FR/sleep.xml
scilab/modules/time/includes/gw_time.h
scilab/modules/time/sci_gateway/c/sci_xpause.c [deleted file]
scilab/modules/time/sci_gateway/cpp/sci_sleep.cpp
scilab/modules/time/sci_gateway/cpp/time_gw.cpp
scilab/modules/time/sci_gateway/cpp/time_gw.vcxproj
scilab/modules/time/sci_gateway/cpp/time_gw.vcxproj.filters
scilab/modules/time/src/c/getdate.c

index 084699a..192bb93 100755 (executable)
@@ -25444,7 +25444,7 @@ fi
 ##############################################################
 
 # Provided by unistd.h
-for ac_func in sleep usleep dup2 getcwd getpagesize getpass
+for ac_func in dup2 getcwd getpagesize getpass
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -25562,12 +25562,13 @@ done
 
 
 # Provided by time.h
-for ac_func in gettimeofday
+for ac_func in nanosleep gettimeofday
 do :
-  ac_fn_c_check_func "$LINENO" "gettimeofday" "ac_cv_func_gettimeofday"
-if test "x$ac_cv_func_gettimeofday" = xyes; then :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
   cat >>confdefs.h <<_ACEOF
-#define HAVE_GETTIMEOFDAY 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
 _ACEOF
 
 fi
index 7c3717f..49d9281 100644 (file)
@@ -1265,7 +1265,7 @@ AC_SUBST(GUI_ENABLE)
 ##############################################################
 
 # Provided by unistd.h
-AC_CHECK_FUNCS([sleep] [usleep] [dup2] [getcwd] [getpagesize] [getpass])
+AC_CHECK_FUNCS([dup2] [getcwd] [getpagesize] [getpass])
 AC_CHECK_FUNCS([rmdir])
 
 AC_CHECK_FUNC([getwd],AC_DEFINE([HAVE_GETWD],[1],[Define to 1 if you have the `getwd' function.]),[AC_DEFINE([getwd(x)],[getcwd(x,1024)],[Don't use getwd but getcwd])])
@@ -1289,7 +1289,7 @@ AC_CHECK_FUNCS([endpwent])
 AC_CHECK_FUNCS([gethostbyaddr] [gethostbyname] [gethostname])
 
 # Provided by time.h
-AC_CHECK_FUNCS([gettimeofday])
+AC_CHECK_FUNCS([gettimeofday] [nanosleep])
 
 # Provided by ctype.h
 AC_CHECK_FUNCS([isascii])
index b7bd5ab..5369780 100644 (file)
 /* Define to 1 if you have the <sgtty.h> header file. */
 #undef HAVE_SGTTY_H
 
-/* Define to 1 if you have the `sleep' function. */
-#undef HAVE_SLEEP
-
 /* Define to 1 if you have the `socket' function. */
 #undef HAVE_SOCKET
 
 /* Define to 1 if you have the <unistd.h> header file. */
 #undef HAVE_UNISTD_H
 
-/* Define to 1 if you have the `usleep' function. */
-#undef HAVE_USLEEP
-
 /* Define to 1 if you have the <values.h> header file. */
 #undef HAVE_VALUES_H
 
index fed04bd..049fed0 100644 (file)
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #ifdef _MSC_VER
 #include <Windows.h>
-#define usleep(micro) Sleep(micro/1000)
 #else
-#include <unistd.h>
+#include <time.h>
 #endif
 
 #include "os_string.h"
@@ -77,7 +77,16 @@ static void *sleepAndSignal(void* in)
         //printf(".");
         //fflush(NULL);
 #endif
-        usleep(TIME_TO_SLEEP);
+#ifdef _MSC_VER
+        Sleep(TIME_TO_SLEEP / 1000)
+#else
+        struct timespec rqtp = {0};
+        rqtp.tv_nsec = TIME_TO_SLEEP * 1000;
+        if (nanosleep(&rqtp, NULL))
+        {
+            fprintf(stderr, "[TCL Daemon] Sleep canceled : %s\n", TclCommand);
+        }
+#endif
         __LockSignal(&wakeUpLock);
         __Signal(&wakeUp);
         __UnLockSignal(&wakeUpLock);
index 393b579..82a5aab 100644 (file)
@@ -13,7 +13,6 @@ GATEWAY_C_SOURCES = \
     sci_gateway/c/sci_realtime.c \
     sci_gateway/c/sci_timer.c \
     sci_gateway/c/sci_calendar.c \
-    sci_gateway/c/sci_xpause.c \
     sci_gateway/c/sci_getdate.c
 
 GATEWAY_CPP_SOURCES = \
index 70e7648..0780afb 100644 (file)
@@ -192,7 +192,6 @@ libscitime_la_DEPENDENCIES = libscitime-algo.la
 am__objects_2 = sci_gateway/c/libscitime_la-sci_realtime.lo \
        sci_gateway/c/libscitime_la-sci_timer.lo \
        sci_gateway/c/libscitime_la-sci_calendar.lo \
-       sci_gateway/c/libscitime_la-sci_xpause.lo \
        sci_gateway/c/libscitime_la-sci_getdate.lo
 am__objects_3 = sci_gateway/cpp/libscitime_la-time_gw.lo \
        sci_gateway/cpp/libscitime_la-sci_tictoc.lo \
@@ -221,7 +220,6 @@ am__depfiles_remade =  \
        sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Plo \
        sci_gateway/c/$(DEPDIR)/libscitime_la-sci_realtime.Plo \
        sci_gateway/c/$(DEPDIR)/libscitime_la-sci_timer.Plo \
-       sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Plo \
        sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_sleep.Plo \
        sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_tictoc.Plo \
        sci_gateway/cpp/$(DEPDIR)/libscitime_la-time_gw.Plo \
@@ -600,7 +598,6 @@ GATEWAY_C_SOURCES = \
     sci_gateway/c/sci_realtime.c \
     sci_gateway/c/sci_timer.c \
     sci_gateway/c/sci_calendar.c \
-    sci_gateway/c/sci_xpause.c \
     sci_gateway/c/sci_getdate.c
 
 GATEWAY_CPP_SOURCES = \
@@ -838,9 +835,6 @@ sci_gateway/c/libscitime_la-sci_timer.lo:  \
 sci_gateway/c/libscitime_la-sci_calendar.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/c/libscitime_la-sci_xpause.lo:  \
-       sci_gateway/c/$(am__dirstamp) \
-       sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
 sci_gateway/c/libscitime_la-sci_getdate.lo:  \
        sci_gateway/c/$(am__dirstamp) \
        sci_gateway/c/$(DEPDIR)/$(am__dirstamp)
@@ -879,7 +873,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscitime_la-sci_realtime.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscitime_la-sci_timer.Plo@am__quote@ # am--include-marker
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_sleep.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_tictoc.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscitime_la-time_gw.Plo@am__quote@ # am--include-marker
@@ -959,13 +952,6 @@ sci_gateway/c/libscitime_la-sci_calendar.lo: sci_gateway/c/sci_calendar.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitime_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscitime_la-sci_calendar.lo `test -f 'sci_gateway/c/sci_calendar.c' || echo '$(srcdir)/'`sci_gateway/c/sci_calendar.c
 
-sci_gateway/c/libscitime_la-sci_xpause.lo: sci_gateway/c/sci_xpause.c
-@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitime_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscitime_la-sci_xpause.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Tpo -c -o sci_gateway/c/libscitime_la-sci_xpause.lo `test -f 'sci_gateway/c/sci_xpause.c' || echo '$(srcdir)/'`sci_gateway/c/sci_xpause.c
-@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Tpo sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='sci_gateway/c/sci_xpause.c' object='sci_gateway/c/libscitime_la-sci_xpause.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitime_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o sci_gateway/c/libscitime_la-sci_xpause.lo `test -f 'sci_gateway/c/sci_xpause.c' || echo '$(srcdir)/'`sci_gateway/c/sci_xpause.c
-
 sci_gateway/c/libscitime_la-sci_getdate.lo: sci_gateway/c/sci_getdate.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscitime_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT sci_gateway/c/libscitime_la-sci_getdate.lo -MD -MP -MF sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Tpo -c -o sci_gateway/c/libscitime_la-sci_getdate.lo `test -f 'sci_gateway/c/sci_getdate.c' || echo '$(srcdir)/'`sci_gateway/c/sci_getdate.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Tpo sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Plo
@@ -1229,7 +1215,6 @@ distclean: distclean-am
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Plo
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_realtime.Plo
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_timer.Plo
-       -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_sleep.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_tictoc.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-time_gw.Plo
@@ -1287,7 +1272,6 @@ maintainer-clean: maintainer-clean-am
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_getdate.Plo
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_realtime.Plo
        -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_timer.Plo
-       -rm -f sci_gateway/c/$(DEPDIR)/libscitime_la-sci_xpause.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_sleep.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-sci_tictoc.Plo
        -rm -f sci_gateway/cpp/$(DEPDIR)/libscitime_la-time_gw.Plo
index 092ff5b..240d71a 100644 (file)
@@ -151,7 +151,7 @@ sleep(30, "s")
                     <itemizedlist>
                         <listitem>
                             The fractional part of <varname>milliseconds</varname>
-                            is now accepted and processed (replace xpause(microseconds)).
+                            is now accepted and processed.
                         </listitem>
                         <listitem>Syntax sleep(seconds, "s") added.
                         </listitem>
index e032f6e..7a359b5 100644 (file)
@@ -161,7 +161,7 @@ sleep(30, "s")
                 <revdescription>
                     <itemizedlist>
                         <listitem>Les fractions de millisecondes sont maintenant
-                            acceptées et prises en compte (remplace xpause(microsecondes)).
+                            acceptées et prises en compte.
                         </listitem>
                         <listitem>Syntaxe sleep(secondes,"s") ajoutée.
                         </listitem>
index 6bd560f..8eb28b1 100644 (file)
@@ -22,7 +22,6 @@
 /*--------------------------------------------------------------------------*/
 TIME_IMPEXP int gw_time(void);
 /*--------------------------------------------------------------------------*/
-int sci_xpause(char *fname, void* pvApiCtx);
 int sci_realtimeinit(char *fname, void* pvApiCtx);
 int sci_realtime(char *fname, void* pvApiCtx);
 int sci_getdate(char *fname, void* pvApiCtx);
diff --git a/scilab/modules/time/sci_gateway/c/sci_xpause.c b/scilab/modules/time/sci_gateway/c/sci_xpause.c
deleted file mode 100644 (file)
index 6348ad1..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA - Allan CORNET
- *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
- *
- */
-
-/*--------------------------------------------------------------------------*/
-#ifdef _MSC_VER
-#include <Windows.h>
-#endif
-#include "machine.h"
-#ifdef HAVE_USLEEP
-#include <unistd.h>
-#endif
-#include "gw_time.h"
-#include "api_scilab.h"
-#include "sciprint.h"
-#include "Scierror.h"
-#include "localization.h"
-/*--------------------------------------------------------------------------*/
-int sci_xpause(char *fname, void* pvApiCtx)
-{
-
-    SciErr sciErr;
-    int m1 = 0, n1 = 0, sec = 0;
-    int * p1_in_address = NULL;
-    double * pDblReal = NULL;
-
-    sciprint(_("%s: Feature %s is obsolete and will be permanently removed in Scilab %s\n"), _("Warning"), fname, "6.1");
-    sciprint(_("%s: Please use %s instead.\n"), _("Warning"), "sleep()");
-
-    CheckLhs(0, 1);
-    CheckRhs(1, 1);
-
-    if (Rhs == 1)
-    {
-        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &p1_in_address);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-        sciErr = getMatrixOfDouble(pvApiCtx, p1_in_address, &m1, &n1, &pDblReal);
-        if (sciErr.iErr)
-        {
-            printError(&sciErr, 0);
-            return 0;
-        }
-
-        if (isScalar(pvApiCtx, p1_in_address) == 0)
-        {
-            Scierror(999, _("%s: Wrong type for input argument #%d: A real scalar expected.\n"), fname, 1);
-            return 0;
-        }
-
-        sec = (int)  * pDblReal;
-
-        if (sec <= 0)
-        {
-            Scierror(999, _("%s: Wrong values for input argument #%d: Non-negative integers expected.\n"), fname, 1);
-            return 0;
-        }
-#ifdef _MSC_VER
-        {
-            int ms = (sec) / 1000; /** time is specified in milliseconds in scilab**/
-            if (ms > 0)
-            {
-                Sleep(ms);    /* Number of milliseconds to sleep. */
-            }
-        }
-#else
-        {
-            unsigned useconds;
-            useconds = (unsigned) sec;
-            if (useconds != 0)
-#ifdef HAVE_USLEEP
-            {
-                usleep(useconds);
-            }
-#else
-#ifdef HAVE_SLEEP
-            {
-                sleep(useconds);
-            }
-#endif
-#endif
-        }
-#endif
-    }
-
-    LhsVar(1) = 0;
-    PutLhsVar();
-
-    return 0;
-}
-/*--------------------------------------------------------------------------*/
-
index 4f84058..21c5373 100644 (file)
@@ -82,23 +82,20 @@ types::Function::ReturnValue sci_sleep(types::typed_list &in, int _iRetCount, ty
     }
 #else
     {
+        struct timespec timeout;
         if (asSec)
         {
-            t *= 1000;
+            double s = std::floor(t);
+            timeout.tv_sec = (time_t) s;
+            timeout.tv_nsec = (t - s) * 10e9;
         }
-
-        if (t)
-#ifdef HAVE_USLEEP
+        else
         {
-            usleep(t * 1000);
+            double s = std::floor(t / 1e3);
+            timeout.tv_sec = (time_t) s;
+            timeout.tv_nsec = (t - (s * 1e3)) * 10e6;
         }
-#else
-#ifdef HAVE_SLEEP
-        {
-            sleep(t * 1000);
-        }
-#endif
-#endif
+        nanosleep(&timeout, NULL);
     }
 #endif
 
index 9ffd452..0defb0f 100644 (file)
@@ -27,7 +27,6 @@ int TimeModule::Load()
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"Calendar", &sci_calendar, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"timer", &sci_timer, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"sleep", &sci_sleep, MODULE_NAME));
-    symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"xpause", &sci_xpause, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"realtimeinit", &sci_realtimeinit, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"realtime", &sci_realtime, MODULE_NAME));
     symbol::Context::getInstance()->addFunction(types::Function::createFunction(L"tic", &sci_tic, MODULE_NAME));
index 5eb0b20..8419854 100644 (file)
     <ClCompile Include="..\c\sci_getdate.c" />
     <ClCompile Include="..\c\sci_realtime.c" />
     <ClCompile Include="..\c\sci_timer.c" />
-    <ClCompile Include="..\c\sci_xpause.c" />
     <ClCompile Include="sci_sleep.cpp" />
     <ClCompile Include="sci_tictoc.cpp" />
     <ClCompile Include="time_gw.cpp" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 97dbef1..4972939 100644 (file)
@@ -24,9 +24,6 @@
     <ClCompile Include="..\c\sci_calendar.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="..\c\sci_xpause.c">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="..\c\sci_getdate.c">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -53,4 +50,4 @@
     <Library Include="..\..\..\..\bin\lapack.lib" />
     <Library Include="..\..\..\..\bin\libintl.lib" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
index 52ab285..99e63c9 100644 (file)
@@ -69,7 +69,7 @@ double *getCurrentDateAsDoubleVector(int *iErr)
 #else
         struct timeval timebuffer;
         gettimeofday(&timebuffer, NULL);
-        nowstruct = localtime(&timebuffer);
+        nowstruct = localtime(&timebuffer.tv_sec);
 #endif
 
 #ifdef _MSC_VER