LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-24-2009, 05:57 AM   #1
mayankparasher
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Rep: Reputation: 0
how to implement delay (microseconds) with real timer ticking at 100ms.


hi all,
In my application i implemented one timer(ITIMER_REAL) ticking @ 100ms. Code given below:
struct timeval my_value={0,100000};
struct timeval my_interval={0,100000};
struct itimerval my_timer={my_interval,my_value};
setitimer(ITIMER_REAL, &my_timer, NULL);
signal(SIGALRM,TimerHandler );
TimerHandler is the event executing @ every 100ms.
It works absolutly fine.

The problem is, i already implemented various usleep in application, which gets terminated because of SIGALRM signal from ITIMER_REAL. So now how do i implement delay(micro seconds) without effecting ITIMER_REAL?.

I tried to write own delay by reading microseconds. Code given below:
void delay_1ms(long int ms)
{
struct timeval tv;
ms= ms*1000;
gettimeofday(&tv, NULL);
ms +=tv.tv_usec;
while(ms!=tv.tv_usec)
{
gettimeofday(&tv, NULL);
}
}
but for value 1ms it goes for couple of seconds waiting.
I m doubting is gettimeofday is 'real time read'?
whats the way out friends?

Thanks in advance
-Mayank parasher.
 
Old 12-24-2009, 12:04 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
void delay_1ms(long int ms)
{
struct timeval tv;
ms *= 10;
gettimeofday(&tv);
time_t s = tv.tv_usec;
while(ms!=(tv.tv_usec-s))
{
gettimeofday(&tv, NULL);
}
}
try that.
 
  


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
Trouble when try to implement a timer thread using C++ steven_yu Programming 10 12-26-2007 08:12 PM
How do you call delay/udelay/mdelay timer in userspace? pat_and_cami SUSE / openSUSE 0 02-23-2006 02:37 AM
How can I implement an accurate timer under the heavey loading situation! appforce Programming 3 10-04-2005 06:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 PM.

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