Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar by removing useless asignments and return statements
[simgrid.git] / src / bindings / java / JavaContext.hpp
1 /* Copyright (c) 2009-2010, 2012-2014. 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 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
8 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
9
10 #include <functional>
11
12 #include <jni.h>
13
14 #include <xbt/misc.h>
15 #include <simgrid/simix.h>
16 #include <xbt/xbt_os_thread.h>
17
18 #include "src/simix/smx_private.h"
19
20 #include "jmsg.h"
21 #include "jmsg_process.h"
22
23 namespace simgrid {
24 namespace kernel {
25 namespace context {
26
27 class JavaContext;
28 class JavacontextFactory;
29
30 class JavaContext : public simgrid::kernel::context::Context {
31 public:
32   // The java process instance bound with the msg process structure:
33   jobject jprocess = nullptr;
34   // JNI interface pointer associated to this thread:
35   JNIEnv *jenv = nullptr;
36   xbt_os_thread_t thread = nullptr;
37   // Sempahore used to schedule/yield the process:
38   xbt_os_sem_t begin = nullptr;
39   // Semaphore used to schedule/unschedule the process:
40   xbt_os_sem_t end = nullptr;
41 public:
42   friend class JavaContextFactory;
43   JavaContext(std::function<void()> code,
44           void_pfn_smxprocess_t cleanup_func,
45           smx_actor_t process);
46   ~JavaContext() override;
47   void stop() override;
48   void suspend() override;
49   void resume();
50 private:
51   static void* wrapper(void *data);
52 };
53
54 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
55 public:
56   JavaContextFactory();
57   ~JavaContextFactory() override;
58   JavaContext* self() override;
59   JavaContext* create_context(std::function<void()> code,
60     void_pfn_smxprocess_t, smx_actor_t process) override;
61   void run_all() override;
62 };
63
64 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
65 XBT_PRIVATE void java_main_jprocess(jobject process);
66
67 }}} // namespace simgrid::kernel::context
68
69 #endif                          /* !_XBT_CONTEXT_JAVA_H */