Rev 1085 | Rev 1450 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /** |
||
20 | ------------ |
||
21 | CVS : $Id: ptest4.c,v 1.1.1.1 2002-09-02 09:37:47 pj Exp $ |
||
22 | |||
23 | File: $File$ |
||
24 | Revision: $Revision: 1.1.1.1 $ |
||
25 | Last update: $Date: 2002-09-02 09:37:47 $ |
||
26 | ------------ |
||
27 | |||
28 | Posix test 4: |
||
29 | |||
30 | the main task create 3 tasks, J1, J2, J3 |
||
31 | at t = 1 sec. it raise a signal to J1 |
||
32 | at t = 2 sec. it kills J2 |
||
33 | |||
34 | J1,J2,J3: it simply calls nanosleep |
||
35 | |||
36 | non standard function used: |
||
37 | cprintf |
||
38 | sys_gettime |
||
39 | keyboard stuffs |
||
40 | sys_end |
||
41 | |||
42 | **/ |
||
43 | |||
44 | /* |
||
45 | * Copyright (C) 2000 Paolo Gai |
||
46 | * |
||
47 | * This program is free software; you can redistribute it and/or modify |
||
48 | * it under the terms of the GNU General Public License as published by |
||
49 | * the Free Software Foundation; either version 2 of the License, or |
||
50 | * (at your option) any later version. |
||
51 | * |
||
52 | * This program is distributed in the hope that it will be useful, |
||
53 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
54 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
55 | * GNU General Public License for more details. |
||
56 | * |
||
57 | * You should have received a copy of the GNU General Public License |
||
58 | * along with this program; if not, write to the Free Software |
||
59 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
60 | * |
||
61 | */ |
||
62 | |||
63 | #include <sys/types.h> |
||
64 | #include <pthread.h> |
||
65 | #include <signal.h> |
||
66 | #include <time.h> |
||
67 | |||
68 | #include <kernel/kern.h> |
||
69 | #include <drivers/keyb.h> |
||
70 | |||
71 | void uscitaJ(void *arg) |
||
72 | { |
||
73 | cprintf("J: (pid=%d) AAAARRRRGGGHHH!!! killed by someone...\n", exec_shadow); |
||
74 | } |
||
75 | |||
76 | void *J(void *arg) |
||
77 | { |
||
78 | struct timespec t1, t2; |
||
79 | int err; |
||
80 | |||
81 | cprintf("J (pid=%d) starts and call nanosleep\n",exec_shadow); |
||
82 | |||
83 | t1.tv_sec = 3; |
||
84 | t1.tv_nsec = 0; |
||
85 | NULL_TIMESPEC(&t2); |
||
86 | pthread_cleanup_push(uscitaJ,NULL); |
||
87 | err = nanosleep(&t1, &t2); |
||
88 | pthread_cleanup_pop(0); |
||
89 | |||
90 | cprintf("J (pid=%d) ending, nanosleep returns errno=%d, t2=%ld.%ld\n", |
||
91 | exec_shadow, err, t2.tv_sec, t2.tv_nsec/1000); |
||
92 | |||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | void signal_handler(int signo, siginfo_t *info, void *extra) |
||
97 | { |
||
98 | cprintf("SIGNAL HANDLER: pid=%d\n",exec_shadow); |
||
99 | } |
||
100 | |||
101 | void fine(KEY_EVT *e) |
||
102 | { |
||
103 | sys_end(); |
||
104 | } |
||
105 | |||
106 | |||
107 | int main(int argc, char **argv) |
||
108 | { |
||
109 | int err; |
||
110 | pthread_t j1, j2, j3; |
||
111 | struct sigaction sig_act; |
||
112 | |||
113 | KEY_EVT emerg; |
||
114 | //keyb_set_map(itaMap); |
||
115 | emerg.ascii = 'x'; |
||
116 | emerg.scan = KEY_X; |
||
117 | emerg.flag = ALTL_BIT; |
||
118 | keyb_hook(emerg,fine); |
||
119 | |||
120 | sig_act.sa_sigaction = (void *) signal_handler; |
||
121 | sig_act.sa_flags = SA_SIGINFO; |
||
122 | sigemptyset(&sig_act.sa_mask); |
||
123 | |||
124 | sigaction(31, &sig_act, NULL); |
||
125 | |||
126 | cprintf("main: creating J1\n"); |
||
127 | err = pthread_create(&j1, NULL, J, NULL); |
||
128 | if (err) cprintf("Error creating J1\n"); |
||
129 | |||
130 | cprintf("main: creating J2\n"); |
||
131 | err = pthread_create(&j2, NULL, J, NULL); |
||
132 | if (err) cprintf("Error creating J2\n"); |
||
133 | |||
134 | cprintf("main: creating J3\n"); |
||
135 | err = pthread_create(&j3, NULL, J, NULL); |
||
136 | if (err) cprintf("Error creating J3\n"); |
||
137 | |||
138 | cprintf("main: waiting 1 sec\n"); |
||
139 | while (sys_gettime(NULL) < 1000000); |
||
140 | |||
141 | cprintf("main: pthread_kill on j1, then wait until t=2 sec \n"); |
||
142 | pthread_kill(j1, 31); |
||
143 | |||
144 | while (sys_gettime(NULL) < 2000000); |
||
145 | cprintf("main: pthread_cancel(J2)\n"); |
||
146 | pthread_cancel(j2); |
||
147 | |||
148 | cprintf("main: ending...\n"); |
||
149 | |||
150 | return 0; |
||
151 | } |