Exemplo n.º 1
0
static void
ucomstart(struct tty *tp)
{
	struct ucom_softc *sc = device_lookup_private(&ucom_cd,
	    UCOMUNIT(tp->t_dev));
	struct ucom_buffer *ub;
	int s;
	u_char *data;
	int cnt;

	if (sc->sc_dying)
		return;

	s = spltty();
	if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP)) {
		DPRINTFN(4,("ucomstart: no go, state=0x%x\n", tp->t_state));
		goto out;
	}
	if (sc->sc_tx_stopped)
		goto out;

	if (!ttypull(tp))
		goto out;

	/* Grab the first contiguous region of buffer space. */
	data = tp->t_outq.c_cf;
	cnt = ndqb(&tp->t_outq, 0);

	if (cnt == 0) {
		DPRINTF(("ucomstart: cnt==0\n"));
		goto out;
	}

	ub = SIMPLEQ_FIRST(&sc->sc_obuff_free);
	KASSERT(ub != NULL);
	SIMPLEQ_REMOVE_HEAD(&sc->sc_obuff_free, ub_link);

	if (SIMPLEQ_FIRST(&sc->sc_obuff_free) == NULL)
		SET(tp->t_state, TS_BUSY);

	if (cnt > sc->sc_obufsize)
		cnt = sc->sc_obufsize;

	if (sc->sc_methods->ucom_write != NULL)
		sc->sc_methods->ucom_write(sc->sc_parent, sc->sc_portno,
					   ub->ub_data, data, &cnt);
	else
		memcpy(ub->ub_data, data, cnt);

	ub->ub_len = cnt;
	ub->ub_index = 0;

	SIMPLEQ_INSERT_TAIL(&sc->sc_obuff_full, ub, ub_link);

	softint_schedule(sc->sc_si);

 out:
	splx(s);
}
Exemplo n.º 2
0
Arquivo: umidi.c Projeto: bluhm/sys
static void
out_intr(struct usbd_xfer *xfer, void *priv, usbd_status status)
{
	struct umidi_endpoint *ep = (struct umidi_endpoint *)priv;
	struct umidi_softc *sc = ep->sc;
	struct umidi_jack *j;
	unsigned pending;
	
	if (usbd_is_dying(sc->sc_udev))
		return;

	ep->used = 0;
	ep->busy = 0;
	for (pending = ep->pending; pending > 0; pending--) {
		j = SIMPLEQ_FIRST(&ep->intrq);
#ifdef DIAGNOSTIC
		if (j == NULL) {
			printf("umidi: missing intr entry\n");
			break;
		}
#endif
		SIMPLEQ_REMOVE_HEAD(&ep->intrq, intrq_entry);
		ep->pending--;
		j->intr = 0;
		mtx_enter(&audio_lock);
		if (j->opened && j->u.out.intr)
			(*j->u.out.intr)(j->arg);
		mtx_leave(&audio_lock);
	}
}
Exemplo n.º 3
0
void
remove_vnode_from_name_tree(struct fuse *f, struct fuse_vnode *vn)
{
    struct fuse_vn_head *vn_head;
    struct fuse_vnode *v;
    struct fuse_vnode *lastv;

    vn_head = dict_get(&f->name_tree, vn->path);
    if (vn_head == NULL)
        return;

    lastv = NULL;
    SIMPLEQ_FOREACH(v, vn_head, node) {
        if (v->parent == vn->parent)
            break;

        lastv = v;
    }
    if (v == NULL)
        return;

    /* if we found the vnode remove it */
    if (v == SIMPLEQ_FIRST(vn_head))
        SIMPLEQ_REMOVE_HEAD(vn_head, node);
    else
        SIMPLEQ_REMOVE_AFTER(vn_head, lastv, node);

    /* if the queue is empty we need to remove it from the dict */
    if (SIMPLEQ_EMPTY(vn_head)) {
        vn_head = dict_pop(&f->name_tree, vn->path);
        free(vn_head);
    }
}
Exemplo n.º 4
0
static void network_notifier(RECOVERY_STATUS status, int error, const char *msg)
{
    int len = msg ? strlen(msg) : 0;
    struct msg_elem *newmsg = (struct msg_elem *)calloc(1, sizeof(*newmsg) + len + 1);
    struct msg_elem *oldmsg;

    if (!newmsg)
        return;

    pthread_mutex_lock(&msglock);
    nrmsgs++;
    if (nrmsgs > NUM_CACHED_MESSAGES) {
        oldmsg = SIMPLEQ_FIRST(&notifymsgs);
        SIMPLEQ_REMOVE_HEAD(&notifymsgs, next);
        free(oldmsg);
        nrmsgs--;
    }
    newmsg->msg = (char *)newmsg + sizeof(struct msg_elem);

    newmsg->status = status;
    newmsg->error = error;

    if (msg) {
        strncpy(newmsg->msg, msg, len);
        clean_msg(newmsg->msg, '\t');
        clean_msg(newmsg->msg, '\n');
        clean_msg(newmsg->msg, '\r');
    }


    SIMPLEQ_INSERT_TAIL(&notifymsgs, newmsg, next);
    pthread_mutex_unlock(&msglock);
}
Exemplo n.º 5
0
void *datalogger_thread(void *queue_ptr) {
	struct da_entry *dae = NULL;
	struct s_datalog_entry *dle = NULL;
	char timestamp[16];
	log_debug("starting datalogger thread");
	while (1) {
		pthread_mutex_lock(&da_mutex);
		pthread_cond_wait(&da_cond, &da_mutex);
		if (!(SIMPLEQ_EMPTY(&da_head))) {
			dae = SIMPLEQ_FIRST(&da_head);
			SIMPLEQ_REMOVE_HEAD(&da_head, da_entries);
		}
		pthread_mutex_unlock(&da_mutex);
		if (dae != NULL) {
			if (!(dle = (struct s_datalog_entry *)malloc(sizeof(struct s_datalog_entry)))) {
				log_error("datalogger_thread: malloc failed");
			}
			struct tm *tm_now = localtime(&dae->timestamp);
			strftime(timestamp, sizeof(timestamp), "%Y%m%d%H%M%S", tm_now);

			(void)snprintf(dle->line, sizeof(dle->line), "%s,%d,%.02f,%.02f,%.02f,%.02f,%.02f,%d,%.02f,%.02f\n",
				timestamp, dae->values->host_id, dae->values->temperature,
				dae->values->pressure, dae->values->humidity,
				dae->values->light, dae->values->wind_speed,
				(unsigned int)dae->values->wind_direction, dae->values->wind_chill,
				dae->values->rainfall);

			datalogger_write(dle);
			free(dae);
			free(dle);
		}
	}
	return 0;
}
Exemplo n.º 6
0
/*
 * Initialize the transmit descriptors.
 */
