Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove needless volatile qualifier.
[simgrid.git] / buildtools / Cmake / test_prog / prog_AC_CHECK_MCSC.c
1 /* Copyright (c) 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #ifdef _XBT_WIN32
11 #include "win32_ucontext.h"
12 #include "win32_ucontext.c"
13 #else
14 #include <ucontext.h>
15 #endif
16
17 void child(void);
18
19 ucontext_t uc_child;
20 ucontext_t uc_main;
21
22
23
24 void child(void)
25 {
26   if (swapcontext(&uc_child, &uc_main) != 0)
27     exit(2);
28 }
29
30 int main(int argc, char *argv[])
31 {
32   FILE *fp;
33   void *stack;
34
35   /* the default is that it fails */
36   if ((fp = fopen("conftestval", "w")) == NULL)
37     exit(3);
38   fprintf(fp, "no\n");
39   fclose(fp);
40
41   /* configure a child user-space context */
42   if ((stack = malloc(64 * 1024)) == NULL)
43     exit(4);
44   if (getcontext(&uc_child) != 0)
45     exit(5);
46   uc_child.uc_link = NULL;
47   uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024);
48   uc_child.uc_stack.ss_size = 32 * 1024;
49   uc_child.uc_stack.ss_flags = 0;
50   makecontext(&uc_child, child, 0);
51
52   /* switch into the user context */
53   if (swapcontext(&uc_main, &uc_child) != 0)
54     exit(6);
55
56   /* Fine, child came home */
57   if ((fp = fopen("conftestval", "w")) == NULL)
58     exit(7);
59   fprintf(fp, "yes\n");
60   fclose(fp);
61
62   /* die successfully */
63   exit(0);
64   return 1;
65 }