FreeBSD/sys/kern/subr_bus.c
/**
 * @brief Queue data to be read from the devctl device
 *
 * Generic interface to queue data to the devctl device.  It is
 * assumed that @p data is properly formatted.  It is further assumed
 * that @p data is allocated using the M_BUS malloc type.
 */
@brief Queue data to be read from the devctl device
Generic interface to queue data to the devctl device.  It is
assumed that @p data is properly formatted.  It is further assumed
that @p data is allocated using the M_BUS malloc type.
@brief Queue data to be read from the devctl device Generic interface to queue data to the devctl device . It is assumed that @p data is properly formatted . It is further assumed that @p data is allocated using the M_BUS malloc type .
void
devctl_queue_data_f(char *data, int flags)
{
	struct dev_event_info *n1 = NULL, *n2 = NULL;
	if (strlen(data) == 0)
		goto out;
	if (devctl_queue_length == 0)
		goto out;
	n1 = malloc(sizeof(*n1), M_BUS, flags);
	if (n1 == NULL)
		goto out;
	n1->dei_data = data;
	mtx_lock(&devsoftc.mtx);
	if (devctl_queue_length == 0) {
		mtx_unlock(&devsoftc.mtx);
		free(n1->dei_data, M_BUS);
		free(n1, M_BUS);
		return;
	}
	while (devsoftc.queued > devctl_queue_length - 1) {
		n2 = TAILQ_FIRST(&devsoftc.devq);
		TAILQ_REMOVE(&devsoftc.devq, n2, dei_link);
		free(n2->dei_data, M_BUS);
		free(n2, M_BUS);
		devsoftc.queued--;
	}
	TAILQ_INSERT_TAIL(&devsoftc.devq, n1, dei_link);
	devsoftc.queued++;
	cv_broadcast(&devsoftc.cv);
	KNOTE_LOCKED(&devsoftc.sel.si_note, 0);
	mtx_unlock(&devsoftc.mtx);
	selwakeup(&devsoftc.sel);
	if (devsoftc.async && devsoftc.sigio != NULL)
		pgsigio(&devsoftc.sigio, SIGIO, 0);
	return;
out:
	free(data, M_BUS);
	return;
}
void devctl_queue_data_f ( char * data , int flags ) { struct dev_event_info * n1 = NULL , * n2 = NULL ; if ( strlen ( data ) == 0 ) goto out ; if ( devctl_queue_length == 0 ) goto out ; n1 = malloc ( sizeof ( * n1 ) , M_BUS , flags ) ; if ( n1 == NULL ) goto out ; n1 -> dei_data = data ; mtx_lock ( & devsoftc . mtx ) ; if ( devctl_queue_length == 0 ) { mtx_unlock ( & devsoftc . mtx ) ; free ( n1 -> dei_data , M_BUS ) ; free ( n1 , M_BUS ) ; return ; } while ( devsoftc . queued > devctl_queue_length - 1 ) { n2 = TAILQ_FIRST ( & devsoftc . devq ) ; TAILQ_REMOVE ( & devsoftc . devq , n2 , dei_link ) ; free ( n2 -> dei_data , M_BUS ) ; free ( n2 , M_BUS ) ; devsoftc . queued -- ; } TAILQ_INSERT_TAIL ( & devsoftc . devq , n1 , dei_link ) ; devsoftc . queued ++ ; cv_broadcast ( & devsoftc . cv ) ; KNOTE_LOCKED ( & devsoftc . sel . si_note , 0 ) ; mtx_unlock ( & devsoftc . mtx ) ; selwakeup ( & devsoftc . sel ) ; if ( devsoftc . async && devsoftc . sigio != NULL ) pgsigio ( & devsoftc . sigio , SIGIO , 0 ) ; return ; out : free ( data , M_BUS ) ; return ; }
@brief Queue data to be read from the devctl device
 Generic interface to queue data to the devctl device.
@brief Queue data to be read from the devctl device Generic interface to queue data to the devctl device .
/* Leave at least one spot in the queue... */ /*
	 * We have to free data on all error paths since the caller
	 * assumes it will be free'd when this item is dequeued.
	 */