static void
rtk_list_tx_init(struct rtk_softc *sc)
{
	struct rtk_tx_desc *txd;
	int i;

	while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_dirty)) != NULL)
		SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_dirty, txd_q);
	while ((txd = SIMPLEQ_FIRST(&sc->rtk_tx_free)) != NULL)
		SIMPLEQ_REMOVE_HEAD(&sc->rtk_tx_free, txd_q);

	for (i = 0; i < RTK_TX_LIST_CNT; i++) {
		txd = &sc->rtk_tx_descs[i];
		CSR_WRITE_4(sc, txd->txd_txaddr, 0);
		SIMPLEQ_INSERT_TAIL(&sc->rtk_tx_free, txd, txd_q);
	}
}
Exemplo n.º 7
0
static int
ld_ataraid_start_span(struct ld_softc *ld, struct buf *bp)
{
	struct ld_ataraid_softc *sc = (void *) ld;
	struct ataraid_array_info *aai = sc->sc_aai;
	struct ataraid_disk_info *adi;
	struct cbuf *cbp;
	char *addr;
	daddr_t bn;
	long bcount, rcount;
	u_int comp;

	/* Allocate component buffers. */
	addr = bp->b_data;

	/* Find the first component. */
	comp = 0;
	adi = &aai->aai_disks[comp];
	bn = bp->b_rawblkno;
	while (bn >= adi->adi_compsize) {
		bn -= adi->adi_compsize;
		adi = &aai->aai_disks[++comp];
	}

	bp->b_resid = bp->b_bcount;

	for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
		rcount = bp->b_bcount;
		if ((adi->adi_compsize - bn) < btodb(rcount))
			rcount = dbtob(adi->adi_compsize - bn);

		cbp = ld_ataraid_make_cbuf(sc, bp, comp, bn, addr, rcount);
		if (cbp == NULL) {
			/* Free the already allocated component buffers. */
                       while ((cbp = SIMPLEQ_FIRST(&sc->sc_cbufq)) != NULL) {
                               SIMPLEQ_REMOVE_HEAD(&sc->sc_cbufq, cb_q);
				CBUF_PUT(cbp);
			}
                       return EAGAIN;
		}

		/*
		 * For a span, we always know we advance to the next disk,
		 * and always start at offset 0 on that disk.
		 */
		adi = &aai->aai_disks[++comp];
		bn = 0;

               SIMPLEQ_INSERT_TAIL(&sc->sc_cbufq, cbp, cb_q);
		addr += rcount;
	}

	/* Now fire off the requests. */
       softint_schedule(sc->sc_sih_cookie);

       return 0;
}
Exemplo n.º 8
0
void
kthread_run_deferred_queue(void)
{
	struct kthread_q *kq;

	while ((kq = SIMPLEQ_FIRST(&kthread_q)) != NULL) {
		SIMPLEQ_REMOVE_HEAD(&kthread_q, kq, kq_q);
		(*kq->kq_func)(kq->kq_arg);
		free(kq, M_TEMP);
	}
}
Exemplo n.º 9
0
void
an_pcmcia_attach(struct device *parent, struct device *self, void *aux)
{
	struct an_pcmcia_softc *psc = (struct an_pcmcia_softc *)self;
	struct an_softc *sc = (struct an_softc *)self;
	struct pcmcia_attach_args *pa = aux;
	struct pcmcia_config_entry *cfe;
	const char *intrstr;
	int error;

	psc->sc_pf = pa->pf;
	cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);

	pcmcia_function_init(pa->pf, cfe);
	if (pcmcia_function_enable(pa->pf)) {
		printf(": function enable failed\n");
		return;
	}

	if (pcmcia_io_alloc(pa->pf, 0, AN_IOSIZ, AN_IOSIZ, &psc->sc_pcioh)) {
		printf(": can't alloc i/o space\n");
		pcmcia_function_disable(pa->pf);
		return;
	}

	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0, AN_IOSIZ,
	    &psc->sc_pcioh, &psc->sc_io_window)) {
		printf(": can't map i/o space\n");
		pcmcia_io_free(pa->pf, &psc->sc_pcioh);
		pcmcia_function_disable(pa->pf);
		return;
	}

	sc->sc_iot = psc->sc_pcioh.iot;
	sc->sc_ioh = psc->sc_pcioh.ioh;
	sc->sc_enabled = 1;

	sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, an_intr, sc,
	    sc->sc_dev.dv_xname);
	intrstr = pcmcia_intr_string(psc->sc_pf, sc->sc_ih);
	if (*intrstr)
		printf(", %s", intrstr);
	printf("\n");

	error = an_attach(sc);
	if (error) {
		printf("%s: failed to attach controller\n",
		    self->dv_xname);
		return;
	}

	sc->sc_enabled = 0;
	psc->sc_state = AN_PCMCIA_ATTACHED;
}
Exemplo n.º 10
0
Arquivo: xbd.c Projeto: MarginC/kame
static void
xbdresume(void)
{
	struct xbdreq *pxr, *xr;
	struct xbd_softc *xs;
	struct buf *bp;

	while ((pxr = SIMPLEQ_FIRST(&xbdr_suspended)) != NULL) {
		DPRINTF(XBDB_IO, ("xbdstart: resuming xbdreq %p for bp %p\n",
		    pxr, pxr->xr_bp));
		bp = pxr->xr_bp;
		xs = getxbd_softc(bp->b_dev);
		if (xs == NULL || xs->sc_shutdown) {
			bp->b_flags |= B_ERROR;
			bp->b_error = EIO;
		}
		if (bp->b_flags & B_ERROR) {
			pxr->xr_bdone -= pxr->xr_bqueue;
			pxr->xr_bqueue = 0;
			if (pxr->xr_bdone == 0) {
				bp->b_resid = bp->b_bcount;
				if (pxr->xr_aligned)
					unmap_align(pxr);
				PUT_XBDREQ(pxr);
				if (xs)
				{
					disk_unbusy(&xs->sc_dksc.sc_dkdev,
					    (bp->b_bcount - bp->b_resid),
					    (bp->b_flags & B_READ));
#if NRND > 0
					rnd_add_uint32(&xs->rnd_source,
					    bp->b_blkno);
#endif
				}
				biodone(bp);
			}
			continue;
		}
		while (__predict_true(pxr->xr_bqueue > 0)) {
			GET_XBDREQ(xr);
			if (__predict_false(xr == NULL))
				goto out;
			xr->xr_parent = pxr;
			fill_ring(xr);
		}
		DPRINTF(XBDB_IO, ("xbdstart: resumed xbdreq %p for bp %p\n",
		    pxr, bp));
		SIMPLEQ_REMOVE_HEAD(&xbdr_suspended, xr_suspended);
	}

 out:
	return;
}
Exemplo n.º 11
0
void
fsd_equeue_fini(void)
{
	struct fsd_equeue_entry *entry;
	
	while ((entry = SIMPLEQ_FIRST(&fsd_equeue_head)) != NULL) {
		fsd_evt_fini(entry->evt);
		SIMPLEQ_REMOVE_HEAD(&fsd_equeue_head, entries);
	}
	
	return;
}
Exemplo n.º 12
0
static void
ucomwritecb(usbd_xfer_handle xfer, usbd_private_handle p, usbd_status status)
{
	struct ucom_softc *sc = (struct ucom_softc *)p;
	int s;

	s = spltty();

	ucom_write_status(sc, SIMPLEQ_FIRST(&sc->sc_obuff_full), status);

	splx(s);
}
Exemplo n.º 13
0
/*
 * Undo the changes done above.
 * Such a function is necessary since we need a full-blown pcmcia world
 * set up in order to do the device probe, but if we don't match the card,
 * leaving this state will cause trouble during other probes.
 */
