Mercurial > octave
changeset 20923:58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
* doc/interpreter/system.txi: removed sleep and usleep from doc.
* libinterp/corefcn/sysdep.cc (pause): updated docstring.
* libinterp/corefcn/sysdep.cc (sleep): moved to deprecate sleep.m.
* libinterp/corefcn/sysdep.cc (usleep): moved to deprecate usleep.m.
* scripts/deprecated/sleep.m: moved here from sysdep.cc.
* scripts/deprecated/usleep.m: moved here from sysdep.cc.
* scripts/deprecated/module.mk: add sleep.m and usleep.m to build system.
* NEWS: deprecation news for sleep and usleep.
* libinterp/corefcn/data.cc: examples updated.
* libinterp/corefcn/syscalls.cc: examples updated.
* scripts/audio/@audioplayer/audioplayer.m: examples updated.
* scripts/audio/@audiorecorder/audiorecorder.m: examples updated.
* scripts/plot/util/ginput.m: examples updated.
* scripts/plot/util/private/__gnuplot_get_var__.m: use pause.
* scripts/plot/util/private/__gnuplot_ginput__.m: use pause.
* libinterp/corefcn/utils.cc (octave_sleep): Unified "sleep" functions here.
* libinterp/corefcn/utils.h: removed header cutils.h.
* libinterp/corefcn/graphics.cc (drawnow): use octave_sleep.
* libinterp/corefcn/graphics.cc (waitfor): use octave_sleep.
* libinterp/corefcn/toplev.cc (clean_up_and_exit): use octave_sleep.
* libinterp/corefcn/cutils.c: removed no longer needed code.
* libinterp/corefcn/cutils.h: removed no longer needed header.
* libinterp/corefcn/matherr.c: removed orphaned code.
* libinterp/corefcn/module.mk: removed cutils.h, cutils.c, and matherr.c from
build system.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Thu, 17 Dec 2015 16:04:13 +0100 |
parents | 49081851fddc |
children | e74e617060cf |
files | NEWS doc/interpreter/system.txi libinterp/corefcn/cutils.c libinterp/corefcn/cutils.h libinterp/corefcn/data.cc libinterp/corefcn/graphics.cc libinterp/corefcn/matherr.c libinterp/corefcn/module.mk libinterp/corefcn/syscalls.cc libinterp/corefcn/sysdep.cc libinterp/corefcn/toplev.cc libinterp/corefcn/utils.cc libinterp/corefcn/utils.h scripts/audio/@audioplayer/audioplayer.m scripts/audio/@audiorecorder/audiorecorder.m scripts/deprecated/module.mk scripts/deprecated/sleep.m scripts/deprecated/usleep.m scripts/plot/util/ginput.m scripts/plot/util/private/__gnuplot_get_var__.m scripts/plot/util/private/__gnuplot_ginput__.m |
diffstat | 21 files changed, 153 insertions(+), 272 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Wed Dec 16 16:47:18 2015 -0800 +++ b/NEWS Thu Dec 17 16:04:13 2015 +0100 @@ -80,6 +80,8 @@ bitmax | flintmax mahalanobis | mahal in Octave-Forge statistics pkg md5sum | hash + sleep | pause + usleep | pause wavread | audioread wavwrite | audiowrite
--- a/doc/interpreter/system.txi Wed Dec 16 16:47:18 2015 -0800 +++ b/doc/interpreter/system.txi Thu Dec 17 16:04:13 2015 +0100 @@ -129,10 +129,6 @@ @DOCSTRING(pause) -@DOCSTRING(sleep) - -@DOCSTRING(usleep) - @DOCSTRING(datenum) @DOCSTRING(datestr)
--- a/libinterp/corefcn/cutils.c Wed Dec 16 16:47:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - -Copyright (C) 1999-2015 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <time.h> - -#include <sys/types.h> -#include <unistd.h> - -#include "cutils.h" - -void -octave_sleep (unsigned int seconds) -{ - sleep (seconds); -} - -void -octave_usleep (unsigned int useconds) -{ - struct timespec delay; - struct timespec remaining; - - unsigned int sec = useconds / 1000000; - unsigned int usec = useconds % 1000000; - - delay.tv_sec = sec; - delay.tv_nsec = usec * 1000; - - nanosleep (&delay, &remaining); -} -
--- a/libinterp/corefcn/cutils.h Wed Dec 16 16:47:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - -Copyright (C) 2012-2015 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#if ! defined (octave_cutils_h) -#define octave_cutils_h 1 - -#include <stdarg.h> - -#ifdef __cplusplus -extern "C" { -#endif - -OCTINTERP_API void octave_sleep (unsigned int seconds); - -OCTINTERP_API void octave_usleep (unsigned int useconds); - -#ifdef __cplusplus -} -#endif - -#endif
--- a/libinterp/corefcn/data.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/data.cc Thu Dec 17 16:04:13 2015 +0100 @@ -6172,7 +6172,7 @@ \n\ @example\n\ @group\n\ -id = tic; sleep (5); toc (id)\n\ +id = tic; pause (5); toc (id)\n\ @result{} 5.0010\n\ @end group\n\ @end example\n\
--- a/libinterp/corefcn/graphics.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/graphics.cc Thu Dec 17 16:04:13 2015 +0100 @@ -43,7 +43,6 @@ #include "singleton-cleanup.h" #include "builtins.h" -#include "cutils.h" #include "defun.h" #include "display.h" #include "error.h" @@ -58,6 +57,7 @@ #include "toplev.h" #include "txt-eng-ft.h" #include "unwind-prot.h" +#include "utils.h" #include "octave-default-image.h" // forward declarations @@ -10983,7 +10983,7 @@ go.get_toolkit ().print_figure (go, term, file, mono, debug_file); - Fsleep (octave_value (0.05)); + octave_sleep (0.05); // FIXME: really needed? gh_manager::lock (); } @@ -11612,7 +11612,7 @@ break; } - octave_usleep (100000); + octave_sleep (0.1); // FIXME: really needed? OCTAVE_QUIT;
--- a/libinterp/corefcn/matherr.c Wed Dec 16 16:47:18 2015 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - -Copyright (C) 1997-2015 John W. Eaton - -This file is part of Octave. - -Octave 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 3 of the License, or (at your -option) any later version. - -Octave 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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#if defined (EXCEPTION_IN_MATH) - -#include "lo-math.h" - -int -matherr (struct exception *x) -{ - /* Possibly print our own message someday. Should probably be - user-switchable. */ - - switch (x->type) - { - case DOMAIN: - case SING: - case OVERFLOW: - case UNDERFLOW: - case TLOSS: - case PLOSS: - default: - break; - } - - /* But don't print the system message. */ - - return 1; -} -#endif
--- a/libinterp/corefcn/module.mk Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/module.mk Thu Dec 17 16:04:13 2015 +0100 @@ -28,7 +28,6 @@ libinterp/corefcn/c-file-ptr-stream.h \ libinterp/corefcn/cdisplay.h \ libinterp/corefcn/comment-list.h \ - libinterp/corefcn/cutils.h \ libinterp/corefcn/data.h \ libinterp/corefcn/debug.h \ libinterp/corefcn/defun-dld.h \ @@ -110,8 +109,6 @@ libinterp/corefcn/oct-tex-parser.yy C_COREFCN_SRC = \ - libinterp/corefcn/cutils.c \ - libinterp/corefcn/matherr.c \ libinterp/corefcn/siglist.c COREFCN_SRC = \
--- a/libinterp/corefcn/syscalls.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/syscalls.cc Thu Dec 17 16:04:13 2015 +0100 @@ -218,7 +218,7 @@ if (ischar (s))\n\ fputs (stdout, s);\n\ elseif (errno () == EAGAIN)\n\ - sleep (0.1);\n\ + pause (0.1);\n\ fclear (out);\n\ else\n\ done = true;\n\ @@ -317,7 +317,7 @@ %! str{idx} = s; %! elseif (errno () == EAGAIN) %! fclear (out); -%! sleep (0.1); +%! pause (0.1); %! if (++errs == 100) %! done = true; %! endif @@ -348,7 +348,7 @@ %! str{idx} = s; %! elseif (errno () == EAGAIN) %! fclear (out); -%! sleep (0.1); +%! pause (0.1); %! if (++errs == 100) %! done = true; %! endif
--- a/libinterp/corefcn/sysdep.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/sysdep.cc Thu Dec 17 16:04:13 2015 +0100 @@ -742,22 +742,31 @@ @deftypefnx {} {} pause (@var{n})\n\ Suspend the execution of the program for @var{n} seconds.\n\ \n\ -@var{n} is a positive real value and may be a fraction of a second.\n\ -\n\ If invoked without an input arguments then the program is suspended until a\n\ character is typed.\n\ \n\ +@var{n} is a positive real value and may be a fraction of a second,\n\ +for example:\n\ +\n\ +@example\n\ +@group\n\ +tic; pause (0.05); toc\n\ + @print{} Elapsed time is 0.05039 seconds.\n\ +@end group\n\ +@end example\n\ +\n\ The following example prints a message and then waits 5 seconds before\n\ clearing the screen.\n\ \n\ @example\n\ @group\n\ -fprintf (stderr, \"wait please...\\n\");\n\ +disp (\"wait please...\");\n\ pause (5);\n\ clc;\n\ @end group\n\ @end example\n\ -@seealso{kbhit, sleep}\n\ +\n\ +@seealso{kbhit}\n\ @end deftypefn") { octave_value_list retval; @@ -803,81 +812,6 @@ %!error (pause (1, 2)) */ -DEFUN (sleep, args, , - "-*- texinfo -*-\n\ -@deftypefn {} {} sleep (@var{seconds})\n\ -Suspend the execution of the program for the given number of seconds.\n\ -@seealso{usleep, pause}\n\ -@end deftypefn") -{ - octave_value_list retval; - - if (args.length () != 1) - print_usage (); - - double dval = args(0).double_value (); - - if (xisnan (dval)) - warning ("sleep: NaN is an invalid delay"); - else - { - Fdrawnow (); - octave_sleep (dval); - } - - return retval; -} - -/* -%!test -%! sleep (1); - -%!error (sleep ()) -%!error (sleep (1, 2)) -*/ - -DEFUN (usleep, args, , - "-*- texinfo -*-\n\ -@deftypefn {} {} usleep (@var{microseconds})\n\ -Suspend the execution of the program for the given number of\n\ -microseconds.\n\ -\n\ -On systems where it is not possible to sleep for periods of time less than\n\ -one second, @code{usleep} will pause the execution for @code{round\n\ -(@var{microseconds} / 1e6)} seconds.\n\ -@seealso{sleep, pause}\n\ -@end deftypefn") -{ - octave_value_list retval; - - if (args.length () != 1) - print_usage (); - - double dval = args(0).double_value (); - - if (xisnan (dval)) - warning ("usleep: NaN is an invalid delay"); - else - { - Fdrawnow (); - - int delay = NINT (dval); - - if (delay > 0) - octave_usleep (delay); - } - - return retval; -} - -/* -%!test -%! usleep (1000); - -%!error (usleep ()) -%!error (usleep (1, 2)) -*/ - // FIXME: maybe this should only return 1 if IEEE floating // point functions really work.
--- a/libinterp/corefcn/toplev.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/toplev.cc Thu Dec 17 16:04:13 2015 +0100 @@ -800,7 +800,7 @@ // exiting for us. Assume that job won't take more than a // day... - gnulib::sleep (86400); + octave_sleep (86400); // FIXME: really needed? } } else
--- a/libinterp/corefcn/utils.cc Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/utils.cc Thu Dec 17 16:04:13 2015 +0100 @@ -1355,25 +1355,22 @@ void octave_sleep (double seconds) { - if (seconds > 0) - { - double t; + if (seconds <= 0) + return; - unsigned int usec - = static_cast<unsigned int> (modf (seconds, &t) * 1000000); + double fraction = std::modf (seconds, &seconds); + fraction = std::floor (fraction * 1000000000); // nanoseconds - unsigned int sec - = ((t > std::numeric_limits<unsigned int>::max ()) - ? std::numeric_limits<unsigned int>::max () - : static_cast<unsigned int> (t)); + time_t sec = ((seconds > std::numeric_limits<time_t>::max ()) + ? std::numeric_limits<time_t>::max () + : static_cast<time_t> (seconds)); - // Versions of these functions that accept unsigned int args are - // defined in cutils.c. - octave_sleep (sec); - octave_usleep (usec); + // call GNULIB POSIX function + struct timespec delay = { sec, static_cast<long> (fraction) }; + struct timespec remaining; + gnulib::nanosleep (&delay, &remaining); - octave_quit (); - } + octave_quit (); } DEFUN (isindex, args, ,
--- a/libinterp/corefcn/utils.h Wed Dec 16 16:47:18 2015 -0800 +++ b/libinterp/corefcn/utils.h Thu Dec 17 16:04:13 2015 +0100 @@ -32,8 +32,6 @@ #include "dMatrix.h" #include "lo-utils.h" -#include "cutils.h" - class octave_value; class octave_value_list; class string_vector;
--- a/scripts/audio/@audioplayer/audioplayer.m Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/audio/@audioplayer/audioplayer.m Thu Dec 17 16:04:13 2015 +0100 @@ -114,11 +114,11 @@ %! audio = randn (2, 2*fs) - 0.5; %! player = audioplayer (audio, fs); %! play (player); -%! sleep (1); +%! pause (1); %! pause (player); -%! sleep (1); +%! pause (1); %! resume (player); -%! sleep (1); +%! pause (1); %! stop (player); ## Tests of audioplayer must not actually play anything. @@ -176,13 +176,13 @@ #%!testif HAVE_PORTAUDIO #%! player = audioplayer (@callback, 44100); #%! play (player); -#%! sleep (2); +#%! pause (2); #%! stop (player); #%! assert (1); #%!testif HAVE_PORTAUDIO #%! player = audioplayer ("callback", 44100, 16); #%! play (player); -#%! sleep (2); +#%! pause (2); #%! stop (player); #%! assert (1);
--- a/scripts/audio/@audiorecorder/audiorecorder.m Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/audio/@audiorecorder/audiorecorder.m Thu Dec 17 16:04:13 2015 +0100 @@ -57,13 +57,13 @@ %!demo %! recorder = audiorecorder (44100, 16, 2); %! record (recorder, 1); -%! sleep (2); +%! pause (2); %! player1 = audioplayer (recorder); %! player2 = getplayer (recorder); %! play (player1); -%! sleep (2); +%! pause (2); %! play (player2); -%! sleep (2); +%! pause (2); %! stop (player1); %! stop (player2); @@ -119,7 +119,7 @@ #%! recorder = audiorecorder (@callback_record, 44100); #%! unlink ("record.txt") #%! record (recorder); -#%! sleep (2); +#%! pause (2); #%! stop (recorder); #%! s = stat ("record.txt"); #%! assert (s.size > 0); @@ -128,7 +128,7 @@ #%! recorder = audiorecorder (@callback_record, 44100); #%! unlink ("record.txt") #%! record (recorder); -#%! sleep (2); +#%! pause (2); #%! stop (recorder); #%! s = stat ("record.txt"); #%! assert (s.size > 0);
--- a/scripts/deprecated/module.mk Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/deprecated/module.mk Thu Dec 17 16:04:13 2015 +0100 @@ -21,8 +21,10 @@ scripts/deprecated/playaudio.m \ scripts/deprecated/saveaudio.m \ scripts/deprecated/setaudio.m \ + scripts/deprecated/sleep.m \ scripts/deprecated/syl.m \ scripts/deprecated/usage.m \ + scripts/deprecated/usleep.m \ scripts/deprecated/wavread.m \ scripts/deprecated/wavwrite.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/sleep.m Thu Dec 17 16:04:13 2015 +0100 @@ -0,0 +1,51 @@ +## Copyright (C) 1993-2015 John W. Eaton +## +## This file is part of Octave. +## +## Octave 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 3 of the License, or (at +## your option) any later version. +## +## Octave 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 Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} sleep (@var{seconds})\n\ +## +## @code{sleep} is deprecated and will be removed in Octave version 4.6. +## Use @code{pause} instead. +## +## Suspend the execution of the program for the given number of seconds. +## +## @seealso{pause} +## @end deftypefn + +function [] = sleep (seconds) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "sleep is obsolete and will be removed from a future version of Octave, please use pause instead"); + endif + + if (nargin == 1) + pause (seconds); + else + print_usage (); + endif + +endfunction + +%!test +%! sleep (1); + +%!error (sleep ()) +%!error (sleep (1, 2))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/deprecated/usleep.m Thu Dec 17 16:04:13 2015 +0100 @@ -0,0 +1,52 @@ +## Copyright (C) 1993-2015 John W. Eaton +## +## This file is part of Octave. +## +## Octave 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 3 of the License, or (at +## your option) any later version. +## +## Octave 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 Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} usleep (@var{microseconds})\n\ +## +## @code{usleep} is deprecated and will be removed in Octave version 4.6. +## Use @code{pause} instead. +## +## Suspend the execution of the program for the given number of +## microseconds (1e-6 seconds). +## +## @seealso{pause} +## @end deftypefn + +function [] = usleep (microseconds) + + persistent warned = false; + if (! warned) + warned = true; + warning ("Octave:deprecated-function", + "usleep is obsolete and will be removed from a future version of Octave, please use pause instead"); + endif + + if (nargin == 1) + pause (microseconds / 1e6); + else + print_usage (); + endif + +endfunction + +%!test +%! usleep (1000); + +%!error (usleep ()) +%!error (usleep (1, 2))
--- a/scripts/plot/util/ginput.m Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/plot/util/ginput.m Thu Dec 17 16:04:13 2015 +0100 @@ -85,7 +85,7 @@ endif ## Release CPU. - sleep (0.01); + pause (0.01); [x, y, n0, button] = ginput_accumulator (-1, 0, 0, 0); until ((n > -1 && n0 >= n) || n0 < 0)
--- a/scripts/plot/util/private/__gnuplot_get_var__.m Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/plot/util/private/__gnuplot_get_var__.m Thu Dec 17 16:04:13 2015 +0100 @@ -117,7 +117,7 @@ while (isempty (str)) str = fread (istream, "*char")'; if (isempty (str)) - sleep (0.05); + pause (0.05); else str = regexp (str, 'OCTAVE:.*', "match"); str = str{end}(8:end);
--- a/scripts/plot/util/private/__gnuplot_ginput__.m Wed Dec 16 16:47:18 2015 -0800 +++ b/scripts/plot/util/private/__gnuplot_ginput__.m Thu Dec 17 16:04:13 2015 +0100 @@ -110,7 +110,7 @@ while (isempty (str)) str = fread (istream, "*char")'; if (isempty (str)) - sleep (0.05); + pause (0.05); else str = regexp (str, 'OCTAVE:\s+[-+.\d]+\s+[-+.\d]+\s+\d*', 'match'); endif