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.hpp"
21 #include "jmsg_process.h"
27 class JavacontextFactory;
29 class JavaContext : public simgrid::simix::Context {
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;
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;
47 void suspend() override;
50 static void* wrapper(void *data);
53 class JavaContextFactory : public simgrid::simix::ContextFactory {
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;
63 XBT_PRIVATE simgrid::simix::ContextFactory* java_factory();
64 XBT_PRIVATE void java_main_jprocess(jobject process);
69 #endif /* !_XBT_CONTEXT_JAVA_H */