Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Code refactoring on CPP
[simgrid.git] / src / cxx / Process.cxx
index a4dab1a..0ee57ed 100644 (file)
@@ -547,14 +547,27 @@ namespace SimGrid
                throw(HostNotFoundException)\r
                {\r
                        smx_process_t nativeCurrentProcess = NULL;\r
-                       nativeProcess = xbt_new0(s_smx_process_t, 1);\r
+                       \r
+                       // allocate the native process\r
+                       this->nativeProcess = xbt_new0(s_smx_process_t, 1);\r
+                       \r
+                       // allocate the simulation data of the native process\r
                        smx_simdata_process_t simdata = xbt_new0(s_smx_simdata_process_t, 1);\r
+                       \r
+                       // try to retrieve the host where to createt the process from its name\r
                        smx_host_t nativeHost = SIMIX_host_get_by_name(rHost.getName());\r
                        \r
-                       throw HostNotFoundException(rHost.getName());\r
+                       if(!nativeHost)\r
+                               throw HostNotFoundException(rHost.getName());\r
                        \r
+                       // realloc the list of the argument to add the pointer to this process instance at the end\r
                        argv = (char**)realloc(argc + 1, sizeo(char*));\r
                        \r
+                       // add the pointer to this instance at the end of the list of the arguments of the process\r
+                       // so the static method Process::run() (passed as argument of the MSG function xbt_context_new())\r
+                       // can retrieve the concerned process object by the run\r
+                       // so Process::run() can call the method main() of the good process\r
+                       // for more detail see Process::run() method\r
                        argv[argc] = (char*)this;\r
                        \r
                        // Simulator Data\r
@@ -563,28 +576,30 @@ namespace SimGrid
                        simdata->cond = NULL;\r
                        simdata->argc = argc;\r
                        simdata->argv = argv;\r
+                       \r
+                       // create the context of the process.\r
                        simdata->context = xbt_context_new(name, Process::run, NULL, NULL, simix_global->cleanup_process_function, nativeProcess, simdata->argc, simdata->argv);\r
                        \r
                        /* Process structure */\r
-                       nativeProcess->name = xbt_strdup(name);\r
-                       nativeProcess->simdata = simdata;\r
+                       this->nativeProcess->name = xbt_strdup(name);\r
+                       this->nativeProcess->simdata = simdata;\r
                        \r
                        // Set process data\r
-                       nativeProcess->data = NULL;\r
+                       this->nativeProcess->data = NULL;\r
                        \r
                        // Set process properties\r
                        simdata->properties = NULL;\r
                        \r
-                       xbt_swag_insert(nativeProcess, nativeHost->simdata->process_list);\r
+                       xbt_swag_insert(this->nativeProcess, nativeHost->simdata->process_list);\r
                        \r
                        /* fix current_process, about which xbt_context_start mocks around */\r
                        nativeCurrentProcess = simix_global->current_process;\r
-                       xbt_context_start(nativeProcess->simdata->context);\r
+                       xbt_context_start(this->nativeProcess->simdata->context);\r
                        simix_global->current_process = nativeCurrentProcess;\r
                        \r
-                       xbt_swag_insert(nativeProcess, simix_global->process_list);\r
-                       DEBUG2("Inserting %s(%s) in the to_run list", nativeProcess->name, nativeHost->name);\r
-                       xbt_swag_insert(nativeProcess, simix_global->process_to_run);\r
+                       xbt_swag_insert(this->nativeProcess, simix_global->process_list);\r
+                       DEBUG2("Inserting %s(%s) in the to_run list", this->nativeProcess->name, nativeHost->name);\r
+                       xbt_swag_insert(this->nativeProcess, simix_global->process_to_run);\r
                }\r
                \r
                Process& Process::fromNativeProcess(m_process_t nativeProcess)\r
@@ -594,9 +609,10 @@ namespace SimGrid
                \r
                int Process::run(int argc, char** argv)\r
                {\r
-                       Process* process =(Process*)argv[argc];\r
                        \r
-                       return process->main(argc, argv);\r
+                       // the last argument of the process is the pointer to the process to run\r
+                       // for mor detail see Process::create() method\r
+                       return ((Process*)argv[argc])->main(argc, argv);\r
                }\r
                \r
        } // namespace Msg\r