/** @brief initialize common datastructures to all models */ surf_model_t surf_model_init(void) { s_surf_action_t action; surf_model_t model = xbt_new0(s_surf_model_t, 1); model->model_private = xbt_new0(s_surf_model_private_t, 1); model->states.ready_action_set = xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.running_action_set = xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.failed_action_set = xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->states.done_action_set = xbt_swag_new(xbt_swag_offset(action, state_hookup)); model->action_unref = int_die_impossible_paction; model->action_cancel = void_die_impossible_paction; model->action_recycle = void_die_impossible_paction; model->action_state_get = surf_action_state_get; model->action_state_set = surf_action_state_set; model->action_get_start_time = surf_action_get_start_time; model->action_get_finish_time = surf_action_get_finish_time; model->action_data_set = surf_action_data_set; model->model_private->modified_set = NULL; model->model_private->action_heap = NULL; model->model_private->update_mechanism = UM_UNDEFINED; model->model_private->selective_update = 0; return model; }
/********************************* Host **************************************/ msg_host_t __MSG_host_create(smx_host_t workstation) { const char *name = SIMIX_host_get_name(workstation); msg_host_priv_t host = xbt_new0(s_msg_host_priv_t, 1); s_msg_vm_t vm; // simply to compute the offset host->vms = xbt_swag_new(xbt_swag_offset(vm,host_vms_hookup)); #ifdef MSG_USE_DEPRECATED int i; char alias[MAX_ALIAS_NAME + 1] = { 0 }; /* buffer used to build the key of the mailbox */ if (msg_global->max_channel > 0) host->mailboxes = xbt_new0(msg_mailbox_t, msg_global->max_channel); for (i = 0; i < msg_global->max_channel; i++) { sprintf(alias, "%s:%d", name, i); /* the key of the mailbox (in this case) is build from the name of the host and the channel number */ host->mailboxes[i] = MSG_mailbox_new(alias); memset(alias, 0, MAX_ALIAS_NAME + 1); } #endif xbt_lib_set(host_lib,name,MSG_HOST_LEVEL,host); return xbt_lib_get_elm_or_null(host_lib, name); }
static void surf_new_model_init_internal(void) { s_surf_action_t action; XBT_DEBUG("surf_new_model_model_init_internal"); surf_new_model = surf_model_init(); new_model_running_action_set_that_does_not_need_being_checked = xbt_swag_new(xbt_swag_offset(action, state_hookup)); surf_new_model->name = "New Model"; surf_new_model->action_unref = new_model_action_unref; surf_new_model->action_cancel = new_model_action_cancel; surf_new_model->action_state_set = new_model_action_state_set; surf_new_model->model_private->finalize = new_model_finalize; surf_new_model->model_private->update_actions_state = new_model_update_actions_state; surf_new_model->model_private->share_resources = new_model_share_resources; surf_new_model->model_private->resource_used = new_model_resource_used; surf_new_model->model_private->update_resource_state = new_model_resources_state; surf_new_model->suspend = new_model_action_suspend; surf_new_model->resume = new_model_action_resume; surf_new_model->is_suspended = new_model_action_is_suspended; surf_new_model->set_max_duration = new_model_action_set_max_duration; surf_new_model->set_priority = new_model_action_set_priority; surf_new_model->extension.new_model.fct = new_model_action_fct; surf_new_model->extension.new_model.create_resource = new_model_create_resource; if (!new_model_maxmin_system) { new_model_maxmin_system = lmm_system_new(new_model_selective_update); } }
Mutex::Mutex() : mutex_(this) { XBT_IN("(%p)", this); // Useful to initialize sleeping swag: simgrid::simix::ActorImpl p; this->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); XBT_OUT(); }
/** * \brief Initialize a condition. * * Allocates and creates the data for the condition. * It have to be called before the use of the condition. * \return A condition */ smx_cond_t SIMIX_cond_init(void) { XBT_IN("()"); s_smx_process_t p; smx_cond_t cond = xbt_new0(s_smx_cond_t, 1); cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); cond->mutex = NULL; XBT_OUT(); return cond; }
StorageN11Model::StorageN11Model() : StorageModel() { Action *action = nullptr; XBT_DEBUG("surf_storage_model_init_internal"); storage_running_action_set_that_does_not_need_being_checked = xbt_swag_new(xbt_swag_offset(*action, stateHookup_)); if (!maxminSystem_) { maxminSystem_ = lmm_system_new(storage_selective_update); } }
/** * \brief Initialize a condition. * * Allocates and creates the data for the condition. * It have to be called before the use of the condition. * \return A condition */ smx_cond_t SIMIX_cond_init() { XBT_IN("()"); simgrid::simix::ActorImpl p; smx_cond_t cond = new s_smx_cond(); cond->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); cond->refcount_ = 1; XBT_OUT(); return cond; }
void SIMIX_request_init(void) { s_smx_req_t req; int i, nthreads = SIMIX_context_get_nthreads(); req_lists = xbt_new0(xbt_swag_t, nthreads); for(i=0; i < nthreads; i++) req_lists[i] = xbt_swag_new(xbt_swag_offset(req, reqtable_hookup)); }
/** @brief Initialize a semaphore */ smx_sem_t SIMIX_sem_init(unsigned int value) { XBT_IN("(%u)",value); s_smx_process_t p; smx_sem_t sem = xbt_new0(s_smx_sem_t, 1); sem->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); sem->value = value; XBT_OUT(); return sem; }
/** * \brief Initialize a mutex. * * Allocs and creates the data for the mutex. * \return A mutex */ smx_mutex_t SIMIX_mutex_init(void) { XBT_IN("()"); s_smx_process_t p; /* useful to initialize sleeping swag */ smx_mutex_t mutex = xbt_new0(s_smx_mutex_t, 1); mutex->locked = 0; mutex->sleeping = xbt_swag_new(xbt_swag_offset(p, synchro_hookup)); XBT_OUT(); return mutex; }
XBT_TEST_UNIT("basic", test_swag_basic, "Basic usage") { shmurtz_t obj1, obj2, obj; xbt_swag_t setA, setB; obj1 = xbt_new0(s_shmurtz_t, 1); obj2 = xbt_new0(s_shmurtz_t, 1); obj1->name = "Obj 1"; obj2->name = "Obj 2"; xbt_test_add("Basic usage"); xbt_test_log("%p %p %ld\n", obj1, &(obj1->setB), (long) ((char *) &(obj1->setB) - (char *) obj1)); setA = xbt_swag_new(xbt_swag_offset(*obj1, setA)); setB = xbt_swag_new(xbt_swag_offset(*obj1, setB)); xbt_swag_insert(obj1, setA); xbt_swag_insert(obj1, setB); xbt_swag_insert(obj2, setA); xbt_swag_insert(obj2, setB); xbt_test_assert(xbt_swag_remove(NULL, setB) == NULL); xbt_test_assert(xbt_swag_remove(obj1, setB) == obj1); /* xbt_test_assert(xbt_swag_remove(obj2, setB) == obj2); */ xbt_test_add("Traverse set A"); xbt_swag_foreach(obj, setA) { xbt_test_log("Saw: %s", obj->name); }