Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
pthreads are not used anymore. Standard C++ ones are
[simgrid.git] / src / bindings / java / JavaContext.hpp
1 /* Context switching within the JVM.                                        */
2
3 /* Copyright (c) 2009-2023. 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 "src/kernel/context/ContextThread.hpp"
15
16 #include "jmsg.hpp"
17
18 namespace simgrid::kernel::context {
19
20 class JavaContext;
21 class JavacontextFactory;
22
23 class JavaContext : public SerialThreadContext {
24 public:
25   // The java process instance bound with the msg process structure:
26   jobject jprocess_ = nullptr;
27   // JNI interface pointer associated to this thread:
28   JNIEnv* jenv_           = nullptr;
29
30   friend class JavaContextFactory;
31   JavaContext(std::function<void()>&& code, actor::ActorImpl* actor);
32
33   void start_hook() override;
34   void stop() override;
35 };
36
37 class JavaContextFactory : public ContextFactory {
38 public:
39   JavaContextFactory();
40   ~JavaContextFactory() override;
41   Context* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
42   void run_all(std::vector<actor::ActorImpl*> const& actors) override;
43 };
44
45 XBT_PRIVATE void java_main_jprocess(jobject process);
46
47 } // namespace simgrid::kernel::context
48
49 #endif /* SIMGRID_JAVA_JAVA_CONTEXT_HPP */