Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: This is a project specific source file for building the
15 * clock related functions as part of librt library.
25 #include <sys/_timeval.h>
26 #include <sys/types.h>
30 #define UNIX_BASE TTime(MAKE_TINT64(0x00dcddb3,0x0f2f8000)) // 00:00, Jan 1st 1970
32 #define BOUNDARY_CHECK(rqtp) ( (rqtp->tv_nsec != 0 && rqtp->tv_nsec < 1000) || \
33 rqtp->tv_nsec >= 1000000000L )\
37 //Returns the resolution (granularity) of a clock
38 //This value is placed in a (non-NULL) *res
39 EXPORT_C int clock_getres(clockid_t clock_id, struct timespec* res)
42 //We expect the user of the library to give us a valid pointer
45 return 0; //no strict reactions please.
51 //Since Symbian OS is not realtime,we simulate the same using
52 //the available wall clock whose resolution is upto microseconds
59 //For all other clocks that cannot be supported or invalid clockids,
60 //we set errno to not-supported
69 //Allow the calling process to retrieve the value used by a clock which
70 //is specified by clock_id
71 EXPORT_C int clock_gettime (clockid_t clock_id, struct timespec *tp)
75 TTimeIntervalSeconds iSeconds;
77 //We expect the user of the library to give us a valid pointer
87 //Since Symbian OS is not realtime,we simulate the same using
88 //the available wall clock.We use TTime::HomeTime() call to get
91 err = t.SecondsFrom(UNIX_BASE, iSeconds); //TODO check for the negative tests..
94 t-=iSeconds;//extracting seconds info into iSeconds
95 tp->tv_sec = iSeconds.Int();
96 tp->tv_nsec = t.Int64();
102 //For all other clocks that cannot be supported or invalid clockids,
103 //we set errno to invalid
112 //The clock_settime allow the calling process to set the value used by a
113 //clock which is specified by clock_id
114 EXPORT_C int clock_settime (clockid_t clock_id, const struct timespec *tp)
117 TTime t(MAKE_TINT64 (0x00dcddb3 ,0x0f2f8000)) ; // 00:00, Jan 1st 1970
127 //Check for boundary values of seconds and microseconds
128 if (BOUNDARY_CHECK(tp))
137 //We support only the wall-clock,hence use the
138 //User::SetHomeTime call to set the time
139 t+=(TTimeIntervalSeconds)tp->tv_sec;
140 microtime = (tp->tv_nsec)/1000;
141 t+=(TTimeIntervalMicroSeconds)microtime;
142 err = User::SetUTCTime(t);
153 //For all other clocks that cannot be supported or invalid clockids,
154 //we set errno to invalid
164 //Returns the clock ID of the CPU-time clock of the process specified by pid
165 EXPORT_C int clock_getcpuclockid (pid_t pid, clockid_t *clock_id)
175 /* We don't allow any process ID but our own. */
178 //The only available clock is the realtime wall clock
179 //Hence we set the clockid to that
180 *clock_id = CLOCK_REALTIME;
190 //clock_nanosleep will not be interrupted by the signal emulation.
191 //hence EINTR is not valid here.
193 EXPORT_C int clock_nanosleep(clockid_t clock_id, int flags,
194 const struct timespec *rqtp, struct timespec */*rmtp*/)
204 //Check for boundary values of seconds and microseconds
205 if (BOUNDARY_CHECK(rqtp))
219 TTime lSetTime(MAKE_TINT64 (0x00dcddb3 ,0x0f2f8000)) ; // 00:00, Jan 1st 1970
221 lSetTime+=(TTimeIntervalSeconds)rqtp->tv_sec;
222 lSetTime+=(TTimeIntervalMicroSeconds)(rqtp->tv_nsec/1000);
230 unsigned long timeout;
231 timeout = (1000000 * rqtp->tv_sec) + (rqtp->tv_nsec /1000);
232 User::AfterHighRes(timeout);
241 //For all other clocks that cannot be supported or invalid clockids,
242 //we set errno to invalid