Subversion Repositories shark

Rev

Rev 1377 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1120 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
 * Copyright (C) 2000 Giorgio Buttazzo, Paolo Gai
21
 *
22
 * This program is free software; you can redistribute it and/or modify
23
 * it under the terms of the GNU General Public License as published by
24
 * the Free Software Foundation; either version 2 of the License, or
25
 * (at your option) any later version.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
 * GNU General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU General Public License
33
 * along with this program; if not, write to the Free Software
34
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
35
 *
36
 *
37
 * CVS :        $Id: intsem.c,v 1.1 2002-11-11 08:22:45 pj Exp $
38
 
39
 this test is a simple main() function with one other task.
40
 
41
 This test verify the correctness of the internal_sem functions.
42
 
43
*/
44
 
45
#include "kernel/kern.h"
46
 
47
#include <kernel/int_sem.h>
48
 
49
internal_sem_t s;
50
 
51
TASK pippo(void *a)
52
{
53
  int i=0;
54
  struct timespec t;
55
 
56
  do {
57
    sys_gettime(&t);
58
 
59
    if (i==0 && t.tv_sec == (int)a) {
60
      i = 1;
61
      cprintf("before internal_sem_wait %d\n",(int)a);
62
      internal_sem_wait(&s);
63
      cprintf("after internal_sem_wait %d\n",(int)a);
64
    }
65
 
66
    if (i==1 && t.tv_sec == 2+(int)a) {
67
      i = 2;
68
      cprintf("before internal_sem_post %d\n",(int)a);
69
      internal_sem_post(&s);
70
      cprintf("after internal_sem_post %d\n",(int)a);
71
      return 0;
72
    }
73
 
74
 
75
  } while (1);
76
}
77
 
78
int main(int argc, char **argv)
79
{
80
  NRT_TASK_MODEL m;
81
  PID p2,p3;
82
 
83
  nrt_task_default_model(m);
84
  nrt_task_def_group(m,1);
85
 
86
  nrt_task_def_arg(m,(void *)1);
87
  p2 = task_create("pippo1", pippo, &m, NULL);
88
  if (p2 == NIL)
89
  { cprintf("Can't create pippo1 task...\n"); return 1; }
90
 
91
  nrt_task_def_arg(m,(void *)2);
92
  p3 = task_create("pippo2", pippo, &m, NULL);
93
  if (p3 == NIL)
94
  { cprintf("Can't create pippo2 task...\n"); return 1; }
95
 
96
  internal_sem_init(&s,1);
97
 
98
  group_activate(1);
99
 
100
  return 0;
101
}