📄 timer.h
字号:
/****************************************************************************** Copyright(C) 2005,2006 Frank ZHANG All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ****************************************************************************** If you want to distribute this software with modifications under any terms other than the GPL or distribute the software linked with proprietary applications that are not distributed in full compliance with the GNU Public License, a Commercial License is needed. Commercial licensing and support of this software are available at a fee. For more information, See http://www.openmgcp.org ******************************************************************************/#include <time.h>#include "pthread.h"#ifdef __cplusplusextern "C" {#endiftypedef unsigned int clockid_t;typedef unsigned long int timer_t;/* sigev_notify values */#define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */ /* when the event of interest occurs. */#define SIGEV_SIGNAL 2 /* A queued signal, with an application defined */ /* value, shall be delivered when the event of */ /* interest occurs. */#define SIGEV_THREAD 3 /* A notification function shall be called to */ /* perform notification. */union sigval{ int sival_int; /* Integer signal value */ void *sival_ptr; /* Pointer signal value */};struct sigevent{ int sigev_notify; /* Notification type */ int sigev_signo; /* Signal number */ union sigval sigev_value; /* Signal value */ void (*sigev_notify_function)( union sigval ); /* Notification function */ pthread_attr_t *sigev_notify_attributes; /* Notification Attributes */};/* Also defined in pthread.h */#ifndef HAVE_STRUCT_TIMESPEC#define HAVE_STRUCT_TIMESPEC 1struct timespec{ timer_t tv_sec; /* Seconds */ long tv_nsec; /* Nanoseconds */};#endifstruct itimerspec{ /* the reload value last set by timer_settime() */ struct timespec it_interval; /*contain the amount of time before the timer expires or zero if the timer is disarmed */ struct timespec it_value;};/* Identifier for system-wide realtime clock. */#define CLOCK_REALTIME 1/* High-resolution timer from the CPU. */#define CLOCK_PROCESS_CPUTIME_ID 2/* Thread-specific CPU-time clock. */#define CLOCK_THREAD_CPUTIME_ID 3///////////////////////////////////////////////////* The timer_create() function shall create a per-process timer using the specifiedclock, clock_id, as the timing base. The timer_create() function shall return,in the location referenced by timerid, a timer ID of type timer_t used to identify the timer in timer requests. This timer ID shall be unique within thecalling process until the timer is deleted. The particular clock, clock_id, is defined in <time.h>. The timer whose ID is returned shall be in a disarmed state upon return from timer_create(). */int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid);int timer_delete(timer_t timerid);/* The timer_gettime() function shall store the amount of time until thespecified timer, timerid, expires and the reload value of the timer into thespace pointed to by the value argument. The it_value member of this structureshall contain the amount of time before the timer expires, or zero if the timeris disarmed. This value is returned as the interval until timer expiration,even if the timer was armed with absolute time. The it_interval member of valueshall contain the reload value last set by timer_settime(). */int timer_gettime(timer_t timerid, struct itimerspec *value);/* The timer_settime() function shall set the time until the next expiration ofthe timer specified by timerid from the it_value member of the value argumentand arm the timer if the it_value member of value is non-zero. If the specifiedtimer was already armed when timer_settime() is called, this call shall resetthe time until next expiration to the value specified. If the it_value memberof value is zero, the timer shall be disarmed. The effect of disarming orresetting a timer with pending expiration notifications is unspecified. */int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, struct itimerspec *ovalue);#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -