Exemplo n.º 1
0
/*
 * 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();
	}

}
Exemplo n.º 2
0
int fdwatch_destroy(FDWATCH_HANDLE handle)
{
	assert(handle && handle->inuse);
	if(handle==NULL || (!handle->inuse)) return ERR_INVALID_HANDLE;
	os_mutex_destroy(&handle->list_mtx);
	handle->inuse = 0;
	return ERR_NOERROR;
}
Exemplo n.º 3
0
struct OsMutex *os_mutex_create(void) {
    struct OsMutex *mutex = allocate_zero<OsMutex>(1);
    if (!mutex) {
        os_mutex_destroy(mutex);
        return NULL;
    }

#if defined(GENESIS_OS_WINDOWS)
    InitializeCriticalSection(&mutex->id);
#else
    int err;
    if ((err = pthread_mutex_init(&mutex->id, NULL))) {
        os_mutex_destroy(mutex);
        return NULL;
    }
    mutex->id_init = true;
#endif

    return mutex;
}
Exemplo n.º 4
0
static void wsf_os_free_resource(void)
{
    if ( NULL != msg_id_lock ) {
        os_mutex_destroy(msg_id_lock);
        msg_id_lock = NULL;
    }

    if ( NULL != sess_lock ) {
        os_mutex_destroy(sess_lock);
        sess_lock = NULL;
    }

    if ( NULL != device_lock ) {
        os_mutex_destroy(device_lock);
        device_lock = NULL;
    }

    if ( NULL != global_request_queue) {
        wsf_msg_queue_destroy(global_request_queue);
        global_request_queue = NULL;
    }
    deinit_req_glist();
}
Exemplo n.º 5
0
int log_close(LOG_HANDLE ctx)
{
	int ret;

	if(ctx->stream.buf!=NULL) {
		os_sem_post(&ctx->stream.inque);
		os_thread_wait(ctx->stream.thread, NULL);

		os_sem_destroy(&ctx->stream.inque);
		os_sem_destroy(&ctx->stream.ouque);
		os_mutex_destroy(&ctx->stream.mtx);
	}

	ret = map[ctx->type].func_close(ctx);
	free(ctx);
	return ret;
}
/******************************************************************************
* 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;
    }
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
void destroy_midi_hardware(struct MidiHardware *midi_hardware) {
    if (midi_hardware) {
        if (midi_hardware->thread) {
            // send dummy event to make thread wake up from blocking
            midi_hardware->quit_flag = true;
            snd_seq_event_t ev;
            snd_seq_ev_clear(&ev);
            ev.source.client = midi_hardware->client_id;
            ev.source.port = 0;
            snd_seq_ev_set_subs(&ev);
            snd_seq_ev_set_direct(&ev);
            ev.type = SND_SEQ_EVENT_USR0;
            int err = snd_seq_event_output(midi_hardware->seq, &ev);
            if (err < 0)
                panic("unable to send event: %s\n", snd_strerror(err));
            err = snd_seq_drain_output(midi_hardware->seq);
            if (err < 0)
                panic("unable to drain output: %s\n", snd_strerror(err));
            os_thread_destroy(midi_hardware->thread);
        }

        destroy_devices_info(midi_hardware->current_devices_info);
        destroy_devices_info(midi_hardware->ready_devices_info);
        genesis_midi_device_unref(midi_hardware->system_announce_device);
        genesis_midi_device_unref(midi_hardware->system_timer_device);

        if (midi_hardware->seq) {
            if (midi_hardware->client_info)
                snd_seq_client_info_free(midi_hardware->client_info);
            if (midi_hardware->port_info)
                snd_seq_port_info_free(midi_hardware->port_info);
            snd_seq_close(midi_hardware->seq);
        }

        os_mutex_destroy(midi_hardware->mutex);

        destroy(midi_hardware, 1);
    }
}
Exemplo n.º 9
0
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);
}
Exemplo n.º 10
0
 ~LockedQueue() {
     destroy(_items, _capacity);
     os_mutex_destroy(_mutex);
     os_cond_destroy(_cond);
 }