Subversion Repositories shark

Rev

Rev 1547 | Details | Compare with Previous | 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 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
 *
1547 pj 37
 * CVS :        $Id: semdemo.c,v 1.3 2005-01-08 14:31:38 pj Exp $
1120 pj 38
 
39
 This is a really simple semaphore demo.
40
 
41
*/
42
 
43
#include "kernel/kern.h"
44
 
45
#include "semaphore.h"
46
 
47
sem_t s;
48
 
49
void *goofy(void *a)
50
{
51
  struct timespec t;
52
  char *n = proc_table[exec_shadow].name;
53
 
54
  cprintf("Task %s: Locking semaphore...\n", n);
55
 
56
  sem_wait(&s);
57
  cprintf("Task %s: Semaphore locked...\n", n);
58
 
59
  do {
60
    sys_gettime(&t);
61
  } while (t.tv_sec < (int)a);
62
 
63
  cprintf("Task %s: Unlocking semaphore...\n", n);
64
 
65
  sem_post(&s);
66
 
67
  cprintf("Task %s: Semaphore unlocked...\n", n);
68
 
69
  return 0;
70
}
71
 
72
int main(int argc, char **argv)
73
{
74
  NRT_TASK_MODEL m;
75
  PID p2,p3;
76
 
1377 giacomo 77
  struct timespec t;
78
 
1120 pj 79
  nrt_task_default_model(m);
80
  nrt_task_def_group(m,1);
81
 
82
  nrt_task_def_arg(m,(void *)1);
83
  p2 = task_create("goofy1", goofy, &m, NULL);
84
  if (p2 == NIL)
85
  { cprintf("Can't create goofy1 task...\n"); return 1; }
86
 
87
  nrt_task_def_arg(m,(void *)2);
88
  p3 = task_create("goofy2", goofy, &m, NULL);
89
  if (p3 == NIL)
90
  { cprintf("Can't create goofy2 task...\n"); return 1; }
91
 
92
  cprintf("Initializing semaphore...\n");
93
 
94
  sem_init(&s,0,1);
95
 
96
  group_activate(1);
97
 
1377 giacomo 98
  do {
99
    sys_gettime(&t);
100
  } while (t.tv_sec < 10);
101
 
1547 pj 102
  exit(0);
1377 giacomo 103
 
1120 pj 104
  return 0;
105
}