void
cfxga_remove_function(struct pcmcia_function *pf)
{
	struct pcmcia_config_entry *cfe;

	/* we are the first and only entry... */
	cfe = SIMPLEQ_FIRST(&pf->cfe_head);
	SIMPLEQ_REMOVE_HEAD(&pf->cfe_head, cfe_list);
	free(cfe, M_DEVBUF);

	/* And we're a figment of the kernel's imagination again. */
	pf->pf_flags |= PFF_FAKE;
}
Exemplo n.º 14
0
fsd_evt_t *
fsd_equeue_pop(void)
{
	struct fsd_equeue_entry *entry;
	fsd_evt_t *evt = NULL;
	
	if ((entry = SIMPLEQ_FIRST(&fsd_equeue_head)) != NULL) {
		evt = entry->evt;
		SIMPLEQ_REMOVE_HEAD(&fsd_equeue_head, entries);
	}
	
	return (evt);
}
Exemplo n.º 15
0
void
free_rdomains(struct rdomain_head *rdomains)
{
	struct rdomain		*rd;

	while ((rd = SIMPLEQ_FIRST(rdomains)) != NULL) {
		SIMPLEQ_REMOVE_HEAD(rdomains, entry);
		filterset_free(&rd->export);
		filterset_free(&rd->import);
		free_networks(&rd->net_l);
		free(rd);
	}
}
Exemplo n.º 16
0
/*
 * When a routine that uses resources is finished, the next device
 * in queue for map registers etc is called. If it succeeds to get
 * resources, call next, and next, and next...
 * This routine must be called at splvm.
 */
