LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-19-2009, 09:40 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Rep: Reputation: 32
Doubts abous how to handle timers in linux.


Hello,

I have a shared library that I create functions to use timers. In this functions I use gettimeofday to obtain time of cpu. I can create several timers and works fine, but I have a doubt, what happen if counters overflow???

I understand that there is a moment that gettimeofday return me overflow counter and restart again from 0, or no???

By other hand, I known that there are other options to create timers, for example posix timer (timer_create, timer_settimer, etc etc ). With posix timers, is easy to create timers, but there is some problem for me, is necessary to create a sigaction:

Code:
	act.sa_sigaction = ManejadorSig;
	sigemptyset(&(act.sa_mask));
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGNUM, &act, NULL);
and I do not know how to pass arguments. My questions is, Can I pass more arguments to act.sa_sigaction or there is other way to do it???

Code:
ManejadorSig (int signo, siginfo_t *info, void *context)
 
Old 10-19-2009, 10:46 AM   #2
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
This is my code:

Code:
//*****************************************************************

typedef struct
{
	unsigned char IN;
	unsigned char Q;
	unsigned long PT;
	unsigned long ET;

	timer_t  id_timer;
	struct timespec period_time;
}myTypeTimer;


//*****************************************************************

void ManejadorSig (int signo, siginfo_t *info, void *context)
{
	printf("Soy el manejador de la seņal #%d, Valor: %d\n",
			info->si_signo, info->_sifields._rt.si_sigval.sival_int);
	printf("Code: (%d) ", info->si_code);
	if (info->si_code == SI_TIMER) printf("SI_TIMER\n");
}

//*****************************************************************

int create_timer (struct timespec VAL_TEMP, myTypeTimer *aux)
{
struct sigaction act;
timer_t temporizador;
struct sigevent evp;
struct itimerspec param_temp;
struct timespec REINICIO_TEMP = {0, 0L};

	// Asigna un manejador ( Atrapa la seņal )
	//**************************************************************
	act.sa_sigaction = ManejadorSig;
	sigemptyset(&(act.sa_mask));
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGNUM, &act, NULL);

	// Crea el temporizador
	//**************************************************************
	evp.sigev_notify = SIGEV_SIGNAL;
	evp.sigev_signo = SIGNUM;
	timer_create(CLOCK_MONOTONIC, &evp, &temporizador);

	// Configurando el temporizador
	//**************************************************************
	param_temp.it_value = VAL_TEMP;
	param_temp.it_interval = REINICIO_TEMP;
	timer_settime(temporizador, 0, &param_temp, NULL);

	return 1;
}

//*****************************************************************

int main (void)
{
struct timespec RETARDO = {7, 0L};
struct timespec VAL_TEMPORIZADOR = {5, 0L};
struct timespec retardo_pend;
myTypeTimer aux_timer;

	create_timer(VAL_TEMPORIZADOR, &aux_timer);

	// Espero un rato
	//**************************************************************
	if (nanosleep(&RETARDO, &retardo_pend) != 0)
		nanosleep(&retardo_pend, NULL);

	return 0;
}
In function main, I have created aux_timer( myTypeTimer type). I pass as argument to create timer function, but when timer reach time, timer call ManejadorSig, and I would like to set aux_timer.Q , but I do not how to pass it to ManejadorSig.
 
Old 10-19-2009, 11:15 AM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Ohhhhhhh!!!!!!!!!!

please admin, could you move this post to PROGRAMMING section.

I am sorry, I am stupid.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Doubts about timers in linux kernel iamjayanth Linux - Kernel 5 01-31-2012 06:53 PM
Linux timers arabindav Linux - General 3 05-20-2011 07:33 AM
Linux timers... ytrew Linux - Newbie 4 06-30-2009 09:05 AM
Linux timers arabindav Programming 2 10-26-2006 01:52 AM
Help with Linux timers samble Programming 8 02-07-2004 10:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration