Ejemplo n.º 1
0
static void *pnet_rx_thread_hnd(void *args) {
	struct pnet_wait_unit *unit = (struct pnet_wait_unit *) args;
	struct pnet_pack *pack;

	while (1) {
		if (unit->buff.cnt == 0) {
			EVENT_WAIT(&unit->event, unit->buff.cnt, EVENT_TIMEOUT_INFINITE);
			continue;
		}
		ring_buff_dequeue(&unit->buff, &pack, 1);
		pnet_process(pack);
	}
	return NULL;
}
Ejemplo n.º 2
0
static ssize_t pipe_read(struct idesc *idesc, void *buf, size_t nbyte) {
	struct pipe *pipe;
	ssize_t res;

	assert(buf);
	assert(idesc);
	assert(idesc->idesc_ops == &idesc_pipe_ops);
	assert(idesc->idesc_amode == FS_MAY_READ);

	if (!nbyte) {
		return 0;
	}

	pipe = idesc_to_pipe(idesc);
	mutex_lock(&pipe->mutex);
	do {
		res = ring_buff_dequeue(pipe->buff, buf, nbyte);

		if (idesc_pipe_isclosed(&pipe->write_desc)) {
			/* Nothing to do, what's read, that's read */
			break;
		}

		if (res > 0) {
			/* Smth read, notify write end (can't be closed,
 			 * checked already) */
			idesc_notify(&pipe->write_desc.idesc, POLLOUT);
			break;
		}

		res = pipe_wait(idesc, pipe, POLLIN | POLLERR);
	} while (res == 0);
	mutex_unlock(&pipe->mutex);

	return res;
}