#include "bindings/ruby_bindings.h"
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(ruby);
+
// 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
VALUE rb_task_new(VALUE class, VALUE name,VALUE comp_size,VALUE comm_size) {
- //char * t_name = RSTRING(name)->ptr;
m_task_t task = MSG_task_create(RSTRING(name)->ptr,NUM2INT(comp_size),NUM2INT(comm_size),NULL);
// Wrap m_task_t to a Ruby Value
return Data_Wrap_Struct(class, 0, rb_task_free, task);
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));
}
// 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");
}
// Receiving Task (returns a Task)
-VALUE rb_task_receive(VALUE class,VALUE mailbox) {
- // Task
- m_task_t task = NULL;
- MSG_task_receive(&task,RSTRING(mailbox)->ptr);
+VALUE rb_task_receive(VALUE class, VALUE mailbox) {
+ // 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;
+ INFO2("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);
}
-// Recieve Task 2
-// Not Appreciated
-void rb_task_receive2(VALUE class,VALUE task,VALUE mailbox) {
- m_task_t tk;
- Data_Get_Struct(task, s_m_task_t, tk);
- MSG_task_receive(&tk,RSTRING(mailbox)->ptr);
-}
-
// It Return a Native Process ( m_process_t )
VALUE rb_task_sender(VALUE class,VALUE task) {
m_task_t tk;