Example #1
0
static void
munch(int fd, enum ev_type ev, void *arg)
{
	ssize_t nbytes;
	char buf[32] = { 0 };
	int err;

	if ((nbytes = read(fd, buf, sizeof (buf))) < 0) {
		FAIL_ERRNO("bad read");
	}
	VERBOSE(("read %ld bytes '%s'", nbytes, buf));

	err = mevent_disable(read_event);
	ASSERT_INT_EQ(("mevent_disable: ", strerror(err)), err, 0);

	pthread_mutex_lock(&mtx);

	ASSERT_INT_EQ(("wrong lastwake"), lastwake, CB_NONE);
	lastwake = CB_READ;

	pthread_cond_signal(&cv);
	VERBOSE(("wakeup"));

	pthread_mutex_unlock(&mtx);
}
Example #2
0
static int
rxfifo_putchar(struct uart_softc *sc, uint8_t ch)
{
	struct fifo *fifo;
	int error;

	fifo = &sc->rxfifo;

	if (fifo->num < fifo->size) {
		fifo->buf[fifo->windex] = ch;
		fifo->windex = (fifo->windex + 1) % fifo->size;
		fifo->num++;
		if (!rxfifo_available(sc)) {
			if (sc->tty.opened) {
				/*
				 * Disable mevent callback if the FIFO is full.
				 */
				error = mevent_disable(sc->mev);
				assert(error == 0);
			}
		}
		return (0);
	} else
		return (-1);
}