let us set the size of the heap in a sane way
[c11tester.git] / main.cc
1 #include "libthreads.h"
2 #include "common.h"
3 #include "threads.h"
4
5 /* global "model" object */
6 #include "model.h"
7 #include "snapshot.h"
8
9 /*
10  * Return 1 if found next thread, 0 otherwise
11  */
12 int num;
13 int num1;
14 int num2;
15
16 static int thread_system_next(void) {
17   Thread *curr, *next;
18   
19   curr = thread_current();
20   if (curr) {
21     if (curr->get_state() == THREAD_READY) {
22       model->check_current_action();
23       model->scheduler->add_thread(curr);
24     } else if (curr->get_state() == THREAD_RUNNING)
25       /* Stopped while running; i.e., completed */
26       curr->complete();
27     else
28       ASSERT(false);
29   }
30   next = model->scheduler->next_thread();
31   if (next)
32     next->set_state(THREAD_RUNNING);
33   DEBUG("(%d, %d)\n", curr ? curr->get_id() : -1, next ? next->get_id() : -1);
34   if (!next)
35     return 1;
36   return Thread::swap(model->get_system_context(), next);
37 }
38
39 static void thread_wait_finish(void) {
40   DBG();
41
42   while (!thread_system_next());
43 }
44
45 void real_main() {
46   thrd_t user_thread;
47   ucontext_t main_context;
48   
49   model = new ModelChecker();
50   
51   if (getcontext(&main_context))
52     return;
53   
54   model->set_system_context(&main_context);
55
56   do {
57     /* Start user program */
58     model->add_thread(new Thread(&user_thread, &user_main, NULL));
59     
60     /* Wait for all threads to complete */
61     thread_wait_finish();
62   } while (model->next_execution());
63   
64   delete model;
65   
66   DEBUG("Exiting\n");
67 }
68
69 int main_numargs;
70 char ** main_args;
71
72 /*
73  * Main system function
74  */
75 int main(int numargs, char ** args) {
76   /* Stash this stuff in case someone wants it eventually */
77   main_numargs=numargs;
78   main_args=args;
79
80   /* Let's jump in quickly and start running stuff */
81   initSnapShotLibrary(10000 /*int numbackingpages*/, 1024 /*unsigned int numsnapshots*/, 1024 /*unsigned int nummemoryregions*/ , 1000 /*int numheappages*/, &real_main /*MyFuncPtr entryPoint*/);
82 }