summaryrefslogtreecommitdiff
path: root/src/SWDRAW/cpulimit.pc
blob: 5867615c6e6a283c0e928bca516a97379d7037ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifdef WNT

#include <windows.h>
#include <winbase.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

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.) 


static unsigned int __stdcall CpuFunc(void * param) {  

	clock_t current;

    while ( 1 ) {
		Sleep(5);
	    
		current = clock()/1000;
        if ((current-MDTV_CPU_CURRENT) >= MDTV_CPU_LIMIT ){ 
   		  
			printf("CpuFunc : Fin sur Cpu Limit \n");
            ExitProcess(2);
			return(0);
		}
	}
	return(0);
} 

//static Standard_Integer cpulimit(Draw_Interpretor& DI, Standard_Integer n, char** a)
void limitelapsed(int n ) {
	
	static int first=1;

	unsigned int __stdcall CpuFunc(void * );

	unsigned ThreadID;

	MDTV_CPU_LIMIT = n;
	MDTV_CPU_CURRENT = clock()/1000;
  

    if (first) { // Lancer le thread au 1er appel seulement.
        first=0;
		_beginthreadex(

			NULL,                        // no security attributes 
			0,                           // use default stack size  
			CpuFunc,				     // thread function
			NULL,            // argument to thread function
			0,                           // use default creation flags 
			&ThreadID);                  // returns the thread identifier
	}
		
}
#endif