Sponsored Content
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:

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

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

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/mkv.so: 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(2)					      BSD System Calls Manual						  CLOCK_SETTIME(2)

NAME
clock_settime, clock_gettime, clock_getres -- clock and timer functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#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 clock identified by clock_id to the absolute time specified by tp. If the time specified by tp is not a multiple of the resolution of the clock, tp is truncated to a multiple of the resolution. The clock_gettime() function stores the time of the clock identified by clock_id into the location specified by tp. The clock_getres() function stores the resolution of the clock identified by clock_id into the location specified by res, unless res is NULL. A clock_id of CLOCK_REALTIME identifies the realtime clock for the system. For this clock, the values specified by clock_settime() and obtained by clock_gettime() represent the amount of time (in seconds and nanoseconds) since 00:00 Universal Coordinated Time, January 1, 1970. A clock_id of CLOCK_MONOTONIC identifies a clock that increases at a steady rate (monotonically). This clock is not affected by calls to adjtime(2) and settimeofday(2) and will fail with an EINVAL error if it's the clock specified in a call to clock_settime(). The origin of the clock is unspecified. If the calling user is not the super-user, then the clock_settime() function in the standard C library will try to use the clockctl(4) device if present, thus making possible for non privileged users to set the system time. If clockctl(4) is not present or not accessible, then clock_settime() reverts to the clock_settime() system call, which is restricted to the super user. RETURN VALUES
A value of 0 is returned on success. Otherwise, a value of -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 function is not supported by this implementation. The clock_settime() function will fail if: [EINVAL] The tp argument is outside the range for the specified clock, clock_id. [EINVAL] The tp argument specified a nanosecond value less than zero of greater than or equal 1000 million. [EINVAL] The clock_id argument is a clock that can not be adjusted. [EPERM] The calling process does not have the appropriate privilege to set the specified clock, clock_id. The clock_gettime() function will fail if: [EFAULT] The tp argument specifies an address that is not a valid part of the process address space. SEE ALSO
ctime(3), time(3), clockctl(4) STANDARDS
The clock_settime(), clock_gettime() and clock_getres() functions conform to IEEE Std 1003.1b-1993 (``POSIX.1''). BSD
February 11, 1999 BSD
All times are GMT -4. The time now is 03:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy