Top


定義場所(file name)

jdk/src/windows/bin/java_md.c

説明(description)

/*
 * Block current thread and continue execution in a new thread
 */

名前(function name)

int
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {

本体部(body)

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

        int rslt = 0;
        unsigned thread_id;

  {- -------------------------------------------
  (1) (STACK_SIZE_PARAM_IS_A_RESERVATION が定義されていない環境で
       コンパイルする場合のために, 一応ここで定義をしておく)
      ---------------------------------------- -}

    #ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
    #define STACK_SIZE_PARAM_IS_A_RESERVATION  (0x10000)
    #endif

  {- -------------------------------------------
  (1) _beginthredex() で子スレッドを作る.

      (なお, 子スレッドのエントリポイントは continuation 引数で指定される)

      (なお, スレッド生成に失敗した場合は, 
      STACK_SIZE_PARAM_IS_A_RESERVATION がサポートされていないだけかもしれないので, 
      もう一度 (STACK_SIZE_PARAM_IS_A_RESERVATION を付けずに) _beginthredex() を呼び出す)
      ---------------------------------------- -}

        /*
         * STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not
         * supported on older version of Windows. Try first with the flag; and
         * if that fails try again without the flag. See MSDN document or HotSpot
         * source (os_win32.cpp) for details.
         */
        HANDLE thread_handle =
          (HANDLE)_beginthreadex(NULL,
                                 (unsigned)stack_size,
                                 continuation,
                                 args,
                                 STACK_SIZE_PARAM_IS_A_RESERVATION,
                                 &thread_id);
        if (thread_handle == NULL) {
          thread_handle =
          (HANDLE)_beginthreadex(NULL,
                                 (unsigned)stack_size,
                                 continuation,
                                 args,
                                 0,
                                 &thread_id);
        }

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

        /* AWT preloading (AFTER main thread start) */
    #ifdef ENABLE_AWT_PRELOAD
        /* D3D preloading */
        if (awtPreloadD3D != 0) {
            char *envValue;
            /* D3D routines checks env.var J2D_D3D if no appropriate
             * command line params was specified
             */
            envValue = getenv("J2D_D3D");
            if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
                awtPreloadD3D = 0;
            }
            /* Test that AWT preloading isn't disabled by J2D_D3D_PRELOAD env.var */
            envValue = getenv("J2D_D3D_PRELOAD");
            if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
                awtPreloadD3D = 0;
            }
            if (awtPreloadD3D < 0) {
                /* If awtPreloadD3D is still undefined (-1), test
                 * if it is turned on by J2D_D3D_PRELOAD env.var.
                 * By default it's turned OFF.
                 */
                awtPreloadD3D = 0;
                if (envValue != NULL && JLI_StrCaseCmp(envValue, "true") == 0) {
                    awtPreloadD3D = 1;
                }
             }
        }
        if (awtPreloadD3D) {
            AWTPreload(D3D_PRELOAD_FUNC);
        }
    #endif /* ENABLE_AWT_PRELOAD */

  {- -------------------------------------------
  (1) 自分は WaitForSingleObject() で作ったスレッドの終了を待つ.

      (なお, _beginthreadex() が2回とも失敗した場合には, 自分で残りの処理を実行する模様.
       といっても, JNI_CreateJavaVM() 内でもスレッドは作るので, そこで失敗してしまうだろうが...)
      ---------------------------------------- -}

        if (thread_handle) {
          WaitForSingleObject(thread_handle, INFINITE);
          GetExitCodeThread(thread_handle, &rslt);
          CloseHandle(thread_handle);
        } else {
          rslt = continuation(args);
        }

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

    #ifdef ENABLE_AWT_PRELOAD
        if (awtPreloaded) {
            AWTPreloadStop();
        }
    #endif /* ENABLE_AWT_PRELOAD */

  {- -------------------------------------------
  (1) 結果をリターン
      ---------------------------------------- -}

        return rslt;
    }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.