From 21c068f1916330e90f814bed461fe0821d1665ec Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 9 Oct 2011 16:36:37 +0000 Subject: checked in pd-0.43-0.src.tar.gz svn path=/trunk/; revision=15557 --- pd/src/x_misc.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'pd/src/x_misc.c') diff --git a/pd/src/x_misc.c b/pd/src/x_misc.c index 2d7860d9..13090f0d 100644 --- a/pd/src/x_misc.c +++ b/pd/src/x_misc.c @@ -9,24 +9,28 @@ #include #include #include -#ifdef HAVE_UNISTD_H +#ifdef _WIN32 +#include +#include +#else #include #include #include #include #include -#endif -#ifdef MSW -#include -#include -#endif +#endif /* _WIN32 */ #if defined (__APPLE__) || defined (__FreeBSD__) #define CLOCKHZ CLK_TCK #endif -#if defined (__linux__) +#if defined (__linux__) || defined (__CYGWIN__) || defined (ANDROID) #define CLOCKHZ sysconf(_SC_CLK_TCK) #endif +#if defined (__FreeBSD_kernel__) || defined(__GNU__) +#include +#define CLOCKHZ CLOCKS_PER_SEC +#endif + /* -------------------------- random ------------------------------ */ /* this is strictly homebrew and untested. */ @@ -145,7 +149,7 @@ static void namecanvas_setup(void) sizeof(t_namecanvas), CLASS_NOINLET, A_DEFSYM, 0); } -/* ---------------serial ports (MSW only -- hack) ------------------------- */ +/* ---------------serial ports (_WIN32 only -- hack) ------------------------- */ #define MAXSERIAL 100 static t_class *serial_class; @@ -194,22 +198,18 @@ static t_class *cputime_class; typedef struct _cputime { t_object x_obj; -#ifdef HAVE_UNISTD_H - struct tms x_setcputime; -#endif -#ifdef MSW +#ifdef _WIN32 LARGE_INTEGER x_kerneltime; LARGE_INTEGER x_usertime; int x_warned; -#endif +#else + struct tms x_setcputime; +#endif /* _WIN32 */ } t_cputime; static void cputime_bang(t_cputime *x) { -#ifdef HAVE_UNISTD_H - times(&x->x_setcputime); -#endif -#ifdef MSW +#ifdef _WIN32 FILETIME ignorethis, ignorethat; BOOL retval; retval = GetProcessTimes(GetCurrentProcess(), &ignorethis, &ignorethat, @@ -222,12 +222,14 @@ static void cputime_bang(t_cputime *x) x->x_kerneltime.QuadPart = 0; x->x_usertime.QuadPart = 0; } -#endif +#else + times(&x->x_setcputime); +#endif /* _WIN32 */ } static void cputime_bang2(t_cputime *x) { -#ifdef HAVE_UNISTD_H +#ifndef _WIN32 t_float elapsedcpu; struct tms newcputime; times(&newcputime); @@ -235,8 +237,7 @@ static void cputime_bang2(t_cputime *x) newcputime.tms_utime + newcputime.tms_stime - x->x_setcputime.tms_utime - x->x_setcputime.tms_stime) / CLOCKHZ; outlet_float(x->x_obj.ob_outlet, elapsedcpu); -#endif -#ifdef MSW +#else t_float elapsedcpu; FILETIME ignorethis, ignorethat; LARGE_INTEGER usertime, kerneltime; @@ -250,7 +251,7 @@ static void cputime_bang2(t_cputime *x) (usertime.QuadPart - x->x_usertime.QuadPart)); else elapsedcpu = 0; outlet_float(x->x_obj.ob_outlet, elapsedcpu); -#endif +#endif /* NOT _WIN32 */ } static void *cputime_new(void) @@ -259,7 +260,7 @@ static void *cputime_new(void) outlet_new(&x->x_obj, gensym("float")); inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("bang"), gensym("bang2")); -#ifdef MSW +#ifdef _WIN32 x->x_warned = 0; #endif cputime_bang(x); -- cgit v1.2.1