Exemplo n.º 1
0
ot_bool alp_is_available(alp_tmpl* alp, ot_int length) {
    ot_bool is_available;
    
    // Check if input queue is presently owned by some other app
    if (alp->inq->options.ubyte[0] != 0) {
        return False;
    }
    
    // Check if there is sufficient space available.  If not, try purging the
    // input and check again.
    is_available = (q_space(alp->inq) >= length);
    if (is_available == False) {
        alp_purge(alp);
        is_available = (q_space(alp->inq) >= length);
    }
    return is_available;
}
Exemplo n.º 2
0
bool
my_queue_insert(struct my_queue *q, void *item, unsigned *pspace)
{
	q_lock(q);
	bool res = false;
	unsigned head = q->head;
	unsigned tail = q->tail;
	unsigned space = q_space(head, tail, q->size);
	if (space >= 1) {
		q->elems[head] = item;
		q->head = (head + 1) & (q->size - 1);
		res = true;
		space--;
	}
	q_unlock(q);
	if (pspace)
		*pspace = space;
	return (res);
}
Exemplo n.º 3
0
bool
my_queue_mb_insert(struct my_queue *q, void *item, unsigned *pspace)
{
	bool res = false;
	unsigned head = q->head;
	unsigned tail = MY_ACCESS_ONCE(q->tail);
	unsigned space = q_space(head, tail, q->num_elems);
	if (space >= 1) {
		memcpy(&q->data[head * q->sizeof_elem], item, q->sizeof_elem);
		smp_wmb();
		q->head = (head + 1) & (q->num_elems - 1);
		smp_wmb();
		res = true;
		space--;
	}
	if (pspace != NULL)
		*pspace = space;
	return (res);
}