Exemplo n.º 1
0
void *cvar_alloc_handle(const char *cvar_parameters,
		void *(*cvar_malloc)(size_t size), void (*cvar_free)(void *cvar_ptr))
{
	cvar_token_t *list_head;;
	cvar_token_t *t;
	handle_t handle;
	handle_t *state = NULL;
	int ret = 0;

	cvar_trace("entry");

	/* Tokenize parameters supplied by filebench. */
	list_head = NULL;
	ret = tokenize(cvar_parameters, DEFAULT_PARAMETER_DELIMITER,
			DEFAULT_KEY_VALUE_DELIMITER, &list_head);
	if (ret)
		goto out;

	/* Get the value of mean and sigma. */
	t = find_token(list_head, RN_MEAN);
	if (t && t->value) {
		t->used = 1;
		handle.mean = atof(t->value);
	} else
		handle.mean = RN_MEAN_DEFAULT;

	t = find_token(list_head, RN_SIGMA);
	if (t && t->value) {
		t->used = 1;
		handle.sigma = atof(t->value);
	} else
		handle.sigma = RN_SIGMA_DEFAULT;

	cvar_trace("mean = %lf, sigma = %lf", handle.mean, handle.sigma);

	t = unused_tokens(list_head);
	if (t) {
		cvar_log_error("Unsupported parameter %s", t->key);
		goto out;
	}

	/* Seed the state. */
	mts_goodseed(&handle.state);

	/* All set. Now allocate space for the handle in the shared segment and
	 * copy the state over. */
	state = (handle_t *) cvar_malloc(sizeof(handle_t));
	if (!state) {
		cvar_log_error("Out of memory");
		goto out;
	}

	*state = handle;

out:
	free_tokens(list_head);

	cvar_trace("exit");
	return state;
}
Exemplo n.º 2
0
void *cvar_alloc_handle(const char *cvar_parameters,
		void *(*cvar_malloc)(size_t size), void (*cvar_free)(void *cvar_ptr))
{
	cvar_token_t *list_head;;
	cvar_token_t *t;
	handle_t handle;
	handle_t *state = NULL;
	int ret = 0;

	cvar_trace("entry");

	/* Tokenize parameters supplied by filebench. */
	list_head = NULL;
	ret = tokenize(cvar_parameters, DEFAULT_PARAMETER_DELIMITER,
			DEFAULT_KEY_VALUE_DELIMITER, &list_head);
	if (ret)
		goto out;

	/* Get the value of lower, upper and mode. */
	t = find_token(list_head, RT_LOWER);
	if (t && t->value) {
		t->used = 1;
		handle.lower = atof(t->value);
	} else
		handle.lower = RT_LOWER_DEFAULT;

	t = find_token(list_head, RT_UPPER);
	if (t && t->value) {
		t->used = 1;
		handle.upper = atof(t->value);
	} else
		handle.upper = RT_UPPER_DEFAULT;

	t = find_token(list_head, RT_MODE);
	if (t && t->value) {
		t->used = 1;
		handle.mode = atof(t->value);
	} else
		handle.mode = RT_MODE_DEFAULT;

	cvar_trace("lower = %lf, upper = %lf, mode = %lf", handle.lower,
			handle.upper, handle.mode);

	/* Validate parameters. */
	if (handle.upper < handle.lower) {
		cvar_log_error("Invalid parameter values: lower = %lf and upper = %lf. "
				"upper must be greater than lower", handle.lower, handle.upper);
		goto out;
	}

	if ((handle.mode > handle.upper) || (handle.mode < handle.lower)) {
		cvar_log_error("Invalid parameter values: lower = %lf, mode = %lf and "
				"upper = %lf. mode must be between lower and upper",
				handle.lower, handle.mode, handle.upper);
		goto out;
	}

	/* Check if there are unused tokens. */
	t = unused_tokens(list_head);
	if (t) {
		cvar_log_error("Unsupported parameter %s", t->key);
		goto out;
	}

	/* Seed the state. */
	mts_goodseed(&handle.state);

	/* All set. Now allocate space for the handle in the shared segment and
	 * copy the state over. */
	state = (handle_t *) cvar_malloc(sizeof(handle_t));
	if (!state) {
		cvar_log_error("Out of memory");
		goto out;
	}

	*state = handle;

out:
	free_tokens(list_head);

	cvar_trace("exit");
	return state;
}
Exemplo n.º 3
0
void *cvar_alloc_handle(const char *cvar_parameters,
		void *(*cvar_malloc)(size_t size), void (*cvar_free)(void *cvar_ptr))
{
	cvar_token_t *list_head;;
	cvar_token_t *t;
	handle_t handle;
	handle_t *state = NULL;
	int ret = 0;

	cvar_trace("entry");

	/* Tokenize parameters supplied by filebench. */
	list_head = NULL;
	ret = tokenize(cvar_parameters, DEFAULT_PARAMETER_DELIMITER,
			DEFAULT_KEY_VALUE_DELIMITER, &list_head);
	if (ret)
		goto out;

	/* Get the value of shape and rate. */
	t = find_token(list_head, RER_SHAPE);
	if (t && t->value) {
		t->used = 1;
		handle.shape = atoi(t->value);
	} else
		handle.shape = RER_SHAPE_DEFAULT;

	t = find_token(list_head, RER_RATE);
	if (t && t->value) {
		t->used = 1;
		handle.rate = atof(t->value);
	} else
		handle.rate = RER_RATE_DEFAULT;

	cvar_trace("shape = %d, rate = %lf", handle.shape, handle.rate);

	/* Validate parameters. */
	if (handle.shape < 0) {
		cvar_log_error("Invalid parameter value: shape = %d. shape is a "
				"non-zero positive integer", handle.shape);
		goto out;
	}

	if (handle.rate < 0) {
		cvar_log_error("Invalid parameter value: rate = %lf. rate is a "
				"non-zero positive rational number", handle.rate);
		goto out;
	}

	t = unused_tokens(list_head);
	if (t) {
		cvar_log_error("Unsupported parameter %s", t->key);
		goto out;
	}

	/* Seed the state. */
	mts_goodseed(&handle.state);

	/* All set. Now allocate space for the handle in the shared segment and
	 * copy the state over. */
	state = (handle_t *) cvar_malloc(sizeof(handle_t));
	if (!state) {
		cvar_log_error("Out of memory");
		goto out;
	}

	*state = handle;

out:
	free_tokens(list_head);

	cvar_trace("exit");
	return state;
}