diff --git a/src/Draw/Draw_BasicCommands.cxx b/src/Draw/Draw_BasicCommands.cxx index 01794fe165..d2db55a3c1 100755 --- a/src/Draw/Draw_BasicCommands.cxx +++ b/src/Draw/Draw_BasicCommands.cxx @@ -25,19 +25,46 @@ #include #include +#include #include #include #include + #include +#include +#include #include #include +#ifdef _WIN32 + +#include +#include +#include +#include +#include +#include +#include + +#define RLIM_INFINITY 0x7fffffff + +static clock_t CPU_CURRENT; // cpu time already used at last + // cpulimit call. (sec.) + +#else /* _WIN32 */ + +#include + #ifdef HAVE_CONFIG_H # include #endif -#if defined(HAVE_TIME_H) || defined(WNT) +#ifdef HAVE_STRINGS_H +# include +#endif + +#if defined(HAVE_TIME_H) # include #endif @@ -45,46 +72,20 @@ # include #endif -#ifndef WNT -# include -# ifdef HAVE_STRINGS_H -# include -# endif -#else -//WNT -extern Standard_Boolean Draw_Batch; -#include -#include -#include -#include -#include -#ifdef HAVE_LIMITS -# include -#elif defined (HAVE_LIMITS_H) -# include +#ifdef HAVE_SYS_SIGNAL_H +# include #endif -#ifdef WNT -# include -#endif - -static clock_t MDTV_CPU_LIMIT; // Cpu_limit in Sec. -static clock_t MDTV_CPU_CURRENT; // cpu time already used at last - // cpulimit call. (sec.) -//#define strcasecmp strcmp Already defined -#define RLIM_INFINITY 0x7fffffff -#endif - -#include -#include -#include - #if defined (__hpux) || defined ( HPUX ) #define RLIM_INFINITY 0x7fffffff #define RLIMIT_CPU 0 #endif +#endif /* _WIN32 */ +extern Standard_Boolean Draw_Batch; + +static clock_t CPU_LIMIT; // Cpu_limit in Sec. //======================================================================= // chronom @@ -400,7 +401,7 @@ static Standard_Integer Draw_wait(Draw_Interpretor& , Standard_Integer n, const //function : cpulimit //purpose : //======================================================================= -#ifdef WNT +#ifdef _WIN32 static unsigned int __stdcall CpuFunc (void * param) { clock_t aCurrent; @@ -411,47 +412,41 @@ static unsigned int __stdcall CpuFunc (void * param) OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds); aCurrent = clock_t(anUserSeconds + aSystemSeconds); - if ((aCurrent - MDTV_CPU_CURRENT) >= MDTV_CPU_LIMIT) + if ((aCurrent - CPU_CURRENT) >= CPU_LIMIT) { - printf ("CpuFunc : Fin sur Cpu Limit \n"); + cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl; ExitProcess (2); return 0; } } return 0; } +#else +static void CpuFunc (int) +{ + cout << "Process killed by CPU limit (" << CPU_LIMIT << " sec)" << endl; + exit(2); +} #endif static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const char** a) { -#ifndef WNT - rlimit rlp; - rlp.rlim_max = RLIM_INFINITY; - if (n <= 1) - rlp.rlim_cur = RLIM_INFINITY; - else - rlp.rlim_cur = atoi(a[1]); +#ifdef _WIN32 + // Windows specific code - int status; - status=setrlimit(RLIMIT_CPU,&rlp); - if (status !=0) - di << "status cpulimit setrlimit : " << status << "\n"; - -#else -//WNT static int aFirst = 1; unsigned int __stdcall CpuFunc (void *); unsigned aThreadID; if (n <= 1) - MDTV_CPU_LIMIT = RLIM_INFINITY; + CPU_LIMIT = RLIM_INFINITY; else { - MDTV_CPU_LIMIT = atoi (a[1]); + CPU_LIMIT = atoi (a[1]); Standard_Real anUserSeconds, aSystemSeconds; OSD_Chronometer::GetProcessCPU (anUserSeconds, aSystemSeconds); - MDTV_CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds); + CPU_CURRENT = clock_t(anUserSeconds + aSystemSeconds); if (aFirst) // Launch the thread only at the 1st call. { @@ -460,6 +455,29 @@ static Standard_Integer cpulimit(Draw_Interpretor& di, Standard_Integer n, const } } +#else + + // Unix & Linux + + rlimit rlp; + rlp.rlim_max = RLIM_INFINITY; + if (n <= 1) + rlp.rlim_cur = RLIM_INFINITY; + else + rlp.rlim_cur = atoi(a[1]); + CPU_LIMIT = rlp.rlim_cur; + + int status; + status=setrlimit(RLIMIT_CPU,&rlp); + if (status !=0) + di << "status cpulimit setrlimit : " << status << "\n"; + + // set signal handler to print a message before death + struct sigaction act, oact; + memset (&act, 0, sizeof(act)); + act.sa_handler = CpuFunc; + sigaction (SIGXCPU, &act, &oact); + #endif return 0; diff --git a/tests/boolean/bsection/N4 b/tests/boolean/bsection/N4 index 2f77a9a32d..49b8b0a7da 100644 --- a/tests/boolean/bsection/N4 +++ b/tests/boolean/bsection/N4 @@ -1,4 +1,4 @@ -cpulimit 1000 +cpulimit 2000 restore [locate_data_file lh3d_px2.brep] a compound result diff --git a/tests/bugs/moddata/bug54 b/tests/bugs/moddata/bug54 index d21dc13b9b..9e72bb6134 100755 --- a/tests/bugs/moddata/bug54 +++ b/tests/bugs/moddata/bug54 @@ -13,9 +13,7 @@ puts "" ## Exception is raised during command "small" in DRAW on attached shape. #################################################### -#cpulimit 9000 -# true CPU limit! cpulimit 2000 -cpulimit 100 +cpulimit 300 restore [locate_data_file OCC54.brep] result puts [checkshape result]