X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/76264ed1928b146602ee73794d86798739cd1209..67d66b0cf79b9fc02c0450f254584693dbf21d3b:/src/bindings/java/JavaContext.hpp diff --git a/src/bindings/java/JavaContext.hpp b/src/bindings/java/JavaContext.hpp index fbad8821dd..70873a5d3b 100644 --- a/src/bindings/java/JavaContext.hpp +++ b/src/bindings/java/JavaContext.hpp @@ -1,5 +1,6 @@ -/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team. - * All rights reserved. */ +/* Context switching within the JVM. */ + +/* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -7,63 +8,47 @@ #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP #define SIMGRID_JAVA_JAVA_CONTEXT_HPP +#include #include -#include -#include -#include - -#include "src/simix/smx_private.hpp" +#include "src/kernel/context/ContextThread.hpp" -#include "jmsg.h" -#include "jmsg_process.h" +#include "jmsg.hpp" namespace simgrid { -namespace java { +namespace kernel { +namespace context { class JavaContext; class JavacontextFactory; -class JavaContext : public simgrid::simix::Context { +class JavaContext : public SerialThreadContext { public: // The java process instance bound with the msg process structure: - jobject jprocess; + jobject jprocess_ = nullptr; // JNI interface pointer associated to this thread: - JNIEnv *jenv; - xbt_os_thread_t thread; - // Sempahore used to schedule/yield the process: - xbt_os_sem_t begin; - // Semaphore used to schedule/unschedule the process: - xbt_os_sem_t end; -public: + JNIEnv* jenv_ = nullptr; + friend class JavaContextFactory; - JavaContext(xbt_main_func_t code, - int argc, char **argv, - void_pfn_smxprocess_t cleanup_func, - smx_process_t process); - ~JavaContext() override; - void stop() override; - void suspend() override; - void resume(); -private: - static void* wrapper(void *data); + JavaContext(std::function&& code, actor::ActorImpl* actor); + + void start_hook() override; + void stop_hook() override; }; -class JavaContextFactory : public simgrid::simix::ContextFactory { +class JavaContextFactory : public ContextFactory { public: JavaContextFactory(); ~JavaContextFactory() override; - JavaContext* self() override; - JavaContext* create_context( - xbt_main_func_t, int, char **, void_pfn_smxprocess_t, - smx_process_t process - ) override; + Context* create_context(std::function&& code, actor::ActorImpl* actor) override; void run_all() override; }; -XBT_PRIVATE simgrid::simix::ContextFactory* java_factory(); +XBT_PRIVATE ContextFactory* java_factory(); +XBT_PRIVATE void java_main_jprocess(jobject process); -} -} +} // namespace context +} // namespace kernel +} // namespace simgrid -#endif /* !_XBT_CONTEXT_JAVA_H */ +#endif /* SIMGRID_JAVA_JAVA_CONTEXT_HPP */