| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /*
- * Copyright (c) 2014, Oculus VR, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- */
- #include "RakThread.h"
- #include "RakAssert.h"
- #include "RakNetDefines.h"
- #include "RakSleep.h"
- #include "RakMemoryOverride.h"
- using namespace RakNet;
- #if defined(_WIN32)
- #include "WindowsIncludes.h"
- #include <stdio.h>
- #if !defined(_WIN32_WCE)
- #include <process.h>
- #endif
- #else
- #include <pthread.h>
- #endif
- #if defined(_WIN32_WCE) || defined(WINDOWS_PHONE_8) || defined(WINDOWS_STORE_RT)
- int RakThread::Create( LPTHREAD_START_ROUTINE start_address, void *arglist, int priority)
- #elif defined(_WIN32)
- int RakThread::Create( unsigned __stdcall start_address( void* ), void *arglist, int priority)
- #else
- int RakThread::Create( void* start_address( void* ), void *arglist, int priority)
- #endif
- {
- #ifdef _WIN32
- HANDLE threadHandle;
- unsigned threadID = 0;
- #if defined(WINDOWS_PHONE_8) || defined(WINDOWS_STORE_RT)
- threadHandle = CreateThread(NULL,0,start_address,arglist,CREATE_SUSPENDED, 0);
- #elif defined _WIN32_WCE
- threadHandle = CreateThread(NULL,MAX_ALLOCA_STACK_ALLOCATION*2,start_address,arglist,0,(DWORD*)&threadID);
- #else
- threadHandle = (HANDLE) _beginthreadex( NULL, MAX_ALLOCA_STACK_ALLOCATION*2, start_address, arglist, 0, &threadID );
- #endif
-
- SetThreadPriority(threadHandle, priority);
- #if defined(WINDOWS_PHONE_8) || defined(WINDOWS_STORE_RT)
- ResumeThread(threadHandle);
- #endif
- if (threadHandle==0)
- {
- return 1;
- }
- else
- {
- CloseHandle( threadHandle );
- return 0;
- }
- #else
- pthread_t threadHandle;
- // Create thread linux
- pthread_attr_t attr;
- sched_param param;
- param.sched_priority=priority;
- pthread_attr_init( &attr );
- pthread_attr_setschedparam(&attr, ¶m);
- pthread_attr_setstacksize(&attr, MAX_ALLOCA_STACK_ALLOCATION*2);
- pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
- int res = pthread_create( &threadHandle, &attr, start_address, arglist );
- RakAssert(res==0 && "pthread_create in RakThread.cpp failed.")
- return res;
- #endif
- }
|