void
uba_done(struct uba_softc *uh)
{
	struct uba_unit *uu;
 
	while ((uu = SIMPLEQ_FIRST(&uh->uh_resq))) {
		SIMPLEQ_REMOVE_HEAD(&uh->uh_resq, uu_resq);
		if ((*uu->uu_ready)(uu) == 0) {
			SIMPLEQ_INSERT_HEAD(&uh->uh_resq, uu, uu_resq);
			break;
		}
	}
}
Exemplo n.º 17
0
static void
ucom_read_complete(struct ucom_softc *sc)
{
	int (*rint)(int, struct tty *);
	struct ucom_buffer *ub;
	struct tty *tp;
	int s;

	tp = sc->sc_tty;
	rint = tp->t_linesw->l_rint;
	ub = SIMPLEQ_FIRST(&sc->sc_ibuff_full);

	while (ub != NULL && !sc->sc_rx_stopped) {

		s = spltty();

		while (ub->ub_index < ub->ub_len && !sc->sc_rx_stopped) {
			/* Give characters to tty layer. */
			if ((*rint)(ub->ub_data[ub->ub_index], tp) == -1) {
				/* Overflow: drop remainder */
				ub->ub_index = ub->ub_len;
			} else
				ub->ub_index++;
		}

		splx(s);

		if (ub->ub_index == ub->ub_len) {
			SIMPLEQ_REMOVE_HEAD(&sc->sc_ibuff_full, ub_link);

			ucomsubmitread(sc, ub);

			ub = SIMPLEQ_FIRST(&sc->sc_ibuff_full);
		}
	}

	sc->sc_rx_unblock = (ub != NULL);
}
Exemplo n.º 18
0
void *aggregate_thread(void *queue_ptr) {
	struct pa_entry *pae = NULL;
	struct da_entry *dae = NULL;
	struct ga_entry *gae = NULL;
	struct s_aggregate *aggregates = NULL;
	// char buf[255];

	log_debug("starting aggregate thread");
	while (1) {
		pthread_mutex_lock(&pa_mutex);
		pthread_cond_wait(&pa_cond, &pa_mutex);

		pae = SIMPLEQ_FIRST(&pa_head);
		SIMPLEQ_REMOVE_HEAD(&pa_head, pa_entries);
		pthread_mutex_unlock(&pa_mutex);

		update_aggregates(pae->packet);
		free(pae);

		if (has_aggregates()) {
			aggregates = get_aggregates();

			if (!(dae = (struct da_entry *)malloc(sizeof(struct da_entry)))) {
				log_error("aggregate_thread: dae: malloc failed");
			}

			dae->values = aggregates;
			dae->timestamp = time(NULL);

			pthread_mutex_lock(&da_mutex);
			SIMPLEQ_INSERT_TAIL(&da_head, dae, da_entries);
			pthread_cond_signal(&da_cond);
			pthread_mutex_unlock(&da_mutex);

			if (!(gae = (struct ga_entry *)malloc(sizeof(struct ga_entry)))) {
				log_error("aggregate_thread: gae: malloc failed");
			}

			gae->values = aggregates;
			gae->timestamp = dae->timestamp;

			pthread_mutex_lock(&ga_mutex);
			SIMPLEQ_INSERT_TAIL(&ga_head, gae, ga_entries);
			pthread_cond_signal(&ga_cond);
			pthread_mutex_unlock(&ga_mutex);
		}

	}
	return 0;
}
Exemplo n.º 19
0
static void cleanum_msg_list(void)
{
    struct msg_elem *notification;

    pthread_mutex_lock(&msglock);

    while (!SIMPLEQ_EMPTY(&notifymsgs)) {
        notification = SIMPLEQ_FIRST(&notifymsgs);
        SIMPLEQ_REMOVE_HEAD(&notifymsgs, next);
        free(notification);
    }
    nrmsgs = 0;
    pthread_mutex_unlock(&msglock);
}
Exemplo n.º 20
0
static void
workqueue_runlist(struct workqueue *wq, struct workqhead *list)
{
	work_impl_t *wk;
	work_impl_t *next;

	/*
	 * note that "list" is not a complete SIMPLEQ.
	 */

	for (wk = SIMPLEQ_FIRST(list); wk != NULL; wk = next) {
		next = SIMPLEQ_NEXT(wk, wk_entry);
		(*wq->wq_func)((void *)wk, wq->wq_arg);
	}
}
Exemplo n.º 21
0
static void
ld_ataraid_start_vstrategy(void *arg)
{
       struct ld_ataraid_softc *sc = arg;
       struct cbuf *cbp;

       while ((cbp = SIMPLEQ_FIRST(&sc->sc_cbufq)) != NULL) {
               SIMPLEQ_REMOVE_HEAD(&sc->sc_cbufq, cb_q);
               if ((cbp->cb_buf.b_flags & B_READ) == 0) {
                       mutex_enter(cbp->cb_buf.b_vp->v_interlock);
                       cbp->cb_buf.b_vp->v_numoutput++;
                       mutex_exit(cbp->cb_buf.b_vp->v_interlock);
               }
               VOP_STRATEGY(cbp->cb_buf.b_vp, &cbp->cb_buf);
       }
}
Exemplo n.º 22
0
void *graphite_thread(void *queue_ptr) {
	struct ga_entry *gae = NULL;
	struct s_graphite_entry *entry = NULL;

	// char buffer[1024];
	char timestamp[11];

	log_debug("starting graphite thread");
	while (1) {
		pthread_mutex_lock(&ga_mutex);
		pthread_cond_wait(&ga_cond, &ga_mutex);
		if (!(SIMPLEQ_EMPTY(&ga_head))) {
			gae = SIMPLEQ_FIRST(&ga_head);
			SIMPLEQ_REMOVE_HEAD(&ga_head, ga_entries);
		}
		pthread_mutex_unlock(&ga_mutex);

		if (gae != NULL) {

			struct tm *tm_now = localtime(&gae->timestamp);
			strftime(timestamp, sizeof(timestamp), "%s", tm_now);

			if (!(entry = (struct s_graphite_entry *)malloc(sizeof(struct s_graphite_entry)))) {
				log_error("graphite_thread: malloc failed");
			}

			entry->host_id = gae->values->host_id;
			entry->temperature = gae->values->temperature;
			entry->pressure = gae->values->pressure;
			entry->c_pressure = gae->values->c_pressure;
			entry->humidity = gae->values->humidity;
			entry->light = gae->values->light;
			entry->wind_speed = gae->values->wind_speed;
			entry->wind_direction = gae->values->wind_direction;
			entry->wind_chill = gae->values->wind_chill;
			entry->rainfall = gae->values->rainfall;
			entry->timestamp = timestamp;

			graphite_write(entry);

			free(entry);
			free(gae);
		}
	}
	return 0;
}
Exemplo n.º 23
0
Arquivo: dt.c Projeto: MarginC/kame
int
dt_intr(void *cookie)
{
	struct dt_softc *sc;
	struct dt_msg *msg, *pend;

	sc = cookie;

	switch (dt_msg_get(&sc->sc_msg, 1)) {
	case DT_GET_ERROR:
		/*
		 * Ugh! The most common occurrence of a data overrun is upon
		 * a key press and the result is a software generated "stuck
		 * key".  All I can think to do is fake an "all keys up"
		 * whenever a data overrun occurs.
		 */
		sc->sc_msg.src = dt_kbd_addr;
		sc->sc_msg.ctl = DT_CTL(1, 0, 0);
		sc->sc_msg.body[0] = DT_KBD_EMPTY;
#ifdef DIAGNOSTIC
		printf("%s: data overrun or stray interrupt\n",
		    sc->sc_dv.dv_xname);
#endif
		break;

	case DT_GET_DONE:
		break;

	case DT_GET_NOTYET:
		return (1);
	}

	if ((msg = SLIST_FIRST(&sc->sc_free)) == NULL) {
		printf("%s: input overflow\n", sc->sc_dv.dv_xname);
		return (1);
	}
	SLIST_REMOVE_HEAD(&sc->sc_free, chain.slist);
	memcpy(msg, &sc->sc_msg, sizeof(*msg));

	pend = SIMPLEQ_FIRST(&sc->sc_queue);
	SIMPLEQ_INSERT_TAIL(&sc->sc_queue, msg, chain.simpleq);
	if (pend == NULL)
		softintr_schedule(sc->sc_sih);

	return (1);
}
Exemplo n.º 24
0
/*
 * If a CCB is specified, enqueue it.  Pull CCBs off the software queue in
 * the order that they were enqueued and try to submit their command blocks
 * to the controller for execution.
 */
