int8_t queue_destroy_internal(queue_t *q, uint8_t fd, void (*ff)(void *)) { // this method will not immediately return on error, // it will try to release all the memory that was allocated. int error = Q_OK; // make sure no new data comes and wake all waiting threads error = queue_set_new_data(q, 0); error = queue_lock_internal(q); // release internal element memory error = queue_flush_internal(q, fd, ff); // destroy lock and queue etc error = pthread_cond_destroy(q->cond_get); free(q->cond_get); error = pthread_cond_destroy(q->cond_put); free(q->cond_put); error = queue_unlock_internal(q); while(EBUSY == (error = pthread_mutex_destroy(q->mutex))) sleepmilli(100); free(q->mutex); // destroy queue free(q); return error; }
int8_t queue_destroy_internal(queue_t *q, uint8_t fd, void (*ff)(void *)) { // make sure no new data comes and wake all waiting threads int8_t r = queue_set_new_data(q, 0); if (r != Q_OK) return r; // release internal element memory r = queue_flush_internal(q, fd, ff); if (r != Q_OK) return r; // destroy lock and queue etc pthread_cond_destroy(q->cond_get); free(q->cond_get); pthread_cond_destroy(q->cond_put); free(q->cond_put); while(EBUSY == pthread_mutex_destroy(q->mutex)) usleep(100 * 1000); free(q->mutex); // destroy queue free(q); return Q_OK; }