[Mplayer-cvslog] CVS: main/linux timer.c,NONE,1.1 Makefile,1.1,1.2 timer.h,1.4,1.5
Nick Kurshev
nick at mplayer.dev.hu
Mon Feb 25 15:24:14 CET 2002
Update of /cvsroot/mplayer/main/linux
In directory mplayer:/var/tmp.root/cvs-serv10919
Modified Files:
Makefile timer.h
Added Files:
timer.c
Log Message:
POSIX compatible timer's callback
--- NEW FILE ---
/* POSIX compatible timer callback */
#include <sys/time.h>
#include <signal.h>
#include <stddef.h>
#include "timer.h"
static timer_callback *user_func = NULL;
static struct itimerval otimer;
static void (*old_alrm)(int) = SIG_DFL;
static void my_alarm_handler( int signo )
{
if(user_func) (*user_func)();
}
unsigned set_timer_callback(unsigned ms,timer_callback func)
{
unsigned ret;
struct itimerval itimer;
user_func = func;
getitimer(ITIMER_REAL,&otimer);
old_alrm = signal(SIGALRM,my_alarm_handler);
signal(SIGALRM,my_alarm_handler);
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = ms*1000;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = ms*1000;
setitimer(ITIMER_REAL,&itimer,NULL);
getitimer(ITIMER_REAL,&itimer);
ret = itimer.it_interval.tv_sec*1000 + itimer.it_interval.tv_usec/1000;
if(!ret) restore_timer();
return ret;
}
void restore_timer(void)
{
signal(SIGALRM,old_alrm);
setitimer(ITIMER_REAL,&otimer,NULL);
}
Index: Makefile
===================================================================
RCS file: /cvsroot/mplayer/main/linux/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Makefile 24 Oct 2001 07:34:40 -0000 1.1
+++ Makefile 25 Feb 2002 14:24:11 -0000 1.2
@@ -3,7 +3,7 @@
LIBNAME = libosdep.a
-SRCS=getch2.c timer-lx.c shmem.c
+SRCS=getch2.c timer-lx.c timer.c shmem.c
OBJS=$(SRCS:.c=.o)
ifeq ($(TARGET_ARCH_X86),yes)
Index: timer.h
===================================================================
RCS file: /cvsroot/mplayer/main/linux/timer.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- timer.h 27 Jan 2002 17:59:12 -0000 1.4
+++ timer.h 25 Feb 2002 14:24:11 -0000 1.5
@@ -1,3 +1,5 @@
+#ifndef __TIMER_H
+#define __TIMER_H
void InitTimer();
unsigned int GetTimer();
@@ -7,3 +9,9 @@
int usec_sleep(int usec_delay);
+/* timer's callback handling */
+typedef void timer_callback( void );
+extern unsigned set_timer_callback(unsigned ms,timer_callback func);
+extern void restore_timer(void);
+
+#endif
More information about the MPlayer-cvslog
mailing list