From 1d96520ded04926898a617cdd213df0a9689f923 Mon Sep 17 00:00:00 2001 From: navarrop Date: Wed, 24 Feb 2010 16:40:00 +0000 Subject: [PATCH] Delete warning during compiling. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7122 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- .../include/simgrid_config.h.in | 66 ++++ .../src/bindings/ruby/rb_msg.h | 52 +++ .../src/bindings/ruby/rb_msg_host.c | 14 +- .../src/bindings/ruby/rb_msg_host.h | 39 +- .../src/bindings/ruby/rb_msg_process.c | 335 ++++++++++++++++++ .../src/bindings/ruby/rb_msg_task.c | 186 ++++++++++ .../simgrid_CMakeList/src/simix/smx_context.c | 152 ++++++++ .../src/simix/smx_context_ruby.c | 209 +++++++++++ .../teshsuite/xbt/log_large_test.tesh | 115 ++++++ src/surf/network_constant.c | 4 +- 10 files changed, 1143 insertions(+), 29 deletions(-) create mode 100644 buildtools/CPACK/simgrid_CMakeList/include/simgrid_config.h.in create mode 100644 buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg.h create mode 100644 buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_process.c create mode 100644 buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_task.c create mode 100644 buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context.c create mode 100644 buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context_ruby.c create mode 100644 buildtools/CPACK/simgrid_CMakeList/teshsuite/xbt/log_large_test.tesh diff --git a/buildtools/CPACK/simgrid_CMakeList/include/simgrid_config.h.in b/buildtools/CPACK/simgrid_CMakeList/include/simgrid_config.h.in new file mode 100644 index 0000000000..f82be86ff3 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/include/simgrid_config.h.in @@ -0,0 +1,66 @@ +/* $Id$ */ + +/* simgrid_config.h - Results of the configure made visible to user code */ + +/* Copyright (c) 2009, Da SimGrid team. All rights 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 "xbt/misc.h" /* XBT_PUBLIC */ + +#ifndef SIMGRID_PUBLIC_CONFIG_H +#define SIMGRID_PUBLIC_CONFIG_H + +/* Get the config */ +#undef SIMGRID_NEED_GETLINE +#undef SIMGRID_NEED_ASPRINTF +#undef SIMGRID_NEED_VASPRINTF +@need_getline@ +@need_asprintf@ +@need_vasprintf@ + +/* Use that config to declare missing elements */ +#ifdef SIMGRID_NEED_GETLINE +#include /* size_t */ +#include /* FILE* */ +XBT_PUBLIC(long) getline(char **lineptr, size_t * n, FILE * stream); +#else +#ifndef _GNU_SOURCE + #define _GNU_SOURCE +#endif +#include +#endif + + +/* snprintf related functions */ +/** @addtogroup XBT_str + * @{ */ +/** @brief print to allocated string (reimplemented when not provided by the system) + * + * The functions asprintf() and vasprintf() are analogues of + * sprintf() and vsprintf(), except that they allocate a string large + * enough to hold the output including the terminating null byte, and + * return a pointer to it via the first parameter. This pointer + * should be passed to free(3) to release the allocated storage when + * it is no longer needed. + */ +#if defined(SIMGRID_NEED_ASPRINTF)||defined(DOXYGEN) +XBT_PUBLIC(int) asprintf(char **ptr, const char *fmt, /*args */ + ...) _XBT_GNUC_PRINTF(2, 3); +#endif +/** @brief print to allocated string (reimplemented when not provided by the system) + * + * See asprintf() + */ +#if defined(SIMGRID_NEED_VASPRINTF)||defined(DOXYGEN) +XBT_PUBLIC(int) vasprintf(char **ptr, const char *fmt, va_list ap); +#endif +/** @brief print to allocated string + * + * Works just like asprintf(), but returns a pointer to the newly created string + */ +XBT_PUBLIC(char *) bprintf(const char *fmt, ...) _XBT_GNUC_PRINTF(1, 2); +/** @} */ + +#endif /* SIMGRID_PUBLIC_CONFIG_H */ diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg.h b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg.h new file mode 100644 index 0000000000..8d77e0b8ad --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg.h @@ -0,0 +1,52 @@ +#ifndef RB_MSG +#define RB_MSG +#include +#include "msg/msg.h" +#ifndef RUBY_H + #include +#endif + +XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, + "Messages specific for this msg example"); + +// #include "msg/private.h" +// #include "simix/private.h" +// #include "simix/smx_context_ruby.h" + +// MSG Module +VALUE rb_msg; +// MSG Classes +VALUE rb_task; +VALUE rb_host; + +//init_Msg Called When The Ruby Interpreter loads this C extension +void Init_msg(); + +// Msg_Init From Ruby +static void msg_init(VALUE Class,VALUE args); + +// Msg_Run From Ruby +static void msg_run(VALUE Class); + +// Create Environment +static void msg_createEnvironment(VALUE Class,VALUE plateformFile); + +// deploy Application +static void msg_deployApplication(VALUE Class,VALUE deploymntFile); + +// Tools +static void msg_info(VALUE Class,VALUE msg); + +//get Clock +static void msg_get_clock(VALUE Class); + +//pajeOutput +static void msg_paje_output(VALUE Class,VALUE pajeFile); + +// Ruby Introspection : To instanciate a Ruby Class from its Name +static VALUE msg_new_ruby_instance(VALUE Class,VALUE className); + +// The Same ... This Time with Args +static VALUE msg_new_ruby_instance_with_args(VALUE Class,VALUE className,VALUE args); + +#endif diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c index 8f8ff0f754..a57278f5dd 100644 --- a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.c @@ -33,9 +33,9 @@ static VALUE host_name(VALUE class,VALUE host) { // Wrap Ruby Value to m_host_t struct - m_host_t ht; + m_host_t *ht; Data_Get_Struct(host, m_host_t, ht); - return rb_str_new2(MSG_host_get_name(ht)); + return rb_str_new2(MSG_host_get_name(*ht)); } @@ -50,9 +50,9 @@ static VALUE host_number(VALUE class) // Host Speed ( Double ) static VALUE host_speed(VALUE class,VALUE host) { - m_host_t ht ; + m_host_t *ht ; Data_Get_Struct(host,m_host_t,ht); - return MSG_get_host_speed(ht); + return MSG_get_host_speed(*ht); } @@ -73,15 +73,15 @@ static VALUE host_get_data(VALUE class,VALUE host) static VALUE host_is_avail(VALUE class,VALUE host) { - m_host_t ht; + m_host_t *ht; Data_Get_Struct(host,m_host_t,ht); - if (!ht) + if (!*ht) { rb_raise(rb_eRuntimeError,"Host not Bound"); return Qnil; } - if(MSG_host_is_avail(ht)) + if(MSG_host_is_avail(*ht)) return Qtrue; return Qfalse; diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h index e76c0481ae..dc07ff1af7 100644 --- a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_host.h @@ -1,32 +1,31 @@ #ifndef RB_MSG_HOST -#define RB_MSG_HOST + #define RB_MSG_HOST -#include -#include "msg/msg.h" + #include + #include "msg/msg.h" -// Free Method -void host_free(m_host_t ht); + // Free Method + void host_free(m_host_t ht); -// New Method -static VALUE host_get_by_name(VALUE Class, VALUE name); + // New Method + static VALUE host_get_by_name(VALUE Class, VALUE name); -//Get Name -static VALUE host_name(VALUE Class,VALUE host); + //Get Name + static VALUE host_name(VALUE Class,VALUE host); -//Get Number -static VALUE host_number(VALUE Class); + //Get Number + static VALUE host_number(VALUE Class); -// get Speed -static VALUE host_speed(VALUE Class,VALUE host); + // get Speed + static VALUE host_speed(VALUE Class,VALUE host); -// Set Data -static void host_set_data(VALUE Class,VALUE host,VALUE data); + // Set Data + static void host_set_data(VALUE Class,VALUE host,VALUE data); -// Get Data -static VALUE host_get_data( VALUE Class,VALUE host); + // Get Data + static VALUE host_get_data( VALUE Class,VALUE host); -//is Available -static VALUE host_is_avail(VALUE Class,VALUE host); - + //is Available + static VALUE host_is_avail(VALUE Class,VALUE host); #endif diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_process.c b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_process.c new file mode 100644 index 0000000000..1544538692 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_process.c @@ -0,0 +1,335 @@ +/* + * $Id$ + * + * Copyright 2010 Martin Quinson, Mehdi Fekari + * 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 "rb_msg_process.h" + +#define DEBUG +// Init Ruby +static void initRuby() +{ + + ruby_init(); + ruby_init_loadpath(); + rb_require("RubyProcess.rb"); + +} + + +/*********************************************** + +Functions for Ruby Process Management ( Up Call) + +Idependant Methods + +************************************************/ + + +// get Ruby Process Name +static VALUE process_getName( VALUE ruby_process ) +{ + + initRuby(); + // instance = rb_funcall3(rb_const_get(rb_cObject, rb_intern("RbProcess")), rb_intern("new"), 0, 0); + return rb_funcall(ruby_process,rb_intern("getName"),0); + +} + +// Get Process ID +static VALUE process_getID(VALUE ruby_process) +{ + + initRuby(); + return rb_funcall(ruby_process,rb_intern("getID"),0); + +} + +// Get Bind +static VALUE process_getBind(VALUE ruby_process) +{ + + initRuby(); + return rb_funcall(ruby_process,rb_intern("getBind"),0); + +} + + +// Set Bind +static void process_setBind(VALUE ruby_process,long bind) +{ + + initRuby(); + VALUE r_bind = LONG2FIX(bind); + rb_funcall(ruby_process,rb_intern("setBind"),1,r_bind); + +} + +// isAlive +static VALUE process_isAlive(VALUE ruby_process) +{ + + initRuby(); + return rb_funcall(ruby_process,rb_intern("alive?"),0); + +} + +// Kill Process +static void process_kill(VALUE ruby_process) +{ + + initRuby(); + rb_funcall(ruby_process,rb_intern("kill"),0); + +} + +// join Process +static void process_join( VALUE ruby_process ) +{ + + initRuby(); + rb_funcall(ruby_process,rb_intern("join"),0); + +} + +// unschedule Process +static void process_unschedule( VALUE ruby_process ) +{ + + initRuby(); + rb_funcall(ruby_process,rb_intern("unschedule"),0); + +} + +// schedule Process +static void process_schedule( VALUE ruby_process ) +{ + + initRuby(); + rb_funcall(ruby_process,rb_intern("schedule"),0); + +} + +/*************************************************** + +Function for Native Process ( Bound ) Management + +Methods Belong to MSG Module + +****************************************************/ + +// Process To Native + +static m_process_t process_to_native(VALUE ruby_process) +{ + + VALUE id = process_getBind(ruby_process); + if (!id) + { + rb_raise(rb_eRuntimeError,"Process Not Bound >>> id_Bind Null"); + return NULL; + } + long l_id= FIX2LONG(id); + return (m_process_t)l_id; + +} + +// Bind Process + +static void processBind(VALUE ruby_process,m_process_t process) +{ + + long bind = (long)(process); + process_setBind(ruby_process,bind); + +} + + +// processCreate + +static void processCreate(VALUE class,VALUE ruby_process,VALUE host) +{ + + VALUE rbName; // Name of Java Process instance + m_process_t process; // Native Process to Create + const char * name ; // Name of C Native Process + char alias[MAX_ALIAS_NAME + 1 ] = {0}; + msg_mailbox_t mailbox; + rbName = process_getName(ruby_process); + + if(!rbName) + { + rb_raise(rb_eRuntimeError,"Internal error : Process Name Cannot be NULL"); + return; + } + // Allocate the data for the simulation + process = xbt_new0(s_m_process_t,1); + process->simdata = xbt_new0(s_simdata_process_t,1); + // Do we Really Need to Create Ruby Process Instance , >> process is already a Ruby Process !! So..Keep on ;) + // Bind The Ruby Process instance to The Native Process + processBind(ruby_process,process); + name = RSTRING(rbName)->ptr; + process->name = xbt_strdup(name); + Data_Get_Struct(host,m_host_t,process->simdata->m_host); + + if(!(process->simdata->m_host)) // Not Binded + { + free(process->simdata); + free(process->data); + free(process); + rb_raise(rb_eRuntimeError,"Host not bound...while creating native process"); + return; + } + process->simdata->PID = msg_global->PID++; // msg_global ?? + /*DEBUG + ("fil in process %s/%s (pid=%d) %p (sd=%p, host=%p, host->sd=%p) ", + process->name ,process->simdata->m_host->name,process->simdata->PID, + process,process->simdata, process->simdata->m_host, + process->simdata->m_host->simdata);*/ + + #ifdef DEBUG + printf("fill in process %s/%s (pid=%d) %p (sd=%p , host=%p, host->sd=%p)\n", + process->name , process->simdata->m_host->name,process->simdata->PID, + process,process->simdata, process->simdata->m_host, + process->simdata->m_host->simdata); + #endif + process->simdata->s_process = + SIMIX_process_create(process->name, + (xbt_main_func_t)ruby_process, + (void *) process, + process->simdata->m_host->simdata->smx_host->name, + 0,NULL,NULL); + + //DEBUG ( "context created (s_process=%p)",process->simdata->s_process); + #ifdef DEBUG + printf("context created (s_process=%p)\n",process->simdata->s_process); + #endif + if (SIMIX_process_self()) { // SomeOne Created Me !! + process->simdata->PPID = MSG_process_get_PID(SIMIX_process_self()->data); + } + else + { + process->simdata->PPID = -1; + } + process->simdata->last_errno = MSG_OK; + // let's Add the Process to the list of the Simulation's Processes + xbt_fifo_unshift(msg_global->process_list,process); + sprintf(alias,"%s:%s",(process->simdata->m_host->simdata->smx_host)->name, + process->name); + + mailbox = MSG_mailbox_new(alias); + +} + + +// Process Management + +static void processSuspend(VALUE class,VALUE ruby_process) +{ + + m_process_t process = process_to_native(ruby_process); + + if (!process) + { + rb_raise(rb_eRuntimeError,"Process Not Bound...while suspending process"); + return; + } + + // Trying to suspend The Process + + if ( MSG_OK != MSG_process_suspend(process)) + rb_raise(rb_eRuntimeError,"MSG_process_suspend() failed"); + + +} + +static void processResume(VALUE class,VALUE ruby_process) +{ + m_process_t process = process_to_native(ruby_process); + if (!process) + { + rb_raise(rb_eRuntimeError,"Process not Bound...while resuming process"); + return ; + } + // Trying to resume the process + if ( MSG_OK != MSG_process_resume(process)) + rb_raise(rb_eRuntimeError,"MSG_process_resume() failed"); + +} + +static VALUE processIsSuspend(VALUE class,VALUE ruby_process) +{ + + m_process_t process = process_to_native(ruby_process); + if (!process) + { + rb_raise (rb_eRuntimeError,"Process not Bound...while testing if suspended"); + return; + } + + // 1 is The Process is Suspended , 0 Otherwise + if(MSG_process_is_suspended(process)) + return Qtrue; + + return Qfalse; + +} + +static void processKill(VALUE class,VALUE ruby_process) +{ + m_process_t process = process_to_native(ruby_process); + + if(!process) + { + rb_raise (rb_eRuntimeError,"Process Not Bound...while killing process"); + return ; + } + // Delete The Global Reference / Ruby Process + process_kill(ruby_process); + // Delete the Native Process + MSG_process_kill(process); + +} + +static VALUE processGetHost(VALUE class,VALUE ruby_process) +{ + + m_process_t process = process_to_native(ruby_process); + m_host_t host; + + if (!process) + { + rb_raise(rb_eRuntimeError,"Process Not Bound...while getting Host"); + return Qnil; // NULL + } + + host = MSG_process_get_host(process); + + if(!host->data) + { + rb_raise (rb_eRuntimeError,"MSG_process_get_host() failed"); + return Qnil; + } + + return Data_Wrap_Struct(class, 0, host_free, host); + +} + +static void processExit(VALUE class,VALUE ruby_process) +{ + + m_process_t process = process_to_native(ruby_process); + if(!process) + { + rb_raise(rb_eRuntimeError,"Process Not Bound...while exiting process"); + return; + } + SIMIX_context_stop(SIMIX_process_self()->context); + +} diff --git a/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_task.c b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_task.c new file mode 100644 index 0000000000..9a3061fb88 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/bindings/ruby/rb_msg_task.c @@ -0,0 +1,186 @@ +/* + * $Id$ + * + * Copyright 2010 Martin Quinson, Mehdi Fekari + * 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 "rb_msg_task.h" + +// Free Method +static void task_free(m_task_t tk) { + MSG_task_destroy(tk); +} + +// New Method +static VALUE 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, task_free, task); + +} + +//Get Computation Size +static VALUE task_comp(VALUE class,VALUE task) +{ + double size; + m_task_t *tk; + // Wrap Ruby Value to m_task_t struct + Data_Get_Struct(task, m_task_t, tk); + size = MSG_task_get_compute_duration(*tk); + return rb_float_new(size); +} + +//Get Name +static VALUE task_name(VALUE class,VALUE task) +{ + + // Wrap Ruby Value to m_task_t struct + m_task_t *tk; + Data_Get_Struct(task, m_task_t, tk); + return rb_str_new2(MSG_task_get_name(*tk)); + +} + +// Execute Task +static VALUE task_execute(VALUE class,VALUE task) +{ + + // Wrap Ruby Value to m_task_t struct + m_task_t *tk; + Data_Get_Struct(task, m_task_t, tk); + return INT2NUM(MSG_task_execute(*tk)); + +} + +// Sending Task +static void task_send(VALUE class,VALUE task,VALUE mailbox) +{ + + // Wrap Ruby Value to m_task_t struct + m_task_t *tk; + Data_Get_Struct(task, 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"); + + return; +} + +// Recieving Task + +/** +*It Return a Task +*/ + +static VALUE task_receive(VALUE class,VALUE mailbox) +{ + // Task + m_task_t task = NULL; + MSG_task_receive(&task,RSTRING(mailbox)->ptr); + return Data_Wrap_Struct(class, 0, task_free, task); +} + +// Recieve Task 2 +// Not Appreciated +static void task_receive2(VALUE class,VALUE task,VALUE mailbox) +{ + m_task_t *tk; + Data_Get_Struct(task, m_task_t, tk); + MSG_task_receive(tk,RSTRING(mailbox)->ptr); + +} + +// It Return a Native Process ( m_process_t ) +static VALUE task_sender(VALUE class,VALUE task) +{ + m_task_t *tk; + Data_Get_Struct(task,m_task_t,tk); + return (VALUE) MSG_task_get_sender(*tk); +} + +// it return a Host +static VALUE task_source(VALUE class,VALUE task) +{ + m_task_t *tk; + Data_Get_Struct(task,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"); + return Qnil; + } + return (VALUE) host; + +} + +// Return Boolean +static VALUE task_listen(VALUE class,VALUE task,VALUE alias) +{ + m_task_t *tk; + const char *p_alias; + int rv; + + Data_Get_Struct(task,m_task_t,tk); + p_alias = RSTRING(alias)->ptr; + + rv = MSG_task_listen(p_alias); + + if(rv) return Qtrue; + + return Qfalse; + +} + +// return Boolean +static VALUE 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,m_task_t,tk); + Data_Get_Struct(host,m_host_t,ht); + p_alias = RSTRING(alias)->ptr; + + rv = MSG_task_listen_from_host(p_alias,*ht); + + if (rv) return Qtrue; + + return Qfalse; + +} + + +// Put +static void task_put(VALUE class,VALUE task,VALUE host) +{ + + m_task_t *tk; + m_host_t *ht; + + Data_Get_Struct(task,m_task_t,tk); + Data_Get_Struct(host,m_host_t,ht); + MSG_task_put(*tk,*ht,PORT_22); //Channel set to 0 + +} + +//get +static VALUE task_get(VALUE class) +{ + + m_task_t task = NULL; + int res = MSG_task_get(&task,PORT_22); // Channel set to 0 + xbt_assert0(res == MSG_OK, "MSG_task_get failed"); + return Data_Wrap_Struct(class, 0, task_free, task); + +} diff --git a/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context.c b/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context.c new file mode 100644 index 0000000000..63e246f015 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context.c @@ -0,0 +1,152 @@ +/* a fast and simple context switching library */ + +/* Copyright (c) 2004-2008 the SimGrid team. */ +/* All rights 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 "portable.h" +#include "xbt/log.h" +#include "xbt/swag.h" +#include "private.h" +#include +#ifndef RUBY_H + #include +#endif +#include "smx_context_ruby.c" + +#define HAVE_RUBY /* HACK HACK */ +// #define DEBUG + +#ifdef HAVE_RUBY + extern void SIMIX_ctx_ruby_factory_init(smx_context_factory_t *factory); +#endif + +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_context, simix, "Context switching mecanism"); + +const char *xbt_ctx_factory_to_use = NULL; + +/** + * This function is call by SIMIX_global_init() to initialize the context module. + */ + +void SIMIX_context_mod_init(void) +{ + if (!simix_global->context_factory) { + /* select context factory to use to create the context(depends of the macro definitions) */ + if (xbt_ctx_factory_to_use) { + SIMIX_context_select_factory(xbt_ctx_factory_to_use); + } else { +#ifdef CONTEXT_THREADS + /* context switch based os thread */ + SIMIX_ctx_thread_factory_init(&simix_global->context_factory); +#elif !defined(WIN32) + /* context switch based ucontext */ + SIMIX_ctx_sysv_factory_init(&simix_global->context_factory); +#else + /* context switch is not allowed on Windows */ +#error ERROR [__FILE__, line __LINE__]: no context based implementation specified. +#endif + } + } +} + +/** + * This function is call by SIMIX_clean() to finalize the context module. + */ +void SIMIX_context_mod_exit(void) +{ + if (simix_global->context_factory) { + smx_pfn_context_factory_finalize_t finalize_factory; + + /* finalize the context factory */ + finalize_factory = simix_global->context_factory->finalize; + (*finalize_factory) (&simix_global->context_factory); + } +} + +/** + * This function is used to change the context factory. + * Warning: it destroy all the existing processes (even for maestro), and it + * will create a new maestro process using the new context factory. + */ +int SIMIX_context_select_factory(const char *name) +{ + /* if a context factory is already instantiated and it is different from the + newly selected one, then kill all the processes, exit the context module + and initialize the new factory. + */ + + + if (simix_global->context_factory != NULL) { + if (strcmp(simix_global->context_factory->name, name)){ + + SIMIX_process_killall(); + + /* kill maestro process */ + SIMIX_context_free(simix_global->maestro_process->context); + free(simix_global->maestro_process); + simix_global->maestro_process = NULL; + + SIMIX_context_mod_exit(); + } + else + /* the same context factory is requested return directly */ + return 0; + } + + /* init the desired factory */ + SIMIX_context_init_factory_by_name(&simix_global->context_factory, name); + + SIMIX_create_maestro_process (); + + + + return 0; +} + +/** + * Initializes a context factory given by its name + */ +void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, + const char *name) +{ + + if (!strcmp(name, "java")) +#ifdef HAVE_JAVA + SIMIX_ctx_java_factory_init(factory); +#else + THROW0(not_found_error, 0, "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library"); +#endif /* HAVE_JAVA */ + + else if (!strcmp(name, "thread")) +#ifdef CONTEXT_THREADS + SIMIX_ctx_thread_factory_init(factory); +#else + THROW0(not_found_error, 0, "Factory 'thread' does not exist: thread support was not compiled in the SimGrid library"); +#endif /* CONTEXT_THREADS */ + + else if (!strcmp(name, "sysv")) + #if !defined(WIN32) && !defined(CONTEXT_THREADS) + SIMIX_ctx_sysv_factory_init(factory); + #else + THROW0(not_found_error, 0, "Factory 'sysv' does not exist: no System V thread support under Windows"); + #endif + else if (!strcmp(name, "lua")) +#ifdef HAVE_LUA + SIMIX_ctx_lua_factory_init(factory); +#else + + THROW0(not_found_error, 0, "Factory 'lua' does not exist: Lua support was not compiled in the SimGrid library"); +#endif /* HAVE_LUA */ + + else if (!strcmp(name,"ruby")) +#ifdef HAVE_RUBY + SIMIX_ctx_ruby_factory_init(factory); +#else + THROW0(not_found_error, 0, "Factory 'ruby' does not exist: Ruby support was not compiled in the SimGrid library"); +#endif + else + THROW1(not_found_error, 0, "Factory '%s' does not exist", name); +} diff --git a/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context_ruby.c b/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context_ruby.c new file mode 100644 index 0000000000..e728013d3d --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/src/simix/smx_context_ruby.c @@ -0,0 +1,209 @@ +/* $Id$ */ + +/* context_Ruby - implementation of context switching with lua coroutines */ + +/* Copyright (c) 2004-2008 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. */ +#ifndef RUBY_H + #include +#endif +#include "private.h" +#include "xbt/function_types.h" +#include "xbt/sysdep.h" +#include "xbt/log.h" +#include "xbt/asserts.h" +#include "context_sysv_config.h" +#include "bindings/ruby/rb_msg_process.c" +// #include "bindings/ruby/rb_msg.c" + +// #define MY_DEBUG + + +typedef struct s_smx_ctx_ruby + +{ + SMX_CTX_BASE_T; + VALUE process; // The Ruby Process Instance + //... +}s_smx_ctx_ruby_t,*smx_ctx_ruby_t; + +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); + +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); + +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); + + (*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 +} + +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_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 + + } + return (smx_context_t) context; + +} + +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)) + { + process = ctx_ruby->process; + 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 + +} + +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) +{ + + + 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 ( process_isAlive( ctx_ruby->process ) ) + { + current = (smx_ctx_ruby_t)simix_global->current_process->context; + process_schedule(current->process); + process = ctx_ruby->process; + // interupt/kill The Ruby Process + process_kill(process); + } + } + }else { + + process = ctx_ruby->process; + ctx_ruby->process = Qnil; + + } + #ifdef MY_DEBUG + printf("smx_ctx_ruby_stop...Done\n"); + #endif +} + +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) + process_unschedule( ctx_ruby->process ) ; +#ifdef MY_DEBUG + printf("smx_ctx_ruby_unschedule...Done\n"); +#endif +} + + 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; + process_schedule(ctx_ruby->process); + + #ifdef MY_DEBUG + printf("smx_ctx_ruby_schedule...Done\n"); + #endif + +} diff --git a/buildtools/CPACK/simgrid_CMakeList/teshsuite/xbt/log_large_test.tesh b/buildtools/CPACK/simgrid_CMakeList/teshsuite/xbt/log_large_test.tesh new file mode 100644 index 0000000000..b8035f19f7 --- /dev/null +++ b/buildtools/CPACK/simgrid_CMakeList/teshsuite/xbt/log_large_test.tesh @@ -0,0 +1,115 @@ +p Check that the dynamic version of the log formated layout works +$ $SG_EXENV_TEST xbt/log_large_test --log=root.fmt:%m%n +> This is a very large message: +> 0 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 1 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9 +> 1.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 2.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 3.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 4.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 5.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 6.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 7.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 8.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 9.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> 0.........1.........2.........3.........4.........5.........6.........7.........8.........9.........0 +> +> Done (strlen>10210) diff --git a/src/surf/network_constant.c b/src/surf/network_constant.c index 8d71f074fc..74a319be31 100644 --- a/src/surf/network_constant.c +++ b/src/surf/network_constant.c @@ -20,11 +20,11 @@ typedef struct surf_action_network_Constant { XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network); static random_data_t random_latency = NULL; -static int host_number = 0; +static int host_number_int = 0; static void netcste_count_hosts(void) { - host_number++; + host_number_int++; } static void netcste_define_callbacks(const char *file) -- 2.20.1