Fix copyright
[yaffs2.git] / direct / test-framework / timothy_tests / threading / threading.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Timothy Manning <timothy@yaffs.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include "threading.h"
14 int random_seed;
15 int simulate_power_failure = 0;
16
17 const struct option long_options[]={
18         {"help",        0,NULL,'h'},
19         {"threads",     1,NULL,'t'}
20 };
21
22 const char short_options[]="ht:";
23
24
25
26
27 void main_init(int argc, char *argv[])
28 {
29         int new_option;
30         int x=0;
31         int new_num_of_threads=5;       
32         x=(unsigned)time(NULL);
33         printf("seeding srand with: %d\n",x);
34         srand(x);
35         do{
36                 new_option=getopt_long(argc,argv,short_options,long_options,NULL);              
37                 if (new_option=='h'){
38                         printf("help\n");
39                         printf("-h will print the commands available\n");
40                         printf("-t [number] sets the number of threads\n");
41                         exit(0);
42                 } else if (new_option=='t') {
43                         new_num_of_threads=atoi(optarg);
44                 }
45         }while (new_option!=-1);
46         number_of_threads(new_num_of_threads);
47         init_counter(new_num_of_threads);
48
49 }
50
51 int main(int argc, char *argv[])
52 {
53         main_init(argc,argv);
54         pthread_t threads[get_num_of_threads()];
55         unsigned int x=0;
56         int output=0;
57         int y=0;
58
59         for (x=0;x<get_num_of_threads();x++)
60         {
61                 
62                 output = pthread_create(&threads[x], NULL,thread_function, (void *)x );
63                 if (output>0){
64                         printf("failed to create thread %d. Error is %d\n",x,output);
65                 }
66                 
67         }
68         while (1){
69                 y=0;
70                 printf("thread counter: %d ",get_counter(y));
71                 for (y=1;y<get_num_of_threads();y++){
72                         printf("| %d ",get_counter(y));
73                 }
74                 printf("\n");
75                 sleep(1);
76         }
77
78 }
79