int q_add(void *qt, void *func, void *arg) { ASSERT(qt); ASSERT(func); /*arg possible NULL*/ Q_t *q = (Q_t*)qt; pthread_mutex_lock(&q->mutex); if (OK == q_isfull(q)) { pthread_mutex_unlock(&q->mutex); return ERROR; } ASSERT(q->last->func == NULL); q->last->func = func; q->last->arg = arg; q->last++; if (q->last == q->first + 1) { ASSERT(1 == q_length(q)); dump(L_DEBUG, "Queue send signal, has data"); pthread_cond_signal(&q->has_data_cond); } if (q->last == q->head + q->size) q->last = q->head; dump(L_DEBUG, "Add Queue Length %d", q_length(q)); pthread_mutex_unlock(&q->mutex); return OK; }
bool q_pushback(Queue *q, int v) { if (q_isfull(q)) { return false; } q->a[q->end] = v; q->end = q_inc(q, q->end); return true; }