void
twe_ccb_enqueue(struct twe_softc *sc, struct twe_ccb *ccb)
{
	int s;

	s = splbio();

	if (ccb != NULL)
		SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_queue, ccb, ccb_chain.simpleq);

	while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_queue)) != NULL) {
		if (twe_ccb_submit(sc, ccb))
			break;
		SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_queue, ccb_chain.simpleq);
	}

	splx(s);
}
Exemplo n.º 25
0
//Calls up on the semaphore
//purpose is to release the lock
void up( semaphore_t* sem ){

    //mutual exclusion
    pthread_mutex_lock(&sem->mutex);
    if(sem->wakeupCount > 0 ){

      //This is where I want to dequeue from the SimpleQ
      SIMPLEQ_REMOVE_HEAD( &sem->conditionalQueue, (np = SIMPLEQ_FIRST(&sem->conditionalQueue)), next );
      pthread_cond_signal(&np->condition);
      free(np);
      --sem->wakeupCount;


    }
    ++sem->count;
    pthread_mutex_unlock(&sem->mutex);

}
Exemplo n.º 26
0
static void
ucom_write_status(struct ucom_softc *sc, struct ucom_buffer *ub,
    usbd_status err)
{
	struct tty *tp = sc->sc_tty;
	uint32_t cc = ub->ub_len;

	switch (err) {
	case USBD_IN_PROGRESS:
		ub->ub_index = ub->ub_len;
		break;
	case USBD_STALLED:
		ub->ub_index = 0;
		softint_schedule(sc->sc_si);
		break;
	case USBD_NORMAL_COMPLETION:
		usbd_get_xfer_status(ub->ub_xfer, NULL, NULL, &cc, NULL);
#if defined(__NetBSD__) && NRND > 0
		rnd_add_uint32(&sc->sc_rndsource, cc);
#endif
		/*FALLTHROUGH*/
	default:
		SIMPLEQ_REMOVE_HEAD(&sc->sc_obuff_full, ub_link);
		SIMPLEQ_INSERT_TAIL(&sc->sc_obuff_free, ub, ub_link);
		cc -= sc->sc_opkthdrlen;

		CLR(tp->t_state, TS_BUSY);
		if (ISSET(tp->t_state, TS_FLUSH))
			CLR(tp->t_state, TS_FLUSH);
		else
			ndflush(&tp->t_outq, cc);

		if (err != USBD_CANCELLED && err != USBD_IOERROR &&
		    !sc->sc_dying) {
			if ((ub = SIMPLEQ_FIRST(&sc->sc_obuff_full)) != NULL)
				ucom_submit_write(sc, ub);

			(*tp->t_linesw->l_start)(tp);
		}
		break;
	}
}
Exemplo n.º 27
0
/*
 * Generate a reset on uba number uban.	 Then
 * call each device that asked to be called during attach,
 * giving it a chance to clean up so as to be able to continue.
 */
