Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / simix / ThreadContext.hpp
1 /* Copyright (c) 2009-2015. 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 /* \file ThreadContext.hpp Context switching with native threads */
8
9 #ifndef SIMGRID_SIMIX_THREAD_CONTEXT_HPP
10 #define SIMGRID_SIMIX_THREAD_CONTEXT_HPP
11
12 #include <simgrid/simix.hpp>
13
14
15 namespace simgrid {
16 namespace simix {
17
18 class ThreadContext;
19 class ThreadContextFactory;
20
21 class ThreadContext : public Context {
22 public:
23   friend ThreadContextFactory;
24   ThreadContext(xbt_main_func_t code,
25           int argc, char **argv,
26           void_pfn_smxprocess_t cleanup_func,
27           smx_process_t process);
28   ~ThreadContext();
29   void stop() override;
30   void suspend() override;
31 private:
32   /** A portable thread */
33   xbt_os_thread_t thread_;
34   /** Semaphore used to schedule/yield the process */
35   xbt_os_sem_t begin_;
36   /** Semaphore used to schedule/unschedule */
37   xbt_os_sem_t end_;
38 private:
39   static void* wrapper(void *param);
40 };
41
42 class ThreadContextFactory : public ContextFactory {
43 public:
44   ThreadContextFactory();
45   ~ThreadContextFactory();
46   virtual ThreadContext* create_context(
47     xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
48     smx_process_t process
49     ) override;
50   void run_all() override;
51   ThreadContext* self() override;
52 };
53
54 }
55 }
56
57 #endif