// Free Method
void rb_task_free(m_task_t tk) {
- MSG_task_destroy(tk);
+ //MSG_task_destroy(tk); ( This cause a bug !! is it really necessary ?!! not really sure !! )
}
// New Method
}
+// set Data : For the Moment , we will consider Data as asimple String ( char * )
+void rb_task_set_data(VALUE class,VALUE task,VALUE data)
+{
+ const char *str_data = RSTRING(data)->ptr;
+ m_task_t tk;
+ Data_Get_Struct(task, s_m_task_t, tk);
+ tk->data = (void*)str_data;
+
+}
+
+// get Data
+VALUE rb_task_get_data(VALUE class,VALUE task)
+{
+ m_task_t tk;
+ Data_Get_Struct(task, s_m_task_t, tk);
+ return rb_str_new2(tk->data);
+
+}
+
+
//Get Computation Size
VALUE rb_task_comp(VALUE class,VALUE task) {
double size;
VALUE rb_task_name(VALUE class,VALUE task) {
// Wrap Ruby Value to m_task_t struct
- m_task_t tk;
+ m_task_t tk;
Data_Get_Struct(task, s_m_task_t, tk);
return rb_str_new2(MSG_task_get_name(tk));
}
// Sending Task
void rb_task_send(VALUE class,VALUE task,VALUE mailbox) {
+ MSG_error_t rv;
// Wrap Ruby Value to m_task_t struct
m_task_t tk;
Data_Get_Struct(task, s_m_task_t, tk);
- INFO1("Sending task %p",tk);
- int res = MSG_task_send(tk,RSTRING(mailbox)->ptr);
- if(res != MSG_OK)
- rb_raise(rb_eRuntimeError,"MSG_task_send failed");
+ DEBUG1("Sending task %p",tk);
+ rv = MSG_task_send(tk,RSTRING(mailbox)->ptr);
+ if(rv != MSG_OK)
+ {
+ if (rv == MSG_TRANSFER_FAILURE )
+ rb_raise(rb_eRuntimeError,"Transfer failure while Sending");
+ else if ( rv == MSG_HOST_FAILURE )
+ rb_raise(rb_eRuntimeError,"Host failure while Sending");
+ else if ( rv == MSG_TIMEOUT_FAILURE )
+ rb_raise(rb_eRuntimeError,"Timeout failure while Sending");
+ else
+ rb_raise(rb_eRuntimeError,"MSG_task_send failed");
+ }
}
// Receiving Task (returns a Task)
VALUE rb_task_receive(VALUE class, VALUE mailbox) {
- // Task
- m_task_t task = NULL;
- INFO1("Receiving a task on mailbox '%s'",RSTRING(mailbox)->ptr);
- MSG_task_receive(&task,RSTRING(mailbox)->ptr);
- INFO2("XXXXXXXXReceived a task %p %s",task,task->name);
+ // We must put the location where we copy the task
+ // pointer to on the heap, because the stack may move
+ // during the context switches (damn ruby internals)
+ m_task_t *ptask = malloc(sizeof(m_task_t));
+ m_task_t task;
+ *ptask = NULL;
+ DEBUG2("Receiving a task on mailbox '%s', store it into %p",RSTRING(mailbox)->ptr,&task);
+ MSG_task_receive(ptask,RSTRING(mailbox)->ptr);
+ task = *ptask;
+ free(ptask);
return Data_Wrap_Struct(class, 0, rb_task_free, task);
}
return Qtrue;
return Qfalse;
}
+
+
+// Set Priority
+void rb_task_set_priority(VALUE class,VALUE task,VALUE priority)
+{
+
+ m_task_t tk;
+ double prt = NUM2DBL(priority);
+ Data_Get_Struct(task,s_m_task_t,tk);
+ MSG_task_set_priority(tk,prt);
+
+}
+
+// Cancel
+void rb_task_cancel(VALUE class,VALUE task)
+{
+ m_task_t tk;
+ Data_Get_Struct(task,s_m_task_t,tk);
+ MSG_task_cancel(tk);
+
+}
+