From: Jean Privat Date: Tue, 3 Jul 2012 23:29:29 +0000 (-0400) Subject: lib: move nanosleep from curses to time X-Git-Tag: v0.6~327 X-Git-Url: http://nitlanguage.org lib: move nanosleep from curses to time Signed-off-by: Jean Privat --- diff --git a/lib/curses/curses.nit b/lib/curses/curses.nit index af98bcb..11d5ab6 100644 --- a/lib/curses/curses.nit +++ b/lib/curses/curses.nit @@ -30,12 +30,6 @@ extern Window fun endwin is extern end -redef class Sys - # Wait a specific number of second and nanoseconds - # FIXME: should not be in the curses module - fun nanosleep(sec, nanosec: Int) is extern -end - redef class Stdin # Is these something to read? (non blocking) # FIXME: should not be in the curses module diff --git a/lib/curses/curses.nit.c b/lib/curses/curses.nit.c index 0e30dbb..c6457a8 100644 --- a/lib/curses/curses.nit.c +++ b/lib/curses/curses.nit.c @@ -4,7 +4,6 @@ */ #include "curses.nit.h" -#include #include /* @@ -67,14 +66,6 @@ void Window_endwin___impl( Window recv ) } /* -C implementation of curses::Sys::nanosleep -*/ -void Sys_nanosleep___impl( Sys recv, bigint sec, bigint nanosec ) { - const struct timespec req = {sec, nanosec}; - nanosleep(&req, NULL); -} - -/* C implementation of curses::Stdin::poll_in */ int Stdin_poll_in___impl( Stdin recv ) { diff --git a/lib/curses/curses.nit.h b/lib/curses/curses.nit.h index 6318fc4..83d3c00 100644 --- a/lib/curses/curses.nit.h +++ b/lib/curses/curses.nit.h @@ -16,6 +16,5 @@ void Window_refresh___impl( Window recv ); void Window_wclear___impl( Window recv ); void Window_delwin___impl( Window recv ); void Window_endwin___impl( Window recv ); -void Sys_nanosleep___impl( Sys recv, bigint sec, bigint nanosec ); int Stdin_poll_in___impl( Stdin recv ); #endif diff --git a/lib/standard/time.nit b/lib/standard/time.nit index 6e9c8c0..951d0e8 100644 --- a/lib/standard/time.nit +++ b/lib/standard/time.nit @@ -19,3 +19,8 @@ redef class Object # Unix time: the number of seconds elapsed since January 1, 1970 protected fun get_time: Int is extern "kernel_Any_Any_get_time_0" end + +redef class Sys + # Wait a specific number of second and nanoseconds + fun nanosleep(sec, nanosec: Int) is extern "std_nanosleep" +end diff --git a/lib/standard/time_nit.c b/lib/standard/time_nit.c new file mode 100644 index 0000000..ca025fb --- /dev/null +++ b/lib/standard/time_nit.c @@ -0,0 +1,19 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + * + * Copyright 2008 Floréal Morandat + * + * This file is free software, which comes along with NIT. This software 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. You can modify it is you want, provided this header + * is kept unaltered, and a notification of the changes is added. + * You are allowed to redistribute it and sell it, alone or is a part of + * another product. + */ + +#include "time_nit.h" + +void std_nanosleep_(long sec,long nanosec) { + const struct timespec req = {sec, nanosec}; + nanosleep(&req, NULL); +} diff --git a/lib/standard/time_nit.h b/lib/standard/time_nit.h index 3ecef80..ea4a210 100644 --- a/lib/standard/time_nit.h +++ b/lib/standard/time_nit.h @@ -15,5 +15,6 @@ #include #define kernel_Any_Any_get_time_0(self) time(NULL) - +#define std_nanosleep(self, sec, nanosec) std_nanosleep_(sec, nanosec); +void std_nanosleep_(long sec, long nanosec); #endif