/** Example launcher. You can use it or provide your own launcher, as you wish
* @param args
- * @throws MsgException
*/
public static void main(String[]args) {
/* initialize the MSG simulation. Must be done before anything else (even logging). */
/**
* This method actually creates and run the process.
* It is a noop if the process is already launched.
- * @throws HostNotFoundException
*/
public final void start() {
if (bind == 0)
if (not host)
THROWF(arg_error, 0, "Host '%s' unknown", process_host);
process.host = process_host;
-
- process.argc = 1 + xbt_dynar_length(arguments);
- process.argv = static_cast<const char**>(xbt_new(const char*, process.argc + 1));
- process.argv[0] = xbt_strdup(process_function);
+ process.args.push_back(process_function);
/* add arguments */
unsigned int i;
char *arg;
xbt_dynar_foreach(arguments, i, arg) {
- process.argv[i + 1] = xbt_strdup(arg);
+ process.args.push_back(arg);
}
- process.argv[process.argc] = nullptr;
// Check we know how to handle this function name:
simgrid::simix::ActorCodeFactory& parse_code = SIMIX_get_actor_code_factory(process_function);
"stop_offset (%zu) should be lower than its successor start offset (%zu)", stop_offset, shared_block_offsets[2*i_block+2]);
size_t start_block_offset = ALIGN_UP(start_offset, smpi_shared_malloc_blocksize);
size_t stop_block_offset = ALIGN_DOWN(stop_offset, smpi_shared_malloc_blocksize);
- for (unsigned block_id=0, i = start_block_offset / smpi_shared_malloc_blocksize; i < stop_block_offset / smpi_shared_malloc_blocksize; block_id++, i++) {
- XBT_DEBUG("\t\tglobal shared allocation, mmap block offset %u", block_id);
- void* pos = (void*)((unsigned long)mem + i * smpi_shared_malloc_blocksize);
+ for (size_t offset = start_block_offset; offset < stop_block_offset; offset += smpi_shared_malloc_blocksize) {
+ XBT_DEBUG("\t\tglobal shared allocation, mmap block offset %zx", offset);
+ void* pos = (void*)((unsigned long)mem + offset);
void* res = mmap(pos, smpi_shared_malloc_blocksize, PROT_READ | PROT_WRITE, mmap_flag,
huge_fd, 0);
xbt_assert(res == pos, "Could not map folded virtual memory (%s). Do you perhaps need to increase the "
, attach_(attach)
{
content_ = parseContent(content_name);
- turnOn();
+ StorageImpl::turnOn();
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
constraintRead_ = lmm_constraint_new(maxminSystem, this, bread);
constraintWrite_ = lmm_constraint_new(maxminSystem, this, bwrite);
}
maxminSystem_ = lmm_system_new(selectiveUpdate_);
- loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
+ loopback_ = NetworkCm02Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
if (getUpdateMechanism() == UM_LAZY) {
modifiedSet_ = new ActionLmmList();
, hostModel_(hmodel)
{
maxminSystem_ = sys;
- loopback_ = createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
+ loopback_ = NetworkL07Model::createLink("__loopback__", 498000000, 0.000015, SURF_LINK_FATPIPE);
}
NetworkL07Model::~NetworkL07Model()
double kill_time = process->kill_time;
int auto_restart = process->on_failure == SURF_ACTOR_ON_FAILURE_DIE ? 0 : 1;
- std::vector<std::string> args(process->argv, process->argv + process->argc);
- std::function<void()> code = factory(std::move(args));
+ std::string process_name = process->args[0];
+ std::function<void()> code = factory(std::move(process->args));
std::shared_ptr<std::map<std::string, std::string>> properties(process->properties);
smx_process_arg_t arg = nullptr;
arg = new simgrid::simix::ProcessArg();
- arg->name = std::string(process->argv[0]);
+ arg->name = process_name;
arg->code = code;
arg->data = nullptr;
arg->host = host;
if (start_time > SIMIX_get_clock()) {
arg = new simgrid::simix::ProcessArg();
- arg->name = std::string(process->argv[0]);
+ arg->name = process_name;
arg->code = std::move(code);
arg->data = nullptr;
arg->host = host;
};
struct s_sg_platf_process_cbarg_t {
- const char** argv = nullptr;
- int argc = 0;
+ std::vector<std::string> args;
std::map<std::string, std::string>* properties = nullptr;
const char* host = nullptr;
const char* function = nullptr;
current_property_set = nullptr;
}
-static int argc;
-static char **argv;
+static std::vector<std::string> arguments;
void STag_surfxml_process()
{
void STag_surfxml_actor()
{
ZONE_TAG = 0;
- argc = 1;
- argv = xbt_new(char *, 1);
- argv[0] = xbt_strdup(A_surfxml_actor_function);
+ arguments.assign(1, A_surfxml_actor_function);
xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
}
actor.properties = current_property_set;
current_property_set = nullptr;
- actor.argc = argc;
- actor.argv = (const char **)argv;
+ actor.args.swap(arguments);
actor.host = A_surfxml_actor_host;
actor.function = A_surfxml_actor_function;
actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
}
sg_platf_new_process(&actor);
-
- for (int i = 0; i != argc; ++i)
- xbt_free(argv[i]);
- xbt_free(argv);
- argv = nullptr;
}
void STag_surfxml_argument(){
- argc++;
- argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
- argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
+ arguments.push_back(A_surfxml_argument_value);
}
void STag_surfxml_model___prop(){
{
xbt_dynar_reset(dynar);
if (dynar)
- free(dynar->data);
+ xbt_free(dynar->data);
}
/** @brief Destructor of the structure not touching to the content
{
if (dynar && *dynar) {
xbt_dynar_t d = *dynar;
- free(d->data);
- free(d);
+ xbt_free(d->data);
+ xbt_free(d);
*dynar = nullptr;
}
}
xbt_dynar_shrink(dynar, 1);
memset(xbt_dynar_push_ptr(dynar), 0, dynar->elmsize);
res = dynar->data;
- free(dynar);
+ xbt_free(dynar);
return res;
}
snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(not strcmp(buf, s2), "The retrieved value is not the same than the injected one (%s!=%s)", buf, s2);
- free(s2);
+ xbt_free(s2);
}
xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
snprintf(buf,1023, "%d", cpt);
xbt_dynar_pop(d, &s2);
xbt_test_assert(not strcmp(buf, s2), "The retrieved value is not the same than the injected one (%s!=%s)", buf, s2);
- free(s2);
+ xbt_free(s2);
}
/* 4. Free the resources */
xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
xbt_dynar_shift(d, &s2);
xbt_test_assert(not strcmp(buf, s2),
"The retrieved value is not the same than the injected one at the begining (%s!=%s)", buf, s2);
- free(s2);
+ xbt_free(s2);
}
for (int cpt = (NB_ELEM / 5) - 1; cpt >= 0; cpt--) {
snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(not strcmp(buf, s2),
"The retrieved value is not the same than the injected one in the middle (%s!=%s)", buf, s2);
- free(s2);
+ xbt_free(s2);
}
for (int cpt = NB_ELEM / 2; cpt < NB_ELEM; cpt++) {
snprintf(buf,1023, "%d", cpt);
xbt_dynar_shift(d, &s2);
xbt_test_assert(not strcmp(buf, s2),
"The retrieved value is not the same than the injected one at the end (%s!=%s)", buf, s2);
- free(s2);
+ xbt_free(s2);
}
xbt_dynar_free(&d); /* This code is used both as example and as regression test, so we try to */
xbt_dynar_free(&d); /* free the struct twice here to check that it's ok, but freeing it only once */
snprintf(buf,1023, "%d", cpt);
xbt_dynar_remove_at(d, 2 * (NB_ELEM / 5), &s2);
xbt_test_assert(not strcmp(buf, s2), "Remove a bad value. Got %s, expected %s", s2, buf);
- free(s2);
+ xbt_free(s2);
}
xbt_dynar_free(&d); /* end_of_doxygen */
}
void _xbt_throw(char* message, xbt_errcat_t errcat, int value, const char* file, int line, const char* func)
{
xbt_ex e(simgrid::xbt::ThrowPoint(file, line, func), message);
- free(message);
+ xbt_free(message);
e.category = errcat;
e.value = value;
throw e;
{
simgrid::xbt::installExceptionHandler();
- if (xbt_initialized) {
- xbt_initialized++;
+ xbt_initialized++;
+ if (xbt_initialized > 1) {
XBT_DEBUG("XBT has been initialized %d times.", xbt_initialized);
return;
}
}
/* these two functions belong to xbt/sysdep.h, which have no corresponding .c file */
-/** @brief like free, but you can be sure that it is a function */
+/** @brief like xbt_free, but you can be sure that it is a function */
void xbt_free_f(void *p)
{
- free(p);
+ xbt_free(p);
}
/** @brief should be given a pointer to pointer, and frees the second one */
void xbt_free_ref(void *d)
{
- free(*(void **) d);
+ xbt_free(*(void**)d);
}
/** @brief Kill the program in silence */
char *q=xbt_strdup(p);
xbt_dynar_push(res,&q);
}
- free(str_to_free);
+ xbt_free(str_to_free);
xbt_dynar_shrink(res, 0);
xbt_dynar_free(&parsed);
return res;