1 /* Context switching within the JVM. */
3 /* Copyright (c) 2009-2017. The SimGrid Team. All rights reserved. */
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. */
8 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
9 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
14 #include "simgrid/simix.h"
15 #include "src/simix/smx_private.h"
16 #include "xbt/xbt_os_thread.h"
25 class JavacontextFactory;
27 class JavaContext : public simgrid::kernel::context::Context {
29 // The java process instance bound with the msg process structure:
30 jobject jprocess = nullptr;
31 // JNI interface pointer associated to this thread:
32 JNIEnv *jenv = nullptr;
33 xbt_os_thread_t thread = nullptr;
34 // Sempahore used to schedule/yield the process:
35 xbt_os_sem_t begin = nullptr;
36 // Semaphore used to schedule/unschedule the process:
37 xbt_os_sem_t end = nullptr;
39 friend class JavaContextFactory;
40 JavaContext(std::function<void()> code,
41 void_pfn_smxprocess_t cleanup_func,
43 ~JavaContext() override;
45 void suspend() override;
48 static void* wrapper(void *data);
51 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
54 ~JavaContextFactory() override;
55 JavaContext* self() override;
56 JavaContext* create_context(std::function<void()> code,
57 void_pfn_smxprocess_t, smx_actor_t process) override;
58 void run_all() override;
61 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
62 XBT_PRIVATE void java_main_jprocess(jobject process);
64 }}} // namespace simgrid::kernel::context
66 #endif /* !_XBT_CONTEXT_JAVA_H */