Debian Codegraph @

gcc/testsuite/gm2/pimcoroutines/run/pass/testtime.mod

raw
1 (* Copyright (C) 2005-2022
2 Free Software Foundation, Inc. *)
3 (* This file is part of GNU Modula-2.
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *)
18
19 MODULE testtime ;
20
21
22 FROM Debug IMPORT Halt ;
23 FROM StdIO IMPORT PushOutput ;
24 FROM StrIO IMPORT WriteString, WriteLn ;
25 FROM TimerHandler IMPORT EVENT, TicksPerSecond, Sleep, ArmEvent,
26 Cancel, WaitOn, ReArmEvent ;
27 FROM SYSTEM IMPORT TurnInterrupts ;
28 FROM COROUTINES IMPORT PROTECTION ;
29 FROM Executive IMPORT DESCRIPTOR, InitProcess, Resume, Ps ;
30 FROM SYSTEM IMPORT ADR ;
31 FROM libc IMPORT write, printf ;
32
33
34 CONST
35 TicksPerTimeUnit = 1 ;
36
37
38 (*
39 OneUnit -
40 *)
41
42 PROCEDURE OneUnit ;
43 VAR
44 n: CARDINAL ;
45 BEGIN
46 OldInts := TurnInterrupts (MIN (PROTECTION)) ;
47 printf ("1 unit process has come to life\n");
48 n := 0 ;
49 LOOP
50 Sleep (1*TicksPerTimeUnit) ;
51 INC (n) ;
52 printf ("%d units\n", n);
53 END
54 END OneUnit ;
55
56
57 (*
58 FourUnits -
59 *)
60
61 PROCEDURE FourUnits ;
62 VAR
63 n: CARDINAL ;
64 BEGIN
65 OldInts := TurnInterrupts (MIN (PROTECTION)) ;
66 printf ("4 units process has come to life\n");
67 n := 0 ;
68 LOOP
69 Sleep (4*TicksPerTimeUnit) ;
70 INC (n) ;
71 printf ("4 units alarm (%d occurance)\n", n);
72 END
73 END FourUnits ;
74
75
76 (*
77 SixUnits -
78 *)
79
80 PROCEDURE SixUnits ;
81 VAR
82 n: CARDINAL ;
83 BEGIN
84 OldInts := TurnInterrupts (MAX (PROTECTION)) ;
85 printf ("6 units process has come to life\n");
86 n := 0 ;
87 LOOP
88 Timeout := ArmEvent (6*TicksPerSecond) ;
89 IF WaitOn (Timeout)
90 THEN
91 WriteString ('...someone cancelled it...')
92 ELSE
93 INC (n) ;
94 printf ("6 unit alarm (%d occurance)\n", n)
95 END
96 END
97 END SixUnits ;
98
99
100 CONST
101 StackSize = 0100000H ;
102
103 VAR
104 p1, p4,
105 p6 : DESCRIPTOR ;
106 OldInts : PROTECTION ;
107 Timeout : EVENT ;
108 BEGIN
109 OldInts := TurnInterrupts (MIN (PROTECTION)) ;
110 printf ("got to OS\n") ;
111
112 printf ("now to create three processes...\n") ;
113
114 p1 := Resume (InitProcess (OneUnit , StackSize, '1')) ;
115 p4 := Resume (InitProcess (FourUnits, StackSize, '4')) ;
116 p6 := Resume (InitProcess (SixUnits , StackSize, '6')) ;
117
118 Sleep (20*TicksPerTimeUnit) ;
119 printf ("successfully completed, finishing now.\n")
120 END testtime.