timer.c

来自「接受modbus rtu协议的数据,报警应用程序.」· C语言 代码 · 共 52 行

C
52
字号
/******************************************************************************
 *
 * Copyright (c) 2008 Shanghai IS Software
 *
 * All rights reserved
 *
 * $Revision$
 *
 * $LastChangedBy$
 * 1.lcj
 *
 * $LastChangedData$
 * 2008/09/26
 *
 * Description: Timer (10ms)
 *
 * Revision History:
 * 2008/09/27 14:33 by lcj
 * #1.created
 *
 *****************************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/select.h>
#include <errno.h>


void ms_sleep(unsigned long ms)
{
	int err;

	struct timeval tv;

	tv.tv_sec = ms/1000;
	tv.tv_usec = (ms%1000) * 1000;

	while ((-1 == select(0,0,0,0,&tv)) && (err == errno));
}

void timer(int sec,long usec)
{
	struct timeval tvselect;

	tvselect.tv_sec = sec;
	tvselect.tv_usec = usec;

	select(0,NULL,NULL,NULL,&tvselect);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?