Пример #1
0
/** \ingroup m_process_management
 * \brief Creates and runs a new #m_process_t.
 *
 * Does exactly the same as #MSG_process_create_with_arguments but without
   providing standard arguments (\a argc, \a argv, \a start_time, \a kill_time).
 * \sa MSG_process_create_with_arguments
 */
m_process_t MSG_process_create(const char *name,
                               xbt_main_func_t code, void *data,
                               m_host_t host)
{
  return MSG_process_create_with_environment(name, code, data, host, -1,
                                             NULL, NULL);
}
Пример #2
0
m_process_t MSG_process_create_with_arguments(const char *name,
                                              xbt_main_func_t code,
                                              void *data, m_host_t host,
                                              int argc, char **argv)
{
  return MSG_process_create_with_environment(name, code, data, host,
                                             argc, argv, NULL);
}
Пример #3
0
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
void MSG_process_create_from_SIMIX(smx_process_t* process, const char *name,
                                    xbt_main_func_t code, void *data,
                                    const char *hostname, int argc, char **argv,
                                    xbt_dict_t properties)
{
  m_host_t host = MSG_get_host_by_name(hostname);
  m_process_t p = MSG_process_create_with_environment(name, code, data,
                                                      host, argc, argv,
                                                      properties);
  *((m_process_t*) process) = p;
}
Пример #4
0
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
smx_actor_t MSG_process_create_from_SIMIX(
  const char *name, std::function<void()> code, void *data, sg_host_t host,
  double kill_time, xbt_dict_t properties,
  int auto_restart, smx_actor_t parent_process)
{
  msg_process_t p = MSG_process_create_with_environment(name, std::move(code), data, host, properties);
  if (p) {
    MSG_process_set_kill_time(p,kill_time);
    MSG_process_auto_restart_set(p,auto_restart);
  }
  return p;
}
Пример #5
0
/** \ingroup m_process_management
 * \brief Creates and runs a new #msg_process_t.

 * A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
 * the corresponding thread) is created, and put in the list of ready process.
 * \param name a name for the object. It is for user-level information and can be nullptr.
 * \param code is a function describing the behavior of the process. It should then only use functions described
 * in \ref m_process_management (to create a new #msg_process_t for example),
   in \ref m_host_management (only the read-only functions i.e. whose name contains the word get),
   in \ref m_task_management (to create or destroy some #msg_task_t for example) and
   in \ref msg_task_usage (to handle file transfers and task processing).
 * \param data a pointer to any data one may want to attach to the new object.  It is for user-level information and
 *        can be nullptr. It can be retrieved with the function \ref MSG_process_get_data.
 * \param host the location where the new process is executed.
 * \param argc first argument passed to \a code
 * \param argv second argument passed to \a code. WARNING, these strings are freed by the SimGrid kernel when the
 *             process exits, so they cannot be static nor shared between several processes.
 * \param properties list a properties defined for this process
 * \see msg_process_t
 * \return The new corresponding object.
 */
msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
                                                  int argc, char **argv, xbt_dict_t properties)
{
  std::function<void()> function;
  if (code)
    function = simgrid::xbt::wrapMain(code, argc, const_cast<const char*const*>(argv));
  msg_process_t res = MSG_process_create_with_environment(name,
    std::move(function), data, host, properties);
  for (int i = 0; i != argc; ++i)
    xbt_free(argv[i]);
  xbt_free(argv);
  return res;
}
Пример #6
0
/* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */
void MSG_process_create_from_SIMIX(smx_process_t* process, const char *name,
                                    xbt_main_func_t code, void *data,
                                    const char *hostname, double kill_time, int argc, char **argv,
                                    xbt_dict_t properties, int auto_restart)
{
  msg_host_t host = MSG_get_host_by_name(hostname);
  msg_process_t p = MSG_process_create_with_environment(name, code, data,
                                                      host, argc, argv,
                                                      properties);
  if (p) {
    MSG_process_set_kill_time(p,kill_time);
    MSG_process_auto_restart_set(p,auto_restart);
  }
  *((msg_process_t*) process) = p;
}
Пример #7
0
/** \ingroup m_process_management
 * \brief Creates and runs a new #msg_process_t.
 *
 * Does exactly the same as #MSG_process_create_with_arguments but without providing standard arguments
 * (\a argc, \a argv, \a start_time, \a kill_time).
 * \sa MSG_process_create_with_arguments
 */
msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host)
{
  return MSG_process_create_with_environment(name, code, data, host, 0, nullptr, nullptr);
}
Пример #8
0
JNIEXPORT void JNICALL
Java_org_simgrid_msg_Process_create(JNIEnv * env,
                                    jobject jprocess_arg,
                                    jobject jhostname)
{


  jobject jprocess;             /* the global reference to the java process instance    */
  jstring jname;                /* the name of the java process instance                */
  const char *name;             /* the C name of the process                            */
  const char *hostname;
  msg_process_t process;          /* the native process to create                         */
  msg_host_t host;                /* Where that process lives */

  hostname = (*env)->GetStringUTFChars(env, jhostname, 0);

  /* get the name of the java process */
  jname = jprocess_get_name(jprocess_arg, env);
  if (!jname) {
    jxbt_throw_null(env,
            xbt_strdup("Internal error: Process name cannot be NULL"));
    return;
  }

  /* bind/retrieve the msg host */
  host = MSG_host_by_name(hostname);

  if (!(host)) {    /* not bound */
    jxbt_throw_host_not_found(env, hostname);
    return;
  }

  /* create a global java process instance */
  jprocess = jprocess_new_global_ref(jprocess_arg, env);
  if (!jprocess) {
    jxbt_throw_jni(env, "Can't get a global ref to the java process");
    return;
  }

  /* build the C name of the process */
  name = (*env)->GetStringUTFChars(env, jname, 0);
  name = xbt_strdup(name);

  /* Retrieve the kill time from the process */
  jdouble jkill = (*env)->GetDoubleField(env, jprocess, jprocess_field_Process_killTime);
  /* Actually build the MSG process */
  process = MSG_process_create_with_environment(name,
						(xbt_main_func_t) jprocess,
						/*data*/ jprocess,
						host,
						/*argc, argv, properties*/
						0,NULL,NULL);
  MSG_process_set_kill_time(process, (double)jkill);
  /* bind the java process instance to the native process */
  jprocess_bind(jprocess, process, env);

  /* release our reference to the process name (variable name becomes invalid) */
  //FIXME : This line should be uncommented but with mac it doesn't work. BIG WARNING
  //(*env)->ReleaseStringUTFChars(env, jname, name);
  (*env)->ReleaseStringUTFChars(env, jhostname, hostname);

  /* sets the PID and the PPID of the process */
  (*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
  (*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
  /* sets the Host of the process */
  jobject jhost = Java_org_simgrid_msg_Host_getByName(env,NULL,jhostname);

  (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
}