Clock in POSIX API
Richard M. Barry
R.Barry at sstl.co.uk
Mon Mar 1 14:59:25 UTC 2004
I want to use the time of day in my (POSIX) application. So I need to set the realtime clock in the beginning of my application. I do this with a call to clock_settime(), but it returns with an error (errno==EINVAL). I can't figure out why, any ideas? I'm guessing it's some #define or #include that I left out, but I have no idea what. Part of the code follows:
#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
#define CONFIGURE_MAXIMUM_POSIX_THREADS 5
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 20
#define CONFIGURE_MAXIMUM_POSIX_MESSAGE_QUEUES 20
#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 20
#define CONFIGURE_POSIX_INIT_THREAD_TABLE
#define CONFIGURE_MAXIMUM_POSIX_TIMERS 4
#include <time.h>
#include <sys/features.h>
#include <errno.h>
...
#ifndef _POSIX_TIMERS
#error "rtems is supposed to have clock_settime"
#endif
...
void *POSIX_Init( void *argument )
{
struct timespec tim;
time_t *now;
tim.tv_sec = 10000; // Just a number, can be anything for what I care
tim.tv_nsec = 0;
status = clock_settime( CLOCK_REALTIME,&tim );
if(status==-1)
{
printf("INIT: errno=%d , EINVAL=%d\n",errno,EINVAL);
}
assert(!status);
...
Thanks,
Richard
More information about the users
mailing list