1 /* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
8 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
15 #include <simgrid/simix.h>
16 #include <xbt/xbt_os_thread.h>
18 #include "src/simix/smx_private.h"
21 #include "jmsg_process.h"
28 class JavacontextFactory;
30 class JavaContext : public simgrid::kernel::context::Context {
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;
42 friend class JavaContextFactory;
43 JavaContext(std::function<void()> code,
44 void_pfn_smxprocess_t cleanup_func,
46 ~JavaContext() override;
48 void suspend() override;
51 static void* wrapper(void *data);
54 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
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;
64 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
65 XBT_PRIVATE void java_main_jprocess(jobject process);
67 }}} // namespace simgrid::kernel::context
69 #endif /* !_XBT_CONTEXT_JAVA_H */