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
13 #include <simgrid/simix.h>
14 #include <xbt/xbt_os_thread.h>
16 #include "src/simix/smx_private.hpp"
19 #include "jmsg_process.h"
25 class JavacontextFactory;
27 class JavaContext : public simgrid::simix::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(xbt_main_func_t code,
41 int argc, char **argv,
42 void_pfn_smxprocess_t cleanup_func,
43 smx_process_t process);
44 ~JavaContext() override;
46 void suspend() override;
49 static void* wrapper(void *data);
52 class JavaContextFactory : public simgrid::simix::ContextFactory {
55 ~JavaContextFactory() override;
56 JavaContext* self() override;
57 JavaContext* create_context(
58 xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
61 void run_all() override;
64 XBT_PRIVATE simgrid::simix::ContextFactory* java_factory();
65 XBT_PRIVATE int java_main(int argc, char *argv[]);
70 #endif /* !_XBT_CONTEXT_JAVA_H */