⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timer.h

📁 这是基于C语言开发的分布式搜索源代码
💻 H
字号:
#include <stdio.h>#include <stdlib.h>#include <stdint.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>#include <pthread.h>#ifndef _TIMER_H#define _TIMER_H#ifdef __cplusplusextern "C" {#endif#ifndef _TYPEDEF_TIMER#define _TYPEDEF_TIMERtypedef struct _TIMER{	struct timeval tv;	time_t start_sec;	uint64_t start_usec;	time_t sec_used;	uint64_t usec_used;	time_t  last_sec;	uint64_t last_usec;	time_t last_sec_used;        uint64_t last_usec_used;	pthread_mutex_t mutex;		void (*reset)(struct _TIMER *);	void (*check)(struct _TIMER *, uint32_t );	void (*sample)(struct _TIMER *);	void (*clean)(struct _TIMER **);	void (*callback)(void);	}TIMER;/* Initialize timer */TIMER *timer_init();#endif /* Reset timer */void timer_reset(TIMER *);/* Check timer and Run callback */void timer_check(TIMER *, uint32_t );/* TIMER  gettime */void timer_sample(TIMER *);/* Clean Timer */void timer_clean(TIMER **);/* VIEW timer */#define TIMER_VIEW(_timer) \{ \	if(_timer) \	{ \		printf("timerptr:%08x\n" \				"timer->start_sec:%u\n" \				"timer->start_usec:%llu\n" \				"timer->tv.tv_sec:%u\n" \				"timer->tv.tv_usec:%u\n" \				"timer->sec_used:%u\n" \				"timer->usec_used:%llu\n" \                                "timer->last_sec:%u\n" \                                "timer->last_usec:%llu\n" \                                "timer->last_sec_used:%u\n" \                                "timer->last_usec_used:%llu\n" \				"timer->reset():%08x\n" \				"timer->check():%08x\n" \				"timer->sample():%08x\n" \				"timer->clean():%08x\n\n", \				_timer, \				_timer->start_sec, \				_timer->start_usec, \				_timer->tv.tv_sec, \				_timer->tv.tv_usec, \				_timer->sec_used, \				_timer->usec_used, \				_timer->last_sec, \				_timer->last_usec, \                                _timer->last_sec_used, \                                _timer->last_usec_used, \				_timer->reset, \				_timer->check, \				_timer->sample, \				_timer->clean); \	} \}#ifdef __cplusplus }#endif#endif

⌨️ 快捷键说明

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