*/
MSG_error_t MSG_task_execute(m_task_t task)
{
- MSG_RETURN(MSG_OK);
+ simdata_task_t simdata = NULL;
+
+ CHECK_HOST();
+
+ simdata = task->simdata;
+ xbt_assert0((!simdata->compute)&&(task->simdata->using==1),
+ "This taks is executed somewhere else. Go fix your code!");
+ simdata->using++;
+ SIMIX_mutex_lock(simdata->mutex);
+ simdata->compute = SIMIX_action_execute(SIMIX_host_self(), task->name, simdata->computation_amount);
+ SIMIX_action_set_priority(simdata->compute, simdata->priority);
+
+ SIMIX_register_action_to_condition(simdata->compute, simdata->cond);
+ SIMIX_register_condition_to_action(simdata->compute, simdata->cond);
+
+ SIMIX_cond_wait(simdata->cond, simdata->mutex);
+
+ SIMIX_mutex_unlock(simdata->mutex);
+ simdata->using--;
+
+// MSG_RETURN(MSG_OK);
+ return MSG_OK;
}
void __MSG_task_execute(m_process_t process, m_task_t task)
#ifndef METASIMGRID_PRIVATE_H
#define METASIMGRID_PRIVATE_H
+#include <stdio.h>
#include "msg/msg.h"
#include "simix/simix.h"
#include "xbt/fifo.h"
#define PROCESS_SET_ERRNO(val) (MSG_process_self()->simdata->last_errno=val)
#define PROCESS_GET_ERRNO() (MSG_process_self()->simdata->last_errno)
-#define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
+//#define MSG_RETURN(val) do {PROCESS_SET_ERRNO(val);return(val);} while(0)
+#define MSG_RETURN(val) do {return(val);} while(0)
/* #define CHECK_ERRNO() ASSERT((PROCESS_GET_ERRNO()!=MSG_HOST_FAILURE),"Host failed, you cannot call this function.") */
-#define CHECK_HOST() xbt_assert0(surf_workstation_resource->extension_public-> \
- get_state(MSG_host_self()->simdata->host)==SURF_CPU_ON,\
+#define CHECK_HOST() xbt_assert0(SIMIX_host_get_state(SIMIX_host_self())==1,\
"Host failed, you cannot call this function.")
m_host_t __MSG_host_create(smx_host_t workstation, void *data);
void __MSG_display_process_status(void);
+m_process_t __MSG_process_create_with_arguments(const char *name,
+ m_process_code_t code, void *data,
+ char * hostname, int argc, char **argv);
#endif
static void MSG_process_cleanup(void *arg)
{
- xbt_die("not implemented yet");
+ /* arg is a pointer to a simix process, we can get the msg process with the field data */
+ m_process_t proc = ((smx_process_t)arg)->data;
+ printf("remove MSG process %s\n", proc->name);
+ xbt_fifo_remove(msg_global->process_list, proc);
+ SIMIX_process_cleanup(arg);
+ free(proc->name);
+ proc->name = NULL;
+ free(proc->simdata);
+ proc->simdata = NULL;
+ free(proc);
+
return;
}
* \see m_process_t
* \return The new corresponding object.
*/
+
+
+
+m_process_t __MSG_process_create_with_arguments(const char *name,
+ m_process_code_t code, void *data,
+ char * hostname, int argc, char **argv)
+{
+ m_host_t host = MSG_get_host_by_name(hostname);
+ return MSG_process_create_with_arguments(name,code,data,host,argc,argv);
+}
+
m_process_t MSG_process_create_with_arguments(const char *name,
m_process_code_t code, void *data,
m_host_t host, int argc, char **argv)
{
simdata_process_t simdata = xbt_new0(s_simdata_process_t,1);
m_process_t process = xbt_new0(s_m_process_t,1);
-
xbt_assert0(((code != NULL) && (host != NULL)), "Invalid parameters");
/* Simulator Data */
simdata->argc = argc;
simdata->argv = argv;
simdata->smx_process = SIMIX_process_create_with_arguments(name, (smx_process_code_t)code,
- (void*)process, host->simdata->host, argc, argv );
+ (void*)process, host->name, argc, argv, MSG_process_cleanup );
if (SIMIX_process_self()) {
simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data);
process->simdata = simdata;
process->data = data;
+ xbt_fifo_unshift(msg_global->process_list, process);
+
return process;
}
*/
void MSG_process_kill(m_process_t process)
{
- xbt_die("not implemented yet");
+
+ /*
+ int i;
+ simdata_process_t p_simdata = process->simdata;
+ simdata_host_t h_simdata= p_simdata->host->simdata;
+ int _cursor;
+ m_process_t proc = NULL;
+
+ DEBUG3("Killing %s(%d) on %s",process->name, p_simdata->PID, p_simdata->host->name);
+
+ for (i=0; i<msg_global->max_channel; i++) {
+ if (h_simdata->sleeping[i] == process) {
+ h_simdata->sleeping[i] = NULL;
+ break;
+ }
+ }
+
+ if(p_simdata->waiting_task) {
+ xbt_dynar_foreach(p_simdata->waiting_task->simdata->sleeping,_cursor,proc) {
+ if(proc==process)
+ xbt_dynar_remove_at(p_simdata->waiting_task->simdata->sleeping,_cursor,&proc);
+ }
+ if(p_simdata->waiting_task->simdata->compute)
+ surf_workstation_resource->common_public->
+ action_free(p_simdata->waiting_task->simdata->compute);
+ else if (p_simdata->waiting_task->simdata->comm) {
+ surf_workstation_resource->common_public->
+ action_change_state(p_simdata->waiting_task->simdata->comm,SURF_ACTION_FAILED);
+ surf_workstation_resource->common_public->
+ action_free(p_simdata->waiting_task->simdata->comm);
+ } else {
+ xbt_die("UNKNOWN STATUS. Please report this bug.");
+ }
+ }
+
+ if ((i==msg_global->max_channel) && (process!=MSG_process_self()) &&
+ (!p_simdata->waiting_task)) {
+ xbt_die("UNKNOWN STATUS. Please report this bug.");
+ }
+*/
+ xbt_fifo_remove(msg_global->process_list,process);
+ SIMIX_process_kill(process->simdata->smx_process);
+
return;
}
*/
MSG_error_t MSG_process_change_host(m_process_t process, m_host_t host)
{
- xbt_die("not implemented yet");
+ xbt_die("MSG_process_change_host - not implemented yet - maybe useless function");
return MSG_OK;
}
*/
m_process_t MSG_process_from_PID(int PID)
{
+ xbt_fifo_item_t i = NULL;
+ m_process_t process = NULL;
+ xbt_fifo_foreach(msg_global->process_list,i,process,m_process_t) {
+ if(MSG_process_get_PID(process) == PID) return process;
+ }
return NULL;
}
*/
m_process_t MSG_process_self(void)
{
- return (m_process_t)SIMIX_process_self()->data;
+ smx_process_t proc = SIMIX_process_self();
+ if (proc != NULL) {
+ return (m_process_t)proc->data;
+ }
+ else {
+ return NULL;
+ }
+
}
/** \ingroup m_process_management