1 /* a fast and simple context switching library */
3 /* Copyright (c) 2004-2008 the SimGrid team. */
4 /* All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #ifndef _XBT_CONTEXT_PRIVATE_H
10 #define _XBT_CONTEXT_PRIVATE_H
12 #include "xbt/sysdep.h"
13 #include "simix/context.h"
18 /* *********************** */
19 /* Context type definition */
20 /* *********************** */
21 /* the following function pointers types describe the interface that all context
22 concepts must implement */
24 /* each context type must contain this macro at its begining -- OOP in C :/ */
25 #define XBT_CTX_BASE_T \
26 s_xbt_swag_hookup_t hookup; \
28 void_f_pvoid_t cleanup_func; \
30 ex_ctx_t *exception; \
32 xbt_main_func_t code; \
35 void_f_pvoid_t startup_func; \
38 /* all other context types derive from this structure */
39 typedef struct s_xbt_context {
43 /* ****************** */
44 /* Globals definition */
45 /* ****************** */
48 extern xbt_context_t current_context;
49 extern xbt_context_t maestro_context;
52 extern xbt_swag_t context_living;
53 extern xbt_swag_t context_to_destroy;
55 /* *********************** */
56 /* factory type definition */
57 /* *********************** */
59 typedef struct s_xbt_context_factory *xbt_context_factory_t;
61 /* The following function pointer types describe the interface that any context
62 factory should implement */
64 /* function used to create a new context */
65 typedef xbt_context_t (*xbt_pfn_context_factory_create_context_t)
66 (const char *, xbt_main_func_t, void_f_pvoid_t, void *, void_f_pvoid_t, void *, int, char **);
68 /* function used to create the context for the maestro process */
69 typedef int (*xbt_pfn_context_factory_create_maestro_context_t) (xbt_context_t*);
71 /* this function finalize the specified context factory */
72 typedef int (*xbt_pfn_context_factory_finalize_t) (xbt_context_factory_t*);
74 /* function used to destroy the specified context */
75 typedef void (*xbt_pfn_context_free_t) (xbt_context_t);
77 /* function used to kill the specified context */
78 typedef void (*xbt_pfn_context_kill_t) (xbt_context_t);
80 /* function used to resume the specified context */
81 typedef void (*xbt_pfn_context_schedule_t) (xbt_context_t);
83 /* function used to yield the specified context */
84 typedef void (*xbt_pfn_context_yield_t) (void);
86 /* function used to start the specified context */
87 typedef void (*xbt_pfn_context_start_t) (xbt_context_t);
89 /* function used to stop the current context */
90 typedef void (*xbt_pfn_context_stop_t) (int);
92 /* interface of the context factories */
93 typedef struct s_xbt_context_factory {
94 xbt_pfn_context_factory_create_maestro_context_t create_maestro_context;
95 xbt_pfn_context_factory_create_context_t create_context;
96 xbt_pfn_context_factory_finalize_t finalize;
97 xbt_pfn_context_free_t free;
98 xbt_pfn_context_kill_t kill;
99 xbt_pfn_context_schedule_t schedule;
100 xbt_pfn_context_yield_t yield;
101 xbt_pfn_context_start_t start;
102 xbt_pfn_context_stop_t stop;
104 } s_xbt_context_factory_t;
106 /* Selects a context factory associated with the name specified by the parameter name.
107 * If successful the function returns 0. Otherwise the function returns the error code.
109 int xbt_context_select_factory(const char *name);
111 /* Initializes a context factory from the name specified by the parameter name.
112 * If the factory cannot be found, an exception is raised.
114 void xbt_context_init_factory_by_name(xbt_context_factory_t * factory, const char *name);
116 /* All factories init */
117 void xbt_ctx_thread_factory_init(xbt_context_factory_t * factory);
119 void xbt_ctx_sysv_factory_init(xbt_context_factory_t * factory);
121 void xbt_ctx_java_factory_init(xbt_context_factory_t * factory);
124 #endif /* !_XBT_CONTEXT_PRIVATE_H */