• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

RakThread.cpp

Go to the documentation of this file.
00001 #include "RakThread.h"
00002 #include "RakAssert.h"
00003 #include "RakNetDefines.h"
00004 #include "RakSleep.h"
00005 
00006 #if defined(_XBOX) || defined(X360)
00007                                                   
00008 #elif defined(_WIN32)
00009 #include "WindowsIncludes.h"
00010 #include <stdio.h>
00011         #if !defined(_WIN32_WCE)
00012         #include <process.h>
00013         #endif
00014 #else
00015 #include <pthread.h>
00016 #endif
00017 
00018 using namespace RakNet;
00019 
00020 #if defined(_WIN32_WCE)
00021 int RakThread::Create( LPTHREAD_START_ROUTINE start_address, void *arglist, int priority)
00022 #elif defined(_WIN32)
00023 int RakThread::Create( unsigned __stdcall start_address( void* ), void *arglist, int priority)
00024 #else
00025 int RakThread::Create( void* start_address( void* ), void *arglist, int priority)
00026 #endif
00027 {
00028 #ifdef _WIN32
00029         HANDLE threadHandle;
00030         unsigned threadID = 0;
00031 #if defined(_XBOX) || defined(X360)
00032                                                                                          
00033 #elif defined (_WIN32_WCE)
00034         threadHandle = CreateThread(NULL,MAX_ALLOCA_STACK_ALLOCATION*2,start_address,arglist,0,(DWORD*)&threadID);
00035         SetThreadPriority(threadHandle, priority);
00036 #else
00037         threadHandle = (HANDLE) _beginthreadex( NULL, MAX_ALLOCA_STACK_ALLOCATION*2, start_address, arglist, 0, &threadID );
00038 #endif
00039         SetThreadPriority(threadHandle, priority);
00040 
00041         if (threadHandle==0)
00042         {
00043                 return 1;
00044         }
00045         else
00046         {
00047                 CloseHandle( threadHandle );
00048                 return 0;
00049         }
00050 #else
00051         pthread_t threadHandle;
00052         // Create thread linux
00053         pthread_attr_t attr;
00054         sched_param param;
00055         param.sched_priority=priority;
00056         pthread_attr_init( &attr );
00057         pthread_attr_setschedparam(&attr, &param);
00058 #if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3)
00059                                                                                                                                                                   
00060 #else
00061         pthread_attr_setstacksize(&attr, MAX_ALLOCA_STACK_ALLOCATION*2);
00062 #endif
00063         pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
00064         int res = pthread_create( &threadHandle, &attr, start_address, arglist );
00065         RakAssert(res==0 && "pthread_create in RakThread.cpp failed.")
00066         return res;
00067 #endif
00068 }

Generated on Thu Sep 30 2010 01:27:26 for RakNet by  doxygen 1.7.1