Top Forums Programming How use pthread_cond_timedwait without clock_gettime? Post 302358787 by fcolombo on Sunday 4th of October 2009 05:48:26 PM
Old 10-04-2009
How use pthread_cond_timedwait without clock_gettime?

I need to use pthread_cond_timedwait, which is available in my old embedded Linux for PPC. But I don't have clock_gettime... So, I build this replacement for clock_gettime, and it seems to work:

#include <sys/time.h>
#include <time.h>

int clock_gettime_replacement(struct timespec *now) {
    return clock_gettime(CLOCK_REALTIME, now);
    now->tv_sec = time(NULL);
    struct timeval tv;
    gettimeofday(&tv, NULL);
    now->tv_nsec = tv.tv_usec * 1000;
    return 0;

But I'm afraid of issues related with daylight saving and timezone. Do you know where I can get sources of clock_gettime, so I can build it on my own using other system calls?

2 More Discussions You Might Find Interesting

1. Programming

undefined symbol: clock_gettime' error

Hi, i've compiled my app on x86_64 with -m32 gcc option. Can anybody tell me what is/would typically cause the 'undefined symbol: clock_gettime' error?? -1 k){0N!x y} '/home/da71336/simon/mkvfh/ undefined symbol: clock_gettime @ "q" "subr:mkv 2:`subr,3; subc:mkv 2:`subc,1;... (4 Replies)
Discussion started by: dpa078
4 Replies

2. Programming

pthread_cond_timedwait relocks forever

looking in pthread's source code I can see that as an epilogue both pthread_cond_timedwait and pthread_cond_wait will try to relock the mutex by means of __pthread_mutex_cond_lock. Does this mean that any of them both could eventually block forever if the mutex is never again available after... (4 Replies)
Discussion started by: ramestica
4 Replies
clock_settime(3RT)					    Realtime Library Functions						clock_settime(3RT)

clock_settime, clock_gettime, clock_getres - high-resolution clock operations SYNOPSIS
cc [ flag... ] file... -lrt [ library... ] #include <time.h> int clock_settime(clockid_t clock_id, const struct timespec *tp); int clock_gettime(clockid_t clock_id, struct timespec *tp); int clock_getres(clockid_t clock_id, struct timespec *res); DESCRIPTION
The clock_settime() function sets the specified clock, clock_id, to the value specified by tp. Time values that are between two consecutive non-negative integer multiples of the resolution of the specified clock are truncated down to the smaller multiple of the resolution. The clock_gettime() function returns the current value tp for the specified clock, clock_id. The resolution of any clock can be obtained by calling clock_getres(). Clock resolutions are system-dependent and cannot be set by a process. If the argument res is not NULL, the resolution of the specified clock is stored in the location pointed to by res. If res is NULL, the clock resolution is not returned. If the time argument of clock_settime() is not a multiple of res, then the value is truncated to a multiple of res. A clock may be systemwide (that is, visible to all processes) or per-process (measuring time that is meaningful only within a process). A clock_id of CLOCK_REALTIME is defined in <time.h>. This clock represents the realtime clock for the system. For this clock, the values returned by clock_gettime() and specified by clock_settime() represent the amount of time (in seconds and nanoseconds) since the Epoch. Additional clocks may also be supported. The interpretation of time values for these clocks is unspecified. A clock_id of CLOCK_HIGHRES represents the non-adjustable, high-resolution clock for the system. For this clock, the value returned by clock_gettime(3RT) represents the amount of time (in seconds and nanoseconds) since some arbitrary time in the past; it is not correlated in any way to the time of day, and thus is not subject to resetting or drifting by way of adjtime(2), ntp_adjtime(2), settimeofday(3C), or clock_settime(). The time source for this clock is the same as that for gethrtime(3C). Additional clocks may also be supported. The interpretation of time values for these clocks is unspecified. RETURN VALUES
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
The clock_settime(), clock_gettime() and clock_getres() functions will fail if: EINVAL The clock_id argument does not specify a known clock. ENOSYS The functions clock_settime(), clock_gettime(), and clock_getres() are not supported by this implementation. The clock_settime() function will fail if: EINVAL The tp argument to clock_settime() is outside the range for the given clock ID; or the tp argument specified a nanosecond value less than zero or greater than or equal to 1000 million. The clock_settime() function may fail if: EPERM The requesting process does not have the appropriate privilege to set the specified clock. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-------------------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-------------------------------------+ |Interface Stability |Standard | +-----------------------------+-------------------------------------+ |MT-Level |clock_gettime() is Async-Signal-Safe | +-----------------------------+-------------------------------------+ SEE ALSO
time(2), ctime(3C), gethrtime(3C), time.h(3HEAD), timer_gettime(3RT), attributes(5), standards(5) SunOS 5.10 28 Jun 2002 clock_settime(3RT)

Featured Tech Videos

All times are GMT -4. The time now is 08:01 PM.
Unix & Linux Forums Content Copyright 1993-2021. All Rights Reserved.
Privacy Policy