summaryrefslogtreecommitdiff
path: root/innobase/os/ts/tsosaux.c
blob: 8f7780844e911345577ffe76116cecf7189afe80 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/************************************************************************
The test module for the operating system interface
Auxiliary executable run alongside tsos.exe to test
process switching speed

(c) 1995 Innobase Oy

Created 9/27/1995 Heikki Tuuri
*************************************************************************/


#include "../os0thread.h"
#include "../os0shm.h"
#include "../os0proc.h"
#include "ut0ut.h"

/*********************************************************************
Test for shared memory and process switching through yield. */

void 
test2(void)
/*=======*/
{
	os_shm_t		shm;
	ulint			tm, oldtm;
	ulint*			pr_no;
	ulint			count;
	ulint			i;
	
        printf("-------------------------------------------\n");
	printf("OS-TEST 2. Test of process switching through yield\n");


	shm = os_shm_create(1000, "TSOS_SHM");

	pr_no = os_shm_map(shm);

	count = 0;

	printf("Process 2 starts test!\n");
	
	oldtm = ut_clock();

	for (i = 0; i < 100000; i++) {
		if (*pr_no != 2) {
			count++;
			*pr_no = 2;
		}
		os_thread_yield();
	}

	tm = ut_clock();

	printf("Process 2 finishes test: %lu process switches noticed\n",
		count);
	
	printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);


	os_shm_unmap(shm);

	os_shm_free(shm);
}

/************************************************************************
Main test function. */

void 
main(void) 
/*======*/
{
	ulint	tm, oldtm;

	oldtm = ut_clock();

	test2();

	tm = ut_clock();
	printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
	printf("TESTS COMPLETED SUCCESSFULLY!\n");
	
	os_process_exit(0);
}