src/thread/windows/SDL_systhread.c
changeset 10148 4ed1bd3724d6
parent 10145 cd87106d1d47
equal deleted inserted replaced
10147:ddbdc9c1b92f 10148:4ed1bd3724d6
   119     pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
   119     pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
   120     pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
   120     pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
   121 #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
   121 #endif /* SDL_PASSED_BEGINTHREAD_ENDTHREAD */
   122     pThreadStartParms pThreadParms =
   122     pThreadStartParms pThreadParms =
   123         (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
   123         (pThreadStartParms) SDL_malloc(sizeof(tThreadStartParms));
       
   124     const DWORD flags = thread->stacksize ? STACK_SIZE_PARAM_IS_A_RESERVATION : 0;
   124     if (!pThreadParms) {
   125     if (!pThreadParms) {
   125         return SDL_OutOfMemory();
   126         return SDL_OutOfMemory();
   126     }
   127     }
   127     /* Save the function which we will have to call to clear the RTL of calling app! */
   128     /* Save the function which we will have to call to clear the RTL of calling app! */
   128     pThreadParms->pfnCurrentEndThread = pfnEndThread;
   129     pThreadParms->pfnCurrentEndThread = pfnEndThread;
   133     if (pfnBeginThread) {
   134     if (pfnBeginThread) {
   134         unsigned threadid = 0;
   135         unsigned threadid = 0;
   135         thread->handle = (SYS_ThreadHandle)
   136         thread->handle = (SYS_ThreadHandle)
   136             ((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize,
   137             ((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize,
   137                                      RunThreadViaBeginThreadEx,
   138                                      RunThreadViaBeginThreadEx,
   138                                      pThreadParms, 0, &threadid));
   139                                      pThreadParms, flags, &threadid));
   139     } else {
   140     } else {
   140         DWORD threadid = 0;
   141         DWORD threadid = 0;
   141         thread->handle = CreateThread(NULL, thread->stacksize,
   142         thread->handle = CreateThread(NULL, thread->stacksize,
   142                                       RunThreadViaCreateThread,
   143                                       RunThreadViaCreateThread,
   143                                       pThreadParms, 0, &threadid);
   144                                       pThreadParms, flags, &threadid);
   144     }
   145     }
   145     if (thread->handle == NULL) {
   146     if (thread->handle == NULL) {
   146         return SDL_SetError("Not enough resources to create thread");
   147         return SDL_SetError("Not enough resources to create thread");
   147     }
   148     }
   148     return 0;
   149     return 0;