Example #1
0
void foo(long x)
{
  switch (x)
    {
    case -6: 
      fail1 (); break;
    case 0: 
      fail2 (); break;
    case 1: case 2: 
      break;
    case 3: case 4: case 5: 
      fail3 ();
      break;
    default:
      fail4 ();
      break;
    }
  switch (x)
    {
      
    case -3: 
      fail1 (); break;
    case 0: case 4: 
      fail2 (); break;
    case 1: case 3: 
      break;
    case 2: case 8: 
      abort ();
      break;
    default:
      fail4 ();
      break;
    }
}
Example #2
0
void setup_main_loop(void)
{
	signal(SIGPIPE, SIG_IGN);

	state.epoll_fd = epoll_create(1);
	if (state.epoll_fd < 0) fail(1, "epoll_create");

	rt_mutex_init(&state.sched_lock);

#if ENABLE_AIO
	int ret;

	static event_t aio_dummy_event;
	state.aio_dummy_event = &aio_dummy_event;

	ret = io_setup(MAX_AIO_EVENTS, &state.aio_ctx);
	if (ret < 0) fail2(1, -ret, "io_setup");

	state.aio_eventfd = eventfd(0, EFD_NONBLOCK);
	if (state.aio_eventfd < 0) fail(1, "eventfd");

	ret = epoll_ctler(EPOLL_CTL_ADD, state.aio_eventfd,
	                  EPOLLIN, state.aio_dummy_event);
	if (ret < 0) fail(1, "epoll_ctl eventfd");
#endif
}
Example #3
0
FILE* mustOpen (const char* filename, const char* mode) {
	FILE* f = fopen(filename, mode);
	(void) printf ("Opening %s with mode %s\n", filename, mode);
	if (!f)
		fail2 ("Cannot open ", filename);
	return f;
}
Example #4
0
// Poll epoll and aio and handle any events. If can_sleep is true
// and no aio events are expected, epoll will block.
static void do_poll(bool can_sleep, struct timespec next_wakeup)
{
	struct epoll_event epoll_events[MAX_EVENTS];
#if ENABLE_AIO
	struct io_event aio_events[MAX_EVENTS];

	// We need to be careful to not let either aio or epoll events
	// starve the other. We do this by always doing nonblocking polls
	// of aio and only having epoll block if we aren't expecting aio
	// events. When both types of events are coming in, we switch
	// between processing the two types.
	// Poll for aio events. Don't block.
	int aio_cnt = io_getevents(state.aio_ctx, 0, MAX_EVENTS,
	                           aio_events, NULL);
	if (aio_cnt < 0) { fail2(1, -aio_cnt, "io_getevents"); }
	bool expect_aio = aio_cnt == MAX_EVENTS;
	for (int i = 0; i < aio_cnt; i++) {
		handle_aio_event(&aio_events[i]);
	}
#else
#define expect_aio 0
#endif

	// If we aren't expecting aio, block indefinitely, otherwise
	// just poll.
	int epoll_timeout = expect_aio || !can_sleep ? 0 :
		compute_timeout(next_wakeup);
	int epoll_cnt = epoll_wait(state.epoll_fd, epoll_events,
	                           MAX_EVENTS, epoll_timeout);
	for (int i = 0; i < epoll_cnt; i++) {
#if ENABLE_AIO
		if (epoll_events[i].data.ptr == state.aio_dummy_event) {
			uint64_t eventfd_val;
			if (read(state.aio_eventfd, &eventfd_val,
			         sizeof(eventfd_val)) < 0)
				fail(1, "eventfd read");
		} else
#endif
		{
			handle_epoll_event(&epoll_events[i]);
		}
	}
}
int main(){
	int i = 0, j = 0;
	int *pnum, num[M]; //num存放每位学生的学号
	
	float score[M][N], *pscore;
	float aver[M], *paver; //aver存放每位学生的平均分
	
	char course[N][40], *pcourse; //course存放5门课程的名称

	printf("请按行输入5门功课的名称:\n");
	pcourse = course[i];
	for(i=0; i<N; ++i){
		scanf("%s", pcourse+40*i);
	}		

	printf("请按照下面的格式输入4个学生的学号和各科成绩:(以空格间隔)\n");
	printf("学号");
	for(i=0; i<N; ++i){
		printf(" %s", pcourse+40*i);
	}
	printf("\n");

	pscore = &score[0][0];
	pnum = &num[0];
	for(i=0; i<M; ++i){
		scanf("%d", pnum+i);
		for(j=0; j<N; ++j){
			scanf("%f", pscore+N*i+j);
		}
	}

	paver = &aver[0];
	printf("\n\n");
	averscore(pscore, paver); 
	avercour5(pcourse, pscore);
	printf("\n\n");
	fail2(pcourse, pnum, pscore, paver);
	printf("\n\n");
	great(pcourse, pnum, pscore, paver);
	return 0;
}