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

📄 3-1.c

📁 最新rtlinux内核源码
💻 C
字号:
/*    * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license.  For the full content * of this license, see the COPYING file at the top level of this  * source tree. * Test that if value.it_value = 0, the timer is disarmed. * Steps: * 1.  Set up sigevent structure to send signal SIGTOTEST on timer *     expiration. * 2.  Set up sigaction structure to catch signal SIGTOTEST on timer *     expiration * 3.  Create timer using timer_create(). * 4.  Activate timer using timer_settime() and then sleep. * 5.  Fail if signal handler is called. * 6.  If signal handler is not called, then PASS. * * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME * will be used. */#include <time.h>#include <signal.h>#include <unistd.h>#include "compat.h"#define PASS 0#define FAIL 1#define UNRESOLVED 2#define SIGTOTEST SIGALRM#define SLEEPDELTA 3timer_t tid;pthread_t th;void handler(int signo){	printf("Incorrectly in signal handler\n");	printf("Test FAILED\n");	exit(FAIL);}void *th_code(void *arg){	struct sigaction act;	struct itimerspec its;	struct timespec ts, tsleft;	act.sa_handler=handler;	act.sa_flags=0;	its.it_interval.tv_sec = 0;	its.it_interval.tv_nsec = 0;	/*	 * value.it_value = 0	 */	its.it_value.tv_sec = 0;	its.it_value.tv_nsec = 0;	ts.tv_sec=SLEEPDELTA;	ts.tv_nsec=0;	/*	if (sigemptyset(&act.sa_mask) == -1) {		perror("Error calling sigemptyset\n");		return UNRESOLVED;	}	*/	if (sigaction(SIGTOTEST, &act, 0) == -1) {		perror("Error calling sigaction\n");		return UNRESOLVED;	}	if (timer_settime(tid, 0, &its, NULL) != 0) {		perror("timer_settime() did not return success\n");		return UNRESOLVED;	}	if (nanosleep(&ts, &tsleft) == -1) {		printf("nanosleep() interrupted\n");		printf("Test FAILED\n");		return FAIL;	}	printf("Test PASSED\n");	return PASS;}int init_module(void){ int err;  struct sigevent ev;    ev.sigev_notify = SIGEV_SIGNAL;  ev.sigev_signo = SIGTOTEST;  if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {		perror("timer_create() did not return success\n");		return UNRESOLVED;	}  err=pthread_create(&th,NULL,th_code,(void *) 0);  return err;}void cleanup_module(void){  timer_delete(tid);  pthread_delete_np(th);}

⌨️ 快捷键说明

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