void
ubareset(struct uba_softc *uh)
{
	struct uba_reset *ur;
	int s;

	s = splvm();
	SIMPLEQ_INIT(&uh->uh_resq);
	printf("%s: reset", uh->uh_dev.dv_xname);
	(*uh->uh_ubainit)(uh);

	ur = SIMPLEQ_FIRST(&uh->uh_resetq);
	if (ur) do {
		printf(" %s", ur->ur_dev->dv_xname);
		(*ur->ur_reset)(ur->ur_dev);
	} while ((ur = SIMPLEQ_NEXT(ur, ur_resetq)));

	printf("\n");
	splx(s);
}
Exemplo n.º 28
0
int
prep_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
{
	struct genppc_pci_chipset_businfo *pbi;
	prop_object_t busmax;

	pbi = SIMPLEQ_FIRST(&genppc_pct->pc_pbi);
	while (busno--)
		pbi = SIMPLEQ_NEXT(pbi, next);
	if (pbi == NULL)
		return 32;

	busmax = prop_dictionary_get(pbi->pbi_properties,
	    "prep-pcibus-maxdevices");
	if (busmax == NULL)
		return 32;
	else
		return prop_number_integer_value(busmax);

	return 32;
}
Exemplo n.º 29
0
Arquivo: cac.c Projeto: ryo/netbsd-src
/*
 * Enqueue the specified command (if any) and attempt to start all enqueued
 * commands.
 */
