Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI: Change the reference speed to a command line option
[simgrid.git] / src / xbt / xbt_context.c
index a1b719e..d969580 100644 (file)
@@ -1,7 +1,6 @@
 /* a fast and simple context switching library                              */
 
-/* Copyright (c) 2004 Arnaud Legrand.                                       */
-/* Copyright (c) 2004, 2005 Martin Quinson.                                 */
+/* Copyright (c) 2004-2008 the SimGrid team.                                */
 /* All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -12,6 +11,9 @@
 #include "xbt/swag.h"
 #include "xbt_context_private.h"
 
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_context, xbt,
+                                "Context switching mecanism");
+
 /* the context associated with the current process                             */
 xbt_context_t current_context = NULL;
 
@@ -25,7 +27,7 @@ xbt_swag_t context_to_destroy = NULL;
 /* this list contains the contexts in use                                              */
 xbt_swag_t context_living = NULL;
 
-/* the context factory used to create the appropriate context  
+/* the context factory used to create the appropriate context
  * each context implementation define its own context factory
  * a context factory is responsable of the creation of the context
  * associated with the maestro and of all the context based on
@@ -96,7 +98,7 @@ void xbt_context_mod_exit(void)
     /* remove the context of the scheduler from the list of the contexts in use */
     xbt_swag_remove(maestro_context, context_living);
 
-    /*  
+    /*
      * kill all the contexts in use :
      * the killed contexts are added in the list of the contexts to destroy
      */
@@ -119,12 +121,12 @@ void xbt_context_mod_exit(void)
 /*******************************/
 /* Object creation/destruction */
 /*******************************/
-/** 
+/**
  * \param code a main function
  * \param startup_func a function to call when running the context for
  *      the first time and just before the main function \a code
  * \param startup_arg the argument passed to the previous function (\a startup_func)
- * \param cleanup_func a function to call when running the context, just after 
+ * \param cleanup_func a function to call when running the context, just after
         the termination of the main function \a code
  * \param cleanup_arg the argument passed to the previous function (\a cleanup_func)
  * \param argc first argument of function \a code
@@ -152,22 +154,22 @@ xbt_context_new(const char *name,
 }
 
 /* Scenario for the end of a context:
- * 
+ *
  * CASE 1: death after end of function
  *   __context_wrapper, called by os thread, calls xbt_context_stop after user code stops
  *   xbt_context_stop calls user cleanup_func if any (in context settings),
  *                    add current to trashbin
  *                    yields back to maestro (destroy os thread on need)
- *   From time to time, maestro calls xbt_context_empty_trash, 
+ *   From time to time, maestro calls xbt_context_empty_trash,
  *       which maps xbt_context_free on the content
- *   xbt_context_free frees some more memory, 
+ *   xbt_context_free frees some more memory,
  *                    joins os thread
- * 
+ *
  * CASE 2: brutal death
  *   xbt_context_kill (from any context)
  *                    set context->wannadie to 1
  *                    yields to the context
- *   the context is awaken in the middle of __yield. 
+ *   the context is awaken in the middle of __yield.
  *   At the end of it, it checks that wannadie == 1, and call xbt_context_stop
  *   (same than first case afterward)
  */
@@ -185,10 +187,10 @@ void xbt_context_kill(xbt_context_t context)
   (*(context->kill)) (context);
 }
 
-/** 
+/**
  * \param context the context to start
- * 
- * Calling this function prepares \a context to be run. It will 
+ *
+ * Calling this function prepares \a context to be run. It will
    however run effectively only when calling #xbt_context_schedule
  */
 void xbt_context_start(xbt_context_t context)
@@ -196,11 +198,11 @@ void xbt_context_start(xbt_context_t context)
   (*(context->start)) (context);
 }
 
-/** 
+/**
  * Calling this function makes the current context yield. The context
  * that scheduled it returns from xbt_context_schedule as if nothing
  * had happened.
- * 
+ *
  * Only the processes can call this function, giving back the control
  * to the maestro
  */
@@ -209,13 +211,13 @@ void xbt_context_yield(void)
   (*(current_context->yield)) ();
 }
 
-/** 
+/**
  * \param context the winner
  *
- * Calling this function blocks the current context and schedule \a context.  
+ * Calling this function blocks the current context and schedule \a context.
  * When \a context will call xbt_context_yield, it will return
  * to this function as if nothing had happened.
- * 
+ *
  * Only the maestro can call this function to run a given process.
  */
 void xbt_context_schedule(xbt_context_t context)