/* * cleanup -- (internal) clean up after each run */ static void cleanup(char test_type) { switch (test_type) { case 'm': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); break; case 'r': os_rwlock_destroy(&((PMEMrwlock_internal *) &(Test_obj->rwlock))->PMEMrwlock_lock); break; case 'c': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); os_cond_destroy(&((PMEMcond_internal *) &(Test_obj->cond))->PMEMcond_cond); break; case 't': os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex))->PMEMmutex_lock); os_mutex_destroy(&((PMEMmutex_internal *) &(Test_obj->mutex_locked))->PMEMmutex_lock); break; default: FATAL_USAGE(); } }
/****************************************************************************** * Function: jpeg_queue_destroy * Description: Destroys the queue object and cleans up internal variables * Input parameters: * p_queue - The pointer to queue object to be destroyed. * Return values: none * Notes: none *****************************************************************************/ void jpeg_queue_destroy(jpeg_queue_t *p_queue) { if (p_queue) { jpeg_q_t *p_q = (jpeg_q_t *)(*p_queue); if (p_q) { JPEG_DBG_LOW("jpeg_queue_destroy: jpeg queue destroy\n"); jpeg_queue_abort(p_queue); JPEG_DBG_LOW("jpeg_queue_destroy: aborted\n"); // queue clean up os_cond_destroy(&(p_q->get_cond)); os_cond_destroy(&(p_q->abort_cond)); os_mutex_destroy(&(p_q->mutex)); JPEG_FREE(p_q); } *p_queue = NULL; } }
struct OsCond * os_cond_create(void) { struct OsCond *cond = allocate_zero<OsCond>(1); if (!cond) { os_cond_destroy(cond); return NULL; } #if defined(GENESIS_OS_WINDOWS) InitializeConditionVariable(&cond->id); InitializeCriticalSection(&cond->default_cs_id); #elif defined(GENESIS_OS_KQUEUE) cond->kq_id = kqueue(); if (cond->kq_id == -1) return NULL; #else if (pthread_condattr_init(&cond->attr)) { os_cond_destroy(cond); return NULL; } cond->attr_init = true; if (pthread_condattr_setclock(&cond->attr, CLOCK_MONOTONIC)) { os_cond_destroy(cond); return NULL; } if (pthread_cond_init(&cond->id, &cond->attr)) { os_cond_destroy(cond); return NULL; } cond->id_init = true; if ((pthread_mutex_init(&cond->default_mutex_id, NULL))) { os_cond_destroy(cond); return NULL; } cond->default_mutex_init = true; #endif return cond; }
void ordered_map_file_close(OrderedMapFile *omf) { if (!omf) return; if (omf->mutex && omf->cond && !omf->queue.error()) { ordered_map_file_flush(omf); omf->running = false; omf->queue.wakeup_all(); } os_thread_destroy(omf->write_thread); if (omf->file) fclose(omf->file); destroy_list(omf); destroy_map(omf); os_mutex_destroy(omf->mutex); os_cond_destroy(omf->cond); destroy(omf, 1); }
void audio_graph_destroy(AudioGraph *ag) { if (!ag) return; if (ag->pipeline) { genesis_pipeline_stop(ag->pipeline); genesis_node_destroy(ag->master_node); ag->master_node = nullptr; } ag->project->events.detach_handler(EventProjectAudioClipsChanged, on_project_audio_clips_changed); ag->project->events.detach_handler(EventProjectAudioClipSegmentsChanged, on_project_audio_clip_segments_changed); while (ag->audio_clip_list.length()) { AudioGraphClip *clip = ag->audio_clip_list.pop(); audio_graph_clip_destroy(clip); } os_cond_destroy(ag->render_cond); }
/* ---------------------------------------------------------------------- * tear down data structures, and free memory, associated with * the given non-wrap fifo handle * * returns 0 on success, non-0 otherwise * -------------------------------------------------------------------- */ int32_t non_wrap_fifo_destroy( VCHI_NWFIFO_T *_fifo ) { NON_WRAP_FIFO_HANDLE_T *fifo = (NON_WRAP_FIFO_HANDLE_T *)_fifo; int32_t success = -1; // first confirm that the handle has been previously allocated if ( fifo->base_address ) { // free the FIFO memory free( fifo->malloc_address ); // free the slot info memory free( fifo->slot_info ); // destroy the os signalling os_cond_destroy( &fifo->space_available_cond ); os_semaphore_destroy( &fifo->sem ); // free the structure free( fifo ); // success! success = 0; } return success; }
int main(int argc, char *argv[]) { START(argc, argv, "obj_direct"); if (argc != 3) UT_FATAL("usage: %s [directory] [# of pools]", argv[0]); unsigned npools = ATOU(argv[2]); const char *dir = argv[1]; int r; os_mutex_init(&lock1); os_mutex_init(&lock2); os_cond_init(&sync_cond1); os_cond_init(&sync_cond2); cond1 = cond2 = 0; PMEMobjpool **pops = MALLOC(npools * sizeof(PMEMobjpool *)); UT_ASSERTne(pops, NULL); size_t length = strlen(dir) + MAX_PATH_LEN; char *path = MALLOC(length); for (unsigned i = 0; i < npools; ++i) { int ret = snprintf(path, length, "%s"OS_DIR_SEP_STR"testfile%d", dir, i); if (ret < 0 || ret >= length) UT_FATAL("!snprintf"); pops[i] = pmemobj_create(path, LAYOUT_NAME, PMEMOBJ_MIN_POOL, S_IWUSR | S_IRUSR); if (pops[i] == NULL) UT_FATAL("!pmemobj_create"); } PMEMoid *oids = MALLOC(npools * sizeof(PMEMoid)); UT_ASSERTne(oids, NULL); PMEMoid *tmpoids = MALLOC(npools * sizeof(PMEMoid)); UT_ASSERTne(tmpoids, NULL); oids[0] = OID_NULL; UT_ASSERTeq(obj_direct(oids[0]), NULL); for (unsigned i = 0; i < npools; ++i) { oids[i] = (PMEMoid) {pops[i]->uuid_lo, 0}; UT_ASSERTeq(obj_direct(oids[i]), NULL); uint64_t off = pops[i]->heap_offset; oids[i] = (PMEMoid) {pops[i]->uuid_lo, off}; UT_ASSERTeq((char *)obj_direct(oids[i]) - off, (char *)pops[i]); r = pmemobj_alloc(pops[i], &tmpoids[i], 100, 1, NULL, NULL); UT_ASSERTeq(r, 0); } r = pmemobj_alloc(pops[0], &thread_oid, 100, 2, NULL, NULL); UT_ASSERTeq(r, 0); UT_ASSERTne(obj_direct(thread_oid), NULL); os_thread_t t; PTHREAD_CREATE(&t, NULL, test_worker, NULL); /* wait for the worker thread to perform the first check */ os_mutex_lock(&lock1); while (!cond1) os_cond_wait(&sync_cond1, &lock1); os_mutex_unlock(&lock1); for (unsigned i = 0; i < npools; ++i) { UT_ASSERTne(obj_direct(tmpoids[i]), NULL); pmemobj_free(&tmpoids[i]); UT_ASSERTeq(obj_direct(tmpoids[i]), NULL); pmemobj_close(pops[i]); UT_ASSERTeq(obj_direct(oids[i]), NULL); } /* signal the worker that we're free and closed */ os_mutex_lock(&lock2); cond2 = 1; os_cond_signal(&sync_cond2); os_mutex_unlock(&lock2); PTHREAD_JOIN(&t, NULL); os_cond_destroy(&sync_cond1); os_cond_destroy(&sync_cond2); os_mutex_destroy(&lock1); os_mutex_destroy(&lock2); FREE(pops); FREE(tmpoids); FREE(oids); DONE(NULL); }
~LockedQueue() { destroy(_items, _capacity); os_mutex_destroy(_mutex); os_cond_destroy(_cond); }