sigxcpu.c

00001 #include <unistd.h>
00002 #include <stdlib.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <signal.h>
00006 #include <getopt.h>
00007 #include <execinfo.h>
00008 #include <native/task.h>
00009 
00010 RT_TASK task;
00011 
00012 void task_body (void *cookie)
00013 
00014 {
00015     /* Ask Xenomai to warn us upon switches to secondary mode. */
00016     rt_task_set_mode(0, T_WARNSW, NULL);
00017 
00018     /* A real-time task always starts in primary mode. */
00019 
00020     for (;;) {
00021         rt_task_sleep(1000000000);
00022         /* Running in primary mode... */
00023         printf("Switched to secondary mode\n");
00024         /* ...printf() => write(2): we have just switched to secondary
00025            mode: SIGXCPU should have been sent to us by now. */
00026     }
00027 }
00028 
00029 void warn_upon_switch(int sig __attribute__((unused)))
00030 
00031 {
00032     void *bt[32];
00033     int nentries;
00034 
00035     /* Dump a backtrace of the frame which caused the switch to
00036        secondary mode: */
00037     nentries = backtrace(bt,sizeof(bt) / sizeof(bt[0]));
00038     backtrace_symbols_fd(bt,nentries,fileno(stdout));
00039 }
00040 
00041 int main (int argc, char **argv)
00042 
00043 {
00044     int err;
00045 
00046     signal(SIGXCPU, warn_upon_switch);
00047 
00048     err = rt_task_create(&task,"mytask",0,1,T_FPU);
00049 
00050     if (err)
00051         {
00052         fprintf(stderr,"failed to create task, code %d\n",err);
00053         return 0;
00054         }
00055 
00056     err = rt_task_start(&task,&task_body,NULL);
00057 
00058     if (err)
00059         {
00060         fprintf(stderr,"failed to start task, code %d\n",err);
00061         return 0;
00062         }
00063 
00064     pause();
00065 
00066     return 0;
00067 }

Generated on Mon Mar 24 18:02:40 2008 for Xenomai API by  doxygen 1.5.3