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/private.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 SMX_CTX_BASE_T \
26 s_xbt_swag_hookup_t hookup; \
27 ex_ctx_t *exception; \
28 xbt_main_func_t code; \
30 /* all other context types derive from this structure */
31 typedef struct s_smx_context {
35 /* *********************** */
36 /* factory type definition */
37 /* *********************** */
39 /* The following function pointer types describe the interface that any context
40 factory should implement */
42 /* function used to create a new context */
43 typedef int (*smx_pfn_context_factory_create_context_t) (smx_process_t *, xbt_main_func_t);
45 /* function used to create the context for the maestro process */
46 typedef int (*smx_pfn_context_factory_create_maestro_context_t) (smx_process_t*);
48 /* this function finalize the specified context factory */
49 typedef int (*smx_pfn_context_factory_finalize_t) (smx_context_factory_t*);
51 /* function used to destroy the specified context */
52 typedef void (*smx_pfn_context_free_t) (smx_process_t);
54 /* function used to kill the specified context */
55 typedef void (*smx_pfn_context_kill_t) (smx_process_t);
57 /* function used to resume the specified context */
58 typedef void (*smx_pfn_context_schedule_t) (smx_process_t);
60 /* function used to yield the specified context */
61 typedef void (*smx_pfn_context_yield_t) (void);
63 /* function used to start the specified context */
64 typedef void (*smx_pfn_context_start_t) (smx_process_t);
66 /* function used to stop the current context */
67 typedef void (*smx_pfn_context_stop_t) (int);
69 /* interface of the context factories */
70 typedef struct s_smx_context_factory {
71 smx_pfn_context_factory_create_maestro_context_t create_maestro_context;
72 smx_pfn_context_factory_create_context_t create_context;
73 smx_pfn_context_factory_finalize_t finalize;
74 smx_pfn_context_free_t free;
75 smx_pfn_context_kill_t kill;
76 smx_pfn_context_schedule_t schedule;
77 smx_pfn_context_yield_t yield;
78 smx_pfn_context_start_t start;
79 smx_pfn_context_stop_t stop;
81 } s_smx_context_factory_t;
83 /* Selects a context factory associated with the name specified by the parameter name.
84 * If successful the function returns 0. Otherwise the function returns the error code.
86 int SIMIX_context_select_factory(const char *name);
88 /* Initializes a context factory from the name specified by the parameter name.
89 * If the factory cannot be found, an exception is raised.
91 void SIMIX_context_init_factory_by_name(smx_context_factory_t * factory, const char *name);
93 /* All factories init */
94 void SIMIX_ctx_thread_factory_init(smx_context_factory_t * factory);
96 void SIMIX_ctx_sysv_factory_init(smx_context_factory_t * factory);
98 void SIMIX_ctx_java_factory_init(smx_context_factory_t * factory);
101 #endif /* !_XBT_CONTEXT_PRIVATE_H */