remove unecessary lock (ARMI_AffinityMask is updated while startup_lock is held)
[AROS.git] / test / oop2 / timerclass.c
blob149f100383368b1ad07c7ebf52a381593858216c
1 /*
2 Copyright © 1997-98, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo of new OOP system
6 Lang: english
7 */
9 #include <sys/time.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include "oop.h"
13 #include "protos.h"
14 #include "timerclass.h"
16 struct TimerData
18 struct timeval start_time;
19 struct timeval elapsed_time;
22 /* Does dest - src => dest */
23 VOID SubTime(struct timeval *dest, struct timeval *src)
25 /* Normalize the terms */
26 while(src->tv_usec > 999999)
28 src->tv_sec++;
29 src->tv_usec -= 1000000;
31 while(dest->tv_usec > 999999)
33 dest->tv_sec++;
34 dest->tv_usec -= 1000000;
37 dest->tv_usec -= src->tv_usec;
38 dest->tv_sec -= src->tv_sec;
40 if(dest->tv_usec < 0)
42 dest->tv_usec += 1000000;
43 dest->tv_sec--;
46 return;
49 VOID _Timer_Start(Class *cl, Object *o, Msg msg)
51 struct TimerData *data = INST_DATA(cl, o);
52 gettimeofday(&(data->start_time), NULL);
53 return;
56 VOID _Timer_Stop(Class *cl, Object *o, Msg msg)
58 struct TimerData *data = INST_DATA(cl, o);
59 gettimeofday(&(data->elapsed_time), NULL);
61 SubTime(&(data->elapsed_time), &(data->start_time));
63 return;
66 VOID _Timer_PrintElapsed(Class *cl, Object *o, Msg msg)
68 struct TimerData *data = INST_DATA(cl, o);
70 printf("%d secs and %d micros\n"
71 ,data->elapsed_time.tv_sec
72 ,data->elapsed_time.tv_usec);
76 IPTR _Timer_TestMethod(Class *cl, Msg msg)
78 return (12345678);
82 Class *MakeTimerClass()
84 APTR methods[] =
86 NULL,
87 NULL,
88 _Timer_Start,
89 _Timer_Stop,
90 _Timer_PrintElapsed,
91 _Timer_TestMethod
93 Class *cl;
95 cl = MakeClass(TIMERCLASS, ROOTCLASS, methods, sizeof (struct TimerData), NUM_TIMER_METHODS);
96 if (cl)
98 AddClass(cl);
101 return (cl);
104 VOID FreeTimerClass(Class *cl)
106 RemoveClass(cl);
107 FreeClass(cl);