static int
cac_ccb_start(struct cac_softc *sc, struct cac_ccb *ccb)
{

	KASSERT(mutex_owned(&sc->sc_mutex));

	if (ccb != NULL)
		SIMPLEQ_INSERT_TAIL(&sc->sc_ccb_queue, ccb, ccb_chain);

	while ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_queue)) != NULL) {
		if ((*sc->sc_cl.cl_fifo_full)(sc))
			return (EAGAIN);
		SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_queue, ccb_chain);
#ifdef DIAGNOSTIC
		ccb->ccb_flags |= CAC_CCB_ACTIVE;
#endif
		(*sc->sc_cl.cl_submit)(sc, ccb);
	}

	return (0);
}
Exemplo n.º 30
0
Arquivo: cac.c Projeto: ryo/netbsd-src
/*
 * Allocate a CCB.
 */
static struct cac_ccb *
cac_ccb_alloc(struct cac_softc *sc, int nosleep)
{
	struct cac_ccb *ccb;

	mutex_enter(&sc->sc_mutex);

	for (;;) {
		if ((ccb = SIMPLEQ_FIRST(&sc->sc_ccb_free)) != NULL) {
			SIMPLEQ_REMOVE_HEAD(&sc->sc_ccb_free, ccb_chain);
			break;
		}
		if (nosleep) {
			ccb = NULL;
			break;
		}
		cv_wait(&sc->sc_ccb_cv, &sc->sc_mutex);
	}

	mutex_exit(&sc->sc_mutex);
	return (ccb);
}