Beispiel #1
0
int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout)
{
	int orig_timeout = timeout;
	struct timespec start;
	int ret;

	clock_gettime_mono(&start);

	while (true) {
		struct timespec now;
		int64_t elapsed;

		ret = poll(fds, num_fds, timeout);
		if (ret != -1) {
			break;
		}
		if (errno != EINTR) {
			break;
		}
		clock_gettime_mono(&now);
		elapsed = nsec_time_diff(&now, &start);
		timeout = (orig_timeout - elapsed) / 1000000;
	};
	return ret;
}
Beispiel #2
0
int asys_results(struct asys_context *ctx, struct asys_result *results,
		 unsigned num_results)
{
	int jobids[num_results];
	int i, ret;

	ret = pthreadpool_finished_jobs(ctx->pool, jobids, num_results);
	if (ret <= 0) {
		return ret;
	}

	for (i=0; i<ret; i++) {
		struct asys_result *result = &results[i];
		struct asys_job *job;
		int jobid;

		jobid = jobids[i];

		if ((jobid < 0) || (jobid >= ctx->num_jobs)) {
			return -EIO;
		}

		job = ctx->jobs[jobid];

		if (job->canceled) {
			result->ret = -1;
			result->err = ECANCELED;
		} else {
			result->ret = job->ret;
			result->err = job->err;
		}
		result->private_data = job->private_data;
		result->duration = nsec_time_diff(&job->end_time, &job->start_time);

		job->busy = 0;
	}

	return ret;
}