int kvz_cu_array_free(cu_array_t * const cua) { int32_t new_refcount; if (!cua) return 1; new_refcount = KVZ_ATOMIC_DEC(&(cua->refcount)); //Still we have some references, do nothing if (new_refcount > 0) return 1; FREE_POINTER(cua->data); free(cua); return 1; }
/** * \brief Free a job. * * Decrement reference count of the job. If no references exist any more, * deallocate associated memory and destroy mutexes. * * Sets the job pointer to NULL. */ void kvz_threadqueue_free_job(threadqueue_job_t **job_ptr) { threadqueue_job_t *job = *job_ptr; if (job == NULL) return; *job_ptr = NULL; int new_refcount = KVZ_ATOMIC_DEC(&job->refcount); if (new_refcount > 0) { // There are still references so we don't free the data yet. return; } assert(new_refcount == 0); for (int i = 0; i < job->rdepends_count; i++) { kvz_threadqueue_free_job(&job->rdepends[i]); } job->rdepends_count = 0; FREE_POINTER(job->rdepends); pthread_mutex_destroy(&job->lock); FREE_POINTER(job); }