public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* How to use CLOCK_REALTIME_ALARM
@ 2011-08-29 21:13 fogobogo
  0 siblings, 0 replies; only message in thread
From: fogobogo @ 2011-08-29 21:13 UTC (permalink / raw)
  To: linux-kernel

Hi!

Since alarmtimers have been mainlined there are now 2 new clock id's, 
CLOCK_REALTIME_ALARM and CLOCK_BOOTTIME_ALARM which are supposed to wake 
up a machine from suspend too. It's roughly outlined here:

http://lwn.net/Articles/429925/

Now me residing in userspace wonder how to use those. It's the first 
time I try to use a kernel interface and it is quite possible the 
problem is on my end but I have no clue what might be wrong. Here is 
some barely working code:

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>

void
func()
{
     printf("pong.\n");
}

int
main(int argc, char *argv[])
{
     timer_t id;

     struct itimerspec A;
     struct sigevent se;

     int rc; /* return code */

     se.sigev_notify = SIGEV_THREAD;
     se.sigev_notify_function = func;
     se.sigev_notify_attributes = NULL;

     /* doesn't accept CLOCK_REALTIME_ALARM */
     rc = timer_create(CLOCK_REALTIME, &se, &id);
     printf("%d\n",rc);

     /* the only place that seems to actually accept it */
     clock_gettime(CLOCK_REALTIME_ALARM, &A.it_value);

     A.it_value.tv_sec += 10;

     A.it_interval.tv_sec = 0;
     A.it_interval.tv_nsec = 0;

     /* set timer */
     rc = timer_settime(&id, TIMER_ABSTIME, &A, 0);
     printf("%d\n",rc);

     printf("ping.\n");

     /* bad. bad. bad. */
     while(1);

     return 0;
}

I'd appreciate if someone could point me on what I'm doing wrong or tell 
me if the new clock id's work at all.

please CC answers. thanks in advance.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-08-29 21:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-29 21:13 How to use CLOCK_REALTIME_ALARM fogobogo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox