Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
unify how threaded and parallelisable context factories find context_self
[simgrid.git] / src / bindings / java / JavaContext.hpp
1 /* Context switching within the JVM.                                        */
2
3 /* Copyright (c) 2009-2018. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
9 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
10
11 #include <functional>
12 #include <jni.h>
13
14 #include "simgrid/simix.h"
15 #include "src/kernel/context/ContextThread.hpp"
16 #include "src/simix/smx_private.hpp"
17 #include "xbt/xbt_os_thread.h"
18
19 #include "jmsg.hpp"
20
21 namespace simgrid {
22 namespace kernel {
23 namespace context {
24
25 class JavaContext;
26 class JavacontextFactory;
27
28 class JavaContext : public simgrid::kernel::context::SerialThreadContext {
29 public:
30   // The java process instance bound with the msg process structure:
31   jobject jprocess_ = nullptr;
32   // JNI interface pointer associated to this thread:
33   JNIEnv* jenv_           = nullptr;
34
35   friend class JavaContextFactory;
36   JavaContext(std::function<void()> code,
37           void_pfn_smxprocess_t cleanup_func,
38           smx_actor_t process);
39
40   void start_hook() override;
41   void stop() override;
42 };
43
44 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
45 public:
46   JavaContextFactory();
47   ~JavaContextFactory() override;
48   JavaContext* create_context(std::function<void()> code,
49     void_pfn_smxprocess_t, smx_actor_t process) override;
50   void run_all() override;
51 };
52
53 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
54 XBT_PRIVATE void java_main_jprocess(jobject process);
55
56 }}} // namespace simgrid::kernel::context
57
58 #endif                          /* !_XBT_CONTEXT_JAVA_H */