~mysql/mysql-server/mysql-6.0

« back to all changes in this revision

Viewing changes to innobase/thr/ts/tsthr.c

  • Committer: monty at mysql
  • Date: 2001-02-17 12:19:19 UTC
  • mto: (554.1.1)
  • mto: This revision was merged to the branch mainline in revision 556.
  • Revision ID: sp1r-monty@donna.mysql.com-20010217121919-07904
Added Innobase to source distribution

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************
 
2
The test module for the thread management of Innobase
 
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
 
6
Created 10/5/1995 Heikki Tuuri
 
7
*************************************************************************/
 
8
 
 
9
#include "../thr0loc.h"
 
10
#include "sync0sync.h"
 
11
#include "mem0mem.h"
 
12
#include "os0thread.h"
 
13
#include "os0sync.h"
 
14
#include "ut0ut.h"
 
15
 
 
16
ulint           val     = 500;
 
17
os_event_t      event;
 
18
 
 
19
/******************************************************************
 
20
Thread start function in test1. */
 
21
 
 
22
ulint
 
23
thread1(
 
24
/*====*/
 
25
        void*   arg)
 
26
{
 
27
        ulint   n;
 
28
 
 
29
        thr_local_create();
 
30
        
 
31
        n = *((ulint*)arg);
 
32
 
 
33
        printf("Thread %lu starts\n", n);
 
34
 
 
35
        thr_local_set_slot_no(os_thread_get_curr_id(), n);
 
36
 
 
37
        ut_a(n == thr_local_get_slot_no(os_thread_get_curr_id()));
 
38
 
 
39
        os_event_wait(event);
 
40
 
 
41
        thr_local_free();
 
42
 
 
43
        os_thread_exit(0);
 
44
 
 
45
        return(0);
 
46
}
 
47
 
 
48
/******************************************************************
 
49
Test function for local storage. */
 
50
 
 
51
void 
 
52
test1(void)
 
53
/*=======*/
 
54
{
 
55
        os_thread_t             thr1, thr2, thr3, thr4, thr5;
 
56
        os_thread_id_t          id1, id2, id3, id4, id5;
 
57
        ulint                   tm, oldtm;
 
58
        ulint                   n1, n2, n3, n4, n5;
 
59
 
 
60
        printf("-------------------------------------------\n");
 
61
        printf("THR-TEST 1. Test of local storage\n");
 
62
 
 
63
        event = os_event_create(NULL);
 
64
        
 
65
        oldtm = ut_clock();
 
66
 
 
67
        n1 = 1;
 
68
        thr1 = os_thread_create(thread1,
 
69
                                  &n1,
 
70
                                  &id1);
 
71
        n2 = 2;
 
72
        thr2 = os_thread_create(thread1,
 
73
                                  &n2,
 
74
                                  &id2);
 
75
        n3 = 3;
 
76
        thr3 = os_thread_create(thread1,
 
77
                                  &n3,
 
78
                                  &id3);
 
79
        n4 = 4;
 
80
        thr4 = os_thread_create(thread1,
 
81
                                  &n4,
 
82
                                  &id4);
 
83
        n5 = 5;
 
84
        thr5 = os_thread_create(thread1,
 
85
                                  &n5,
 
86
                                  &id5);
 
87
 
 
88
        os_thread_sleep(500000);
 
89
 
 
90
        ut_a(n1 == thr_local_get_slot_no(id1));
 
91
        ut_a(n2 == thr_local_get_slot_no(id2));
 
92
        ut_a(n3 == thr_local_get_slot_no(id3));
 
93
        ut_a(n4 == thr_local_get_slot_no(id4));
 
94
        ut_a(n5 == thr_local_get_slot_no(id5));
 
95
 
 
96
        os_event_set(event);
 
97
 
 
98
        os_thread_wait(thr1);
 
99
        os_thread_wait(thr2);
 
100
        os_thread_wait(thr3);
 
101
        os_thread_wait(thr4);
 
102
        os_thread_wait(thr5);
 
103
 
 
104
        tm = ut_clock();
 
105
        printf("Wall clock time for 5 threads %ld milliseconds\n",
 
106
                        tm - oldtm);
 
107
}
 
108
 
 
109
/************************************************************************
 
110
Main test function. */
 
111
 
 
112
void 
 
113
main(void) 
 
114
/*======*/
 
115
{
 
116
        ulint   tm, oldtm;
 
117
 
 
118
        sync_init();
 
119
        mem_init();
 
120
        thr_local_init();
 
121
 
 
122
        oldtm = ut_clock();
 
123
 
 
124
        test1();
 
125
 
 
126
        thr_local_close();
 
127
        
 
128
        tm = ut_clock();
 
129
        printf("Wall clock time for test %lu milliseconds\n", tm - oldtm);
 
130
        printf("TESTS COMPLETED SUCCESSFULLY!\n");
 
131