コード例 #1
0
ファイル: smx_context_sysv.c プロジェクト: tempbottle/simgrid
void SIMIX_ctx_sysv_factory_init(smx_context_factory_t *factory)
{
  smx_ctx_base_factory_init(factory);
  XBT_VERB("Activating SYSV context factory");

  (*factory)->finalize = smx_ctx_sysv_factory_finalize;
  (*factory)->create_context = smx_ctx_sysv_create_context;
  /* Do not overload that method (*factory)->finalize */
  (*factory)->free = smx_ctx_sysv_free;
  (*factory)->name = "smx_sysv_context_factory";

  if (SIMIX_context_is_parallel()) {
#ifdef CONTEXT_THREADS  /* To use parallel ucontexts a thread pool is needed */
    int nthreads = SIMIX_context_get_nthreads();
    sysv_parmap = xbt_parmap_new(nthreads, SIMIX_context_get_parallel_mode());
    sysv_workers_context = xbt_new(smx_ctx_sysv_t, nthreads);
    sysv_maestro_context = NULL;
    xbt_os_thread_key_create(&sysv_worker_id_key);
    (*factory)->stop = smx_ctx_sysv_stop_parallel;
    (*factory)->suspend = smx_ctx_sysv_suspend_parallel;
    (*factory)->runall = smx_ctx_sysv_runall_parallel;
#else
    THROWF(arg_error, 0, "No thread support for parallel context execution");
#endif
  } else {
    (*factory)->stop = smx_ctx_sysv_stop_serial;
    (*factory)->suspend = smx_ctx_sysv_suspend_serial;
    (*factory)->runall = smx_ctx_sysv_runall_serial;
  }    
}
コード例 #2
0
void SIMIX_ctx_cojava_factory_init(smx_context_factory_t * factory)
{
  /* instantiate the context factory */
  smx_ctx_base_factory_init(factory);

  (*factory)->create_context = smx_ctx_cojava_factory_create_context;
  /* Leave default behavior of (*factory)->finalize */
  (*factory)->free = smx_ctx_cojava_free;
  (*factory)->stop = smx_ctx_cojava_stop;
  (*factory)->suspend = smx_ctx_cojava_suspend;
  (*factory)->runall = smx_ctx_cojava_runall;
  (*factory)->name = "ctx_cojava_factory";
  //(*factory)->finalize = smx_ctx_base_factory_finalize;
  (*factory)->self = smx_ctx_cojava_self;
  (*factory)->get_process = smx_ctx_base_get_process;

  global_env = get_current_thread_env();

  coclass = (*global_env)->FindClass(global_env, "java/dyn/Coroutine");
  xbt_assert((coclass != NULL), "Can't find java.dyn.Coroutine class.");
  //Cache the method id we are going to use
  coroutine_init = (*global_env)->GetMethodID(global_env, coclass, "<init>", "(Ljava/lang/Runnable;)V");
  xbt_assert((coroutine_init != NULL), "Can't find <init>");
  coroutine_stop = (*global_env)->GetMethodID(global_env, coclass, "stop", "()V");
  xbt_assert((coroutine_stop != NULL), "Method not found...");
  coroutine_yield = (*global_env)->GetStaticMethodID(global_env, coclass, "yield", "()V");
  xbt_assert((coroutine_yield != NULL), "Method yield not found.");
  coroutine_yieldTo = (*global_env)->GetStaticMethodID(global_env, coclass, "yieldTo", "(Ljava/dyn/Coroutine;)V");
  xbt_assert((coroutine_yieldTo != NULL), "Method yieldTo not found.");

  jclass class_thread = (*global_env)->FindClass(global_env, "java/lang/Thread");
  xbt_assert((class_thread != NULL), "Can't find java.lang.Thread class");
  
  jclass class_coroutine_support = (*global_env)->FindClass(global_env, "java/dyn/CoroutineSupport");
  xbt_assert((class_coroutine_support != NULL), "Can't find java.dyn.CoroutineSupport class");
  jmethodID thread_get_current = (*global_env)->GetStaticMethodID(global_env, class_thread, "currentThread", "()Ljava/lang/Thread;");
  xbt_assert((thread_get_current != NULL), "Can't find Thread.currentThread() method.");

  /**
   * Retrieve maetro coroutine object
   */
  jobject jthread;
  jthread = (*global_env)->CallStaticObjectMethod(global_env, class_thread, thread_get_current);
  xbt_assert((jthread != NULL), "Can't find current thread.");

  jmethodID thread_get_coroutine_support = (*global_env)->GetMethodID(global_env, class_thread, "getCoroutineSupport", "()Ljava/dyn/CoroutineSupport;");
  xbt_assert((thread_get_coroutine_support != NULL), "Can't find Thread.getCoroutineSupport method");

  jobject jcoroutine_support;
  jcoroutine_support = (*global_env)->CallObjectMethod(global_env, jthread, thread_get_coroutine_support);
  xbt_assert((jcoroutine_support != NULL), "Can't find coroutine support object");
  //FIXME ? Be careful, might change in the implementation (we are relying on private fields, so...).
  jfieldID coroutine_support_thread_coroutine = (*global_env)->GetFieldID(global_env, class_coroutine_support, "threadCoroutine", "Ljava/dyn/Coroutine;");
  xbt_assert((coroutine_support_thread_coroutine != NULL), "Can't find threadCoroutine field");
  cojava_maestro_coroutine = (jobject)(*global_env)->GetObjectField(global_env, jcoroutine_support, coroutine_support_thread_coroutine);
  xbt_assert((cojava_maestro_coroutine != NULL), "Can't find the thread coroutine.");
  cojava_maestro_coroutine = (*global_env)->NewGlobalRef(global_env, cojava_maestro_coroutine);
  xbt_assert((cojava_maestro_coroutine != NULL), "Can't get a global reference to the thread coroutine.");
}