static xbt_swag_t context_to_destroy = NULL;
static xbt_swag_t context_living = NULL;
+static void __xbt_context_yield(xbt_context_t context)
+{
+ int return_value = 0;
+
+ xbt_assert0(current_context,"You have to call context_init() first.");
+
+/* WARNING("--------- current_context (%p) is yielding to context(%p) ---------",current_context,context); */
+/* VOIRP(current_context); */
+/* if(current_context) VOIRP(current_context->save); */
+/* VOIRP(context); */
+/* if(context) VOIRP(context->save); */
+
+ if (context) {
+ if(context->save==NULL) {
+/* WARNING("**** Yielding to somebody else ****"); */
+/* WARNING("Saving current_context value (%p) to context(%p)->save",current_context,context); */
+ context->save = current_context ;
+/* WARNING("current_context becomes context(%p) ",context); */
+ current_context = context ;
+/* WARNING("Current position memorized (context->save). Jumping to context (%p)",context); */
+ return_value = swapcontext (&(context->save->uc), &(context->uc));
+ xbt_assert0((return_value==0),"Context swapping failure");
+/* WARNING("I am (%p). Coming back\n",context); */
+ } else {
+ xbt_context_t old_context = context->save ;
+/* WARNING("**** Back ! ****"); */
+/* WARNING("Setting current_context (%p) to context(%p)->save",current_context,context); */
+ current_context = context->save ;
+/* WARNING("Setting context(%p)->save to NULL",context); */
+ context->save = NULL ;
+/* WARNING("Current position memorized (%p). Jumping to context (%p)",context,old_context); */
+ return_value = swapcontext (&(context->uc), &(old_context->uc));
+ xbt_assert0((return_value==0),"Context swapping failure");
+/* WARNING("I am (%p). Coming back\n",context); */
+ }
+ }
+
+ return;
+}
+
static void xbt_context_destroy(xbt_context_t context)
{
xbt_free(context);
xbt_swag_remove(context, context_living);
xbt_swag_insert(context, context_to_destroy);
- xbt_context_yield(context);
+ __xbt_context_yield(context);
return NULL;
}
return res;
}
-void xbt_context_yield(xbt_context_t context)
-{
- int return_value = 0;
-
- xbt_assert0(current_context,"You have to call context_init() first.");
-
-/* WARNING("--------- current_context (%p) is yielding to context(%p) ---------",current_context,context); */
-/* VOIRP(current_context); */
-/* if(current_context) VOIRP(current_context->save); */
-/* VOIRP(context); */
-/* if(context) VOIRP(context->save); */
- if (context) {
- if(context->save==NULL) {
-/* WARNING("**** Yielding to somebody else ****"); */
-/* WARNING("Saving current_context value (%p) to context(%p)->save",current_context,context); */
- context->save = current_context ;
-/* WARNING("current_context becomes context(%p) ",context); */
- current_context = context ;
-/* WARNING("Current position memorized (context->save). Jumping to context (%p)",context); */
- return_value = swapcontext (&(context->save->uc), &(context->uc));
- xbt_assert0((return_value==0),"Context swapping failure");
-/* WARNING("I am (%p). Coming back\n",context); */
- } else {
- xbt_context_t old_context = context->save ;
-/* WARNING("**** Back ! ****"); */
-/* WARNING("Setting current_context (%p) to context(%p)->save",current_context,context); */
- current_context = context->save ;
-/* WARNING("Setting context(%p)->save to NULL",context); */
- context->save = NULL ;
-/* WARNING("Current position memorized (%p). Jumping to context (%p)",context,old_context); */
- return_value = swapcontext (&(context->uc), &(old_context->uc));
- xbt_assert0((return_value==0),"Context swapping failure");
-/* WARNING("I am (%p). Coming back\n",context); */
- }
- }
+void xbt_context_yield(void)
+{
+ __xbt_context_yield(current_context);
+}
- return;
+void xbt_context_schedule(xbt_context_t context)
+{
+ xbt_assert0((current_context==init_context),
+ "You are not supposed to run this function here!");
+ __xbt_context_yield(context);
}
void xbt_context_exit(void) {
AM_CFLAGS=-g
CLEANFILES = *~ test a.out *.o gras/datadesc_usage.out datadesc_usage.out
-DISTCLEANFILES = gras/.libs/* xbt/.libs/* surf/.libs/*
+DISTCLEANFILES = gras/.libs/* xbt/.libs/* surf/.libs/* msg/.libs/*
MAINTAINERCLEANFILES=Makefile.in
EXTRA_DIST=run_tests.in \
gras/datadesc.little32 gras/datadesc.little64 gras/datadesc.big32 gras/datadesc.big64 \
gras/datadesc.aix gras/datadesc.win32 gras/datadesc.g5 \
gras/mk_datadesc_structs.pl \
- surf/trace_A.txt surf/trace_B.txt surf/trace_A_failure.txt
+ surf/trace_A.txt surf/trace_B.txt surf/trace_A_failure.txt surf/platform.txt \
+ msg/platform.txt
# Test stuff
xbt/log_usage \
xbt/heap_bench \
xbt/swag_usage \
+ xbt/context_usage \
xbt/config_usage
# xbt/multidict_crash
SG_tests = \
surf/maxmin_usage surf/maxmin_bench \
- surf/trace_usage surf/surf_usage surf/surf_usage2
+ surf/trace_usage surf/surf_usage surf/surf_usage2 \
+ msg/msg_test
check_PROGRAMS = $(xbt_tests) $(RL_tests) $(SG_tests)
check_SCRIPTS = run_tests gras/trp_tcp_usage
xbt_config_usage_LDADD= $(LDADD_UTILS)
xbt_heap_bench_LDADD= $(LDADD_UTILS)
+xbt_context_usage_LDADD= $(LDADD_UTILS)
surf_maxmin_usage_LDADD= $(LDADD_UTILS)
surf_maxmin_bench_LDADD= $(LDADD_UTILS)
surf_surf_usage_LDADD= $(LDADD_UTILS)
surf_surf_usage2_LDADD= $(LDADD_UTILS)
+msg_msg_test_LDADD= $(LDADD_UTILS)
+
gras_trp_tcp_client_LDADD= $(LDADD_RL)
gras_trp_tcp_server_LDADD= $(LDADD_RL)
gras_trp_file_client_LDADD= $(LDADD_RL)
--- /dev/null
+#include "xbt/context.h"
+#include "xbt/fifo.h"
+#include "stdlib.h"
+#include "stdio.h"
+
+xbt_context_t cA = NULL;
+xbt_context_t cB = NULL;
+xbt_context_t cC = NULL;
+xbt_fifo_t fifo = NULL;
+
+void print_args(int argc, char** argv);
+void print_args(int argc, char** argv)
+{
+ int i ;
+
+ printf("<");
+ for(i=0; i<argc; i++)
+ printf("%s ",argv[i]);
+ printf(">\n");
+}
+
+int fA(int argc, char** argv);
+int fA(int argc, char** argv)
+{
+ printf("fA: ");
+ print_args(argc,argv);
+
+ printf("\tA: Yield\n");
+ xbt_context_yield();
+ printf("\tA: Yield\n");
+ xbt_context_yield();
+ printf("\tA : bye\n");
+
+ return 0;
+}
+
+int fB(int argc, char** argv);
+int fB(int argc, char** argv)
+{
+ printf("fB: ");
+ print_args(argc,argv);
+
+ printf("\tB: Yield\n");
+ xbt_context_yield();
+ xbt_fifo_push(fifo,cA);
+ printf("\tB->A\n");
+ printf("\tB: Yield\n");
+ xbt_context_yield();
+ printf("\tB : bye\n");
+
+ return 0;
+}
+
+int fC(int argc, char** argv);
+int fC(int argc, char** argv)
+{
+ printf("fC: ");
+ print_args(argc,argv);
+
+
+ printf("\tC: Yield\n");
+ xbt_context_yield();
+
+
+ return 0;
+}
+
+int main(int argc, char** argv)
+{
+ xbt_context_t context = NULL;
+
+ xbt_context_init();
+
+ cA = xbt_context_new(fA, 0, NULL);
+ cB = xbt_context_new(fB, 0, NULL);
+ cC = xbt_context_new(fC, 0, NULL);
+
+ fifo = xbt_fifo_new();
+
+ xbt_context_start(cA);
+ printf("\tO->A\n");xbt_fifo_push(fifo,cA);
+ xbt_context_start(cB);
+ printf("\tO->B\n");xbt_fifo_push(fifo,cB);
+ xbt_context_start(cC);xbt_fifo_push(fifo,cC);
+ printf("\tO->C\n");xbt_fifo_push(fifo,cC);
+
+ while((context=xbt_fifo_shift(fifo))) {
+ printf("\tO:Yield\n");
+ xbt_context_schedule(context);
+ }
+
+ xbt_fifo_free(fifo);
+ xbt_context_exit();
+
+ cA=cB=cC=NULL;
+ return 0;
+}