Hello,
I am trying to get the thread (timing) to wait for the signal (SIGRTMIN). It
is not receiving the signal. When sigwait is moved to the main thread, the
signal is received. The program uses POSIX wrappers.
How can I get the timing thread to receive the signal?
Also, in an article, it stated "any application linking against libcobalt has
its main thread attached to the real-time system automatically". When a thread
is created from the main, will that thread be in the primary or secondary mode?
Below is an example of the program.
The system is setup with:
Ubuntu 14.04 LTS
vanilla kernel linux 3.14.33
ipipe-core-3.14.33-x86-8.patch
xenomai-3.0-rc4
Build args: --with-core=cobalt --enable-smp --enable-pshared
--host=x86_64-linux host_alias=x86_64-linux
Thanks for your help with my previous signal issue.
Tony
-------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sched.h>
#include <sys/types.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include "/usr/xenomai/include/cobalt/wrappers.h"
short fexit_t1=0, fexit_mon=0;
timer_t timer_id;
timer_t * __restrict__ timer_id_rptr;
struct sigaction act, oact, act1, oact1;
struct tm gmt;
/* Timer variables */
struct sigaction sa;
sigset_t allsigs;
struct itimerspec tmr_setting;
/* Define threads and attributes
*********************************/
pthread_t tidp0; /* main */
pthread_t tidp1; /* timing */
pthread_attr_t attr1;
/* Semaphores for threads
******************************/
char *bs30_path = "/bsem30"; /* main */
int bsfd30;
sem_t *main_semaphore;
int status=0;
/* Thread Entries */
extern void timing();
int gfos;
/* Thread functions */
#include "thrds2.c"
/* Routine that is called when timer expires */
void timer_intr(int sig, siginfo_t *extra, void *cruft) {
int value=0;
sem_post(timing_semaphore);
if (sem_getvalue(timing_semaphore,&value) < 0)
printf("Error with sem getvalue\n"); }
/***********************************************************************/
void kill_handler( int sig)
{
if (sig == SIGCHLD)
{
printf("CHILD Signal captured !!!\n");
}else{
printf("%s\n","program killed\n");
fexit_mon = 1;
}
printf("fexit mon set in kill handler\n");
fflush(stdout);
}
int main()
{
int pid, tc;
char msg[120];
/* Timer variables */
struct sigaction sa;
struct sigevent sig_spec;
struct sigevent * __restrict__ sig_spec_rptr;
sigset_t allsigs;
struct itimerspec tmr_setting;
struct itimerspec * __restrict__ tmr_setting_rptr;
struct itimerspec *tmr_value;
struct sched_param schedule_parameter;
/* Setup error handler parameters */
act1.sa_handler = kill_handler;
if(sigemptyset(&act1.sa_mask) == -1) {
perror("sigemptyset");
exit(EXIT_FAILURE);
}
act1.sa_flags = 0;
if(sigaction(SIGINT, &act1, &oact1) == -1) {
perror("sigaction");
exit(EXIT_FAILURE);
}
/* create mask */
if (sigemptyset(&allsigs) < 0)
printf("sigemptyset error\n");
sigaddset(&allsigs, SIGRTMIN);
/* Create the threads */
add_thread("timing",timing);
/* Thread start */
if (start_thrd("timing"))
{
printf("Cannot start Timing Thread!");
exit(0);
}
/* Setup main & Thread Priorities */
schedule_parameter.sched_priority = 17;
if(pthread_setschedparam(tidp0, SCHED_FIFO,
&schedule_parameter) == -1) {
printf("Error setting scheduler policy. Program Terminated");
perror(" Scheduler problem");
exit(-1);
}
/* setup signal to respond to timer */
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = timer_intr;
if ( sigaction(SIGRTMIN, &sa, NULL) < 0 )
{
perror("sigaction");
printf("Timer signal setup failed");
exit(0);
}
sig_spec.sigev_notify = SIGEV_THREAD_ID;
sig_spec.sigev_signo = SIGRTMIN;
sig_spec.sigev_notify_thread_id = getpid();
sig_spec.sigev_value.sival_ptr = &timer_id;
/* create timer, which uses the REALTIME clock */
timer_id_rptr = &timer_id;
sig_spec_rptr = &sig_spec;
if ((timer_create(CLOCK_REALTIME,sig_spec_rptr,timer_id_rptr)) < 0 )
{
perror("timer create");
printf("Error creating timer\n");
exit(0);
}
tmr_setting.it_value.tv_sec = 0;
tmr_setting.it_value.tv_nsec = 50000000;
tmr_setting.it_interval.tv_sec = 0;
tmr_setting.it_interval.tv_nsec = 50000000;
tmr_setting_rptr = &tmr_setting;
if (timer_settime(timer_id,0,tmr_setting_rptr,NULL) < 0 ) {
perror("settimer");
printf("Error setting timer parameters");
exit(0);
}
printf("timer SET\n");
fflush(stdout);
/* Main loop */
while (1) {
if (sem_wait(main_semaphore) == -1)
{
perror("main semaphore error:: ");
exit(0);
}
***
}
}
if(fexit_mon == 1) {
printf("\nPROGRAM TERMINATION COMMENSING!!!\n");
***
exit(0);
}else{
sched_yield();
}
}
printf("Done.\n");
exit(0);
}
/* timing process */
void timing()
{
int sig;
change_priority("timing",45);
while (1)
{
/* Wait for SIGRTMIN */
if ((sigwait(&sigm, &sig) > ))
{
pritnf("Sigwait error\n");
perror("sigwait: ");
}
***
}
}
}
_______________________________________________
Xenomai mailing list
[email protected]
http://xenomai.org/mailman/listinfo/xenomai