From 7e71fb2465e221c39ce004c598388d89cc7f968e Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 2 Mar 2010 00:29:04 +0000 Subject: [PATCH] reindent git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7153 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/bindings/ruby/rb_msg_host.c | 29 +++-- src/bindings/ruby/rb_msg_task.c | 79 +++++++------ src/simix/smx_context_ruby.c | 190 ++++++++++++-------------------- 3 files changed, 124 insertions(+), 174 deletions(-) diff --git a/src/bindings/ruby/rb_msg_host.c b/src/bindings/ruby/rb_msg_host.c index f4ecd65962..797ac10d96 100644 --- a/src/bindings/ruby/rb_msg_host.c +++ b/src/bindings/ruby/rb_msg_host.c @@ -1,10 +1,10 @@ -/* - * Copyright 2010. The SimGrid Team. All right reserved. - * - * This program is free software; you can redistribute - * it and/or modify it under the terms of the license - *(GNU LGPL) which comes with this package. - */ +/* Host-related bindings to ruby */ + +/* Copyright 2010. The SimGrid Team. All right reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "bindings/ruby_bindings.h" // Free Method @@ -14,24 +14,23 @@ void rb_host_free(m_host_t ht) { // New Method : return a Host VALUE rb_host_get_by_name(VALUE class, VALUE name) { - + const char * h_name = RSTRING(name)->ptr; m_host_t host = MSG_get_host_by_name(h_name); if(!host) - rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failled"); - - return Data_Wrap_Struct(class,0,rb_host_free,host); + rb_raise(rb_eRuntimeError,"MSG_get_host_by_name() failed"); + return Data_Wrap_Struct(class,0,rb_host_free,host); } //Get Name VALUE rb_host_name(VALUE class,VALUE host) { - + // Wrap Ruby Value to m_host_t struct m_host_t ht; Data_Get_Struct(host, s_m_host_t, ht); return rb_str_new2(MSG_host_get_name(ht)); - + } // Get Number @@ -65,9 +64,9 @@ VALUE rb_host_is_avail(VALUE class,VALUE host) { rb_raise(rb_eRuntimeError,"Host not Bound"); return Qnil; } - + if(MSG_host_is_avail(ht)) return Qtrue; - + return Qfalse; } diff --git a/src/bindings/ruby/rb_msg_task.c b/src/bindings/ruby/rb_msg_task.c index 0de3ffa898..3faeeee9ce 100644 --- a/src/bindings/ruby/rb_msg_task.c +++ b/src/bindings/ruby/rb_msg_task.c @@ -1,10 +1,11 @@ -/* - * Copyright 2010. The SimGrid Team. All right reserved. - * - * This program is free software; you can redistribute - * it and/or modify it under the terms of the license - *(GNU LGPL) which comes with this package. - */ +/* Task-related bindings to ruby */ + +/* Copyright 2010. The SimGrid Team. All right reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + + #include "bindings/ruby_bindings.h" // Free Method @@ -33,7 +34,7 @@ VALUE rb_task_comp(VALUE class,VALUE task) { //Get Name VALUE rb_task_name(VALUE class,VALUE task) { - + // Wrap Ruby Value to m_task_t struct m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); @@ -42,7 +43,7 @@ VALUE rb_task_name(VALUE class,VALUE task) { // Execute Task VALUE rb_task_execute(VALUE class,VALUE task) { - + // Wrap Ruby Value to m_task_t struct m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); @@ -51,13 +52,13 @@ VALUE rb_task_execute(VALUE class,VALUE task) { // Sending Task void rb_task_send(VALUE class,VALUE task,VALUE mailbox) { - + // Wrap Ruby Value to m_task_t struct m_task_t tk; Data_Get_Struct(task, s_m_task_t, tk); int res = MSG_task_send(tk,RSTRING(mailbox)->ptr); if(res != MSG_OK) - rb_raise(rb_eRuntimeError,"MSG_task_send failed"); + rb_raise(rb_eRuntimeError,"MSG_task_send failed"); } // Receiving Task (returns a Task) @@ -88,7 +89,7 @@ VALUE rb_task_sender(VALUE class,VALUE task) { VALUE rb_task_source(VALUE class,VALUE task) { m_task_t tk; Data_Get_Struct(task,s_m_task_t,tk); - + m_host_t host = MSG_task_get_source(tk); if(!host->data) { rb_raise(rb_eRuntimeError,"MSG_task_get_source() failed"); @@ -100,37 +101,35 @@ VALUE rb_task_source(VALUE class,VALUE task) { // Return Boolean VALUE rb_task_listen(VALUE class,VALUE task,VALUE alias) { - m_task_t tk; - const char *p_alias; - int rv; - - Data_Get_Struct(task,s_m_task_t,tk); - p_alias = RSTRING(alias)->ptr; - - rv = MSG_task_listen(p_alias); - - if(rv) return Qtrue; - - return Qfalse; + m_task_t tk; + const char *p_alias; + int rv; + + Data_Get_Struct(task,s_m_task_t,tk); + p_alias = RSTRING(alias)->ptr; + + rv = MSG_task_listen(p_alias); + + if(rv) return Qtrue; + + return Qfalse; } // return Boolean VALUE rb_task_listen_host(VALUE class,VALUE task,VALUE alias,VALUE host) { - - m_task_t tk; - m_host_t ht; - const char *p_alias; - int rv; - - Data_Get_Struct(task,s_m_task_t,tk); - Data_Get_Struct(host,s_m_host_t,ht); - p_alias = RSTRING(alias)->ptr; - - rv = MSG_task_listen_from_host(p_alias,ht); - - if (rv) - return Qtrue; - return Qfalse; -} + m_task_t tk; + m_host_t ht; + const char *p_alias; + int rv; + + Data_Get_Struct(task,s_m_task_t,tk); + Data_Get_Struct(host,s_m_host_t,ht); + p_alias = RSTRING(alias)->ptr; + rv = MSG_task_listen_from_host(p_alias,ht); + + if (rv) + return Qtrue; + return Qfalse; +} diff --git a/src/simix/smx_context_ruby.c b/src/simix/smx_context_ruby.c index b5062bb60d..0dc94daaa2 100644 --- a/src/simix/smx_context_ruby.c +++ b/src/simix/smx_context_ruby.c @@ -1,8 +1,6 @@ -/* $Id$ */ +/* context_Ruby - implementation of context switching with/for ruby */ -/* context_Ruby - implementation of context switching with ruby coroutines */ - -/* Copyright (c) 2010, the SimGrid team. All right reserved */ +/* Copyright (c) 2010, the SimGrid team. All right reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -14,88 +12,67 @@ #include "xbt/asserts.h" #include "bindings/ruby_bindings.h" - + static smx_context_t smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, - void_f_pvoid_t cleanup_func,void *cleanup_arg); + void_f_pvoid_t cleanup_func,void *cleanup_arg); static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory); - static void smx_ctx_ruby_free(smx_context_t context); - static void smx_ctx_ruby_start(smx_context_t context); - static void smx_ctx_ruby_stop(smx_context_t context); - static void smx_ctx_ruby_suspend(smx_context_t context); - static void - smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context); - +smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context); static void smx_ctx_ruby_wrapper(void); +void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) { + *factory = xbt_new0(s_smx_context_factory_t,1); -void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory) -{ - - *factory = xbt_new0(s_smx_context_factory_t,1); - - (*factory)->create_context = smx_ctx_ruby_create_context; - (*factory)->finalize = smx_ctx_ruby_factory_finalize; - (*factory)->free = smx_ctx_ruby_free; - (*factory)->start = smx_ctx_ruby_start; - (*factory)->stop = smx_ctx_ruby_stop; - (*factory)->suspend = smx_ctx_ruby_suspend; - (*factory)->resume = smx_ctx_ruby_resume; - (*factory)->name = "smx_ruby_context_factory"; + (*factory)->create_context = smx_ctx_ruby_create_context; + (*factory)->finalize = smx_ctx_ruby_factory_finalize; + (*factory)->free = smx_ctx_ruby_free; + (*factory)->start = smx_ctx_ruby_start; + (*factory)->stop = smx_ctx_ruby_stop; + (*factory)->suspend = smx_ctx_ruby_suspend; + (*factory)->resume = smx_ctx_ruby_resume; + (*factory)->name = "smx_ruby_context_factory"; ruby_init(); ruby_init_loadpath(); - #ifdef MY_DEBUG - printf("SIMIX_ctx_ruby_factory_init...Done\n"); - #endif + DEBUG0("SIMIX_ctx_ruby_factory_init...Done"); } - -static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory) -{ - - free(*factory); - *factory = NULL; - return 0; - + +static int smx_ctx_ruby_factory_finalize(smx_context_factory_t *factory) { + free(*factory); + *factory = NULL; + return 0; } static smx_context_t - smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, - void_f_pvoid_t cleanup_func,void* cleanup_arg) -{ - +smx_ctx_ruby_create_context(xbt_main_func_t code,int argc,char** argv, + void_f_pvoid_t cleanup_func,void* cleanup_arg) { + smx_ctx_ruby_t context = xbt_new0(s_smx_ctx_ruby_t,1); - + /*if the user provided a function for the process , then use it Otherwise it's the context for maestro */ - if( code ) - { - context->cleanup_func = cleanup_func; - context->cleanup_arg = cleanup_arg; - context->process = (VALUE)code; - - #ifdef MY_DEBUG - printf("smx_ctx_ruby_create_context...Done\n"); - #endif - + if (code) { + context->cleanup_func = cleanup_func; + context->cleanup_arg = cleanup_arg; + context->process = (VALUE)code; + + DEBUG0("smx_ctx_ruby_create_context...Done"); } return (smx_context_t) context; - } - -static void smx_ctx_ruby_free(smx_context_t context) -{ - /* VALUE process; + +static void smx_ctx_ruby_free(smx_context_t context) { + /* VALUE process; if (context) { smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; - + if (ctx_ruby->process){ // if the Ruby Process is Alive , Join it // if ( process_isAlive(ctx_ruby->process)) @@ -104,92 +81,67 @@ static void smx_ctx_ruby_free(smx_context_t context) ctx_ruby->process = Qnil; process_join(process); } - + } free(context); context = NULL; }*/ free (context); context = NULL; - #ifdef MY_DEBUG - printf("smx_ctx_ruby_free_context...Done\n"); - #endif - + DEBUG0("smx_ctx_ruby_free_context...Done"); } -static void smx_ctx_ruby_start(smx_context_t context) -{ - - /* Already Done .. Since a Ruby Process is launched within initialization +static void smx_ctx_ruby_start(smx_context_t context) { + /* Already Done .. Since a Ruby Process is launched within initialization We Start it Within the Initializer ... We Use the Semaphore To Keep The Thread Alive Waitin' For Mutex Signal to Execute The Main*/ - + } -static void smx_ctx_ruby_stop(smx_context_t context) -{ - - +static void smx_ctx_ruby_stop(smx_context_t context) { + VALUE process = Qnil; smx_ctx_ruby_t ctx_ruby,current; - + if ( context->cleanup_func) (*(context->cleanup_func)) (context->cleanup_arg); - + ctx_ruby = (smx_ctx_ruby_t) context; - + // Well , Let's Do The Same as JNI Stoppin' Process - if ( simix_global->current_process->iwannadie ) - { - if( ctx_ruby->process ) - { - //if the Ruby Process still Alive ,let's Schedule it - if ( rb_process_isAlive( ctx_ruby->process ) ) - { - current = (smx_ctx_ruby_t)simix_global->current_process->context; - rb_process_schedule(current->process); - process = ctx_ruby->process; - // interupt/kill The Ruby Process - rb_process_kill_up(process); + if ( simix_global->current_process->iwannadie ) { + if( ctx_ruby->process ) { + //if the Ruby Process still Alive ,let's Schedule it + if ( rb_process_isAlive( ctx_ruby->process ) ) { + current = (smx_ctx_ruby_t)simix_global->current_process->context; + rb_process_schedule(current->process); + process = ctx_ruby->process; + // interupt/kill The Ruby Process + rb_process_kill_up(process); + } } - } - }else { - + } else { process = ctx_ruby->process; ctx_ruby->process = Qnil; - } - #ifdef MY_DEBUG - printf("smx_ctx_ruby_stop...Done\n"); - #endif + DEBUG0("smx_ctx_ruby_stop...Done\n"); } -static void smx_ctx_ruby_suspend(smx_context_t context) -{ - -if (context) -{ -smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; - if (ctx_ruby->process) - rb_process_unschedule( ctx_ruby->process ) ; -#ifdef MY_DEBUG - printf("smx_ctx_ruby_unschedule...Done\n"); -#endif -} - - else +static void smx_ctx_ruby_suspend(smx_context_t context) { + + if (context) { + smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) context; + if (ctx_ruby->process) + rb_process_unschedule(ctx_ruby->process); + DEBUG0("smx_ctx_ruby_unschedule...Done"); + } else rb_raise(rb_eRuntimeError,"smx_ctx_ruby_suspend failed"); - } -static void smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context) -{ - - smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context; - rb_process_schedule(ctx_ruby->process); - - #ifdef MY_DEBUG - printf("smx_ctx_ruby_schedule...Done\n"); - #endif - +static void smx_ctx_ruby_resume(smx_context_t old_context,smx_context_t new_context) { + smx_ctx_ruby_t ctx_ruby = (smx_ctx_ruby_t) new_context; + rb_process_schedule(ctx_ruby->process); + + DEBUG0("smx_ctx_ruby_schedule...Done"); } + -- 2.20.1