コード例 #1
0
ファイル: tsd.c プロジェクト: IIJ-NetBSD/netbsd-src
static void *
thd_start(void *arg) {
	int d = (int)(uintptr_t)arg;
	void *p;

	tsd_t *tsd = tsd_fetch();
	assert_x_eq(tsd_test_data_get(tsd), MALLOC_TSD_TEST_DATA_INIT,
	    "Initial tsd get should return initialization value");

	p = malloc(1);
	assert_ptr_not_null(p, "Unexpected malloc() failure");

	tsd_test_data_set(tsd, d);
	assert_x_eq(tsd_test_data_get(tsd), d,
	    "After tsd set, tsd get should return value that was set");

	d = 0;
	assert_x_eq(tsd_test_data_get(tsd), (int)(uintptr_t)arg,
	    "Resetting local data should have no effect on tsd");

	tsd_test_callback_set(tsd, &data_cleanup);

	free(p);
	return NULL;
}
コード例 #2
0
ファイル: tsd.c プロジェクト: IIJ-NetBSD/netbsd-src
void
data_cleanup(int *data) {
	if (data_cleanup_count == 0) {
		assert_x_eq(*data, MALLOC_TSD_TEST_DATA_INIT,
		    "Argument passed into cleanup function should match tsd "
		    "value");
	}
	++data_cleanup_count;

	/*
	 * Allocate during cleanup for two rounds, in order to assure that
	 * jemalloc's internal tsd reinitialization happens.
	 */
	bool reincarnate = false;
	switch (*data) {
	case MALLOC_TSD_TEST_DATA_INIT:
		*data = 1;
		reincarnate = true;
		break;
	case 1:
		*data = 2;
		reincarnate = true;
		break;
	case 2:
		return;
	default:
		not_reached();
	}

	if (reincarnate) {
		void *p = mallocx(1, 0);
		assert_ptr_not_null(p, "Unexpeced mallocx() failure");
		dallocx(p, 0);
	}
}
コード例 #3
0
ファイル: tsd.c プロジェクト: harrifeng/version-src
static void *
thd_start(void *arg)
{
    data_t d = (data_t)(uintptr_t)arg;
    assert_x_eq(*data_tsd_get(), DATA_INIT,
                "Initial tsd get should return initialization value");

    data_tsd_set(&d);
    assert_x_eq(*data_tsd_get(), d,
                "After tsd set, tsd get should return value that was set");

    d = 0;
    assert_x_eq(*data_tsd_get(), (data_t)(uintptr_t)arg,
                "Resetting local data should have no effect on tsd");

    return (NULL);
}
コード例 #4
0
ファイル: tsd.c プロジェクト: wangxuemin/coding
void
data_cleanup(void *arg)
{
	data_t *data = (data_t *)arg;

	assert_x_eq(*data, THREAD_DATA,
	    "Argument passed into cleanup function should match tsd value");
	data_cleanup_executed = true;
}
コード例 #5
0
ファイル: tsd.c プロジェクト: DawidvC/chapel
static void *
thd_start(void *arg)
{
	data_t d = (data_t)(uintptr_t)arg;
	void *p;

	assert_x_eq(*data_tsd_get(true), DATA_INIT,
	    "Initial tsd get should return initialization value");

	p = malloc(1);
	assert_ptr_not_null(p, "Unexpected malloc() failure");

	data_tsd_set(&d);
	assert_x_eq(*data_tsd_get(true), d,
	    "After tsd set, tsd get should return value that was set");

	d = 0;
	assert_x_eq(*data_tsd_get(true), (data_t)(uintptr_t)arg,
	    "Resetting local data should have no effect on tsd");

	free(p);
	return (NULL);
}
コード例 #6
0
ファイル: tsd.c プロジェクト: harrifeng/version-src
void
data_cleanup(void *arg)
{
    data_t *data = (data_t *)arg;

    if (!data_cleanup_executed) {
        assert_x_eq(*data, THREAD_DATA,
                    "Argument passed into cleanup function should match tsd "
                    "value");
    }
    data_cleanup_executed = true;

    /*
     * Allocate during cleanup for two rounds, in order to assure that
     * jemalloc's internal tsd reinitialization happens.
     */
    switch (*data) {
    case THREAD_DATA:
        *data = 1;
        data_tsd_set(data);
        break;
    case 1:
        *data = 2;
        data_tsd_set(data);
        break;
    case 2:
        return;
    default:
        not_reached();
    }

    {
        void *p = mallocx(1, 0);
        assert_ptr_not_null(p, "Unexpeced mallocx() failure");
        dallocx(p, 0);
    }
}