Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[java] Fix RngStream.setPackageSeed
[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 java {
25
26 class JavaContext;
27 class JavacontextFactory;
28
29 class JavaContext : public simgrid::simix::Context {
30 public:
31   // The java process instance bound with the msg process structure:
32   jobject jprocess = nullptr;
33   // JNI interface pointer associated to this thread:
34   JNIEnv *jenv = nullptr;
35   xbt_os_thread_t thread = nullptr;
36   // Sempahore used to schedule/yield the process:
37   xbt_os_sem_t begin = nullptr;
38   // Semaphore used to schedule/unschedule the process:
39   xbt_os_sem_t end = nullptr;
40 public:
41   friend class JavaContextFactory;
42   JavaContext(std::function<void()> code,
43           void_pfn_smxprocess_t cleanup_func,
44           smx_process_t process);
45   ~JavaContext() override;
46   void stop() override;
47   void suspend() override;
48   void resume();
49 private:
50   static void* wrapper(void *data);
51 };
52
53 class JavaContextFactory : public simgrid::simix::ContextFactory {
54 public:
55   JavaContextFactory();
56   ~JavaContextFactory() override;
57   JavaContext* self() override;
58   JavaContext* create_context(std::function<void()> code,
59     void_pfn_smxprocess_t, smx_process_t process) override;
60   void run_all() override;
61 };
62
63 XBT_PRIVATE simgrid::simix::ContextFactory* java_factory();
64 XBT_PRIVATE void java_main_jprocess(jobject process);
65
66 }
67 }
68
69 #endif                          /* !_XBT_CONTEXT_JAVA_H */