caudio/Source/cThread.cpp
Joshua Jones 75ece68dcf Added cross-platform Mutex and Thread classes.
Made cAudio, cAudioCapture, cAudioManager and other classes thread safe.
Made cAudioManager use a seperate update thread by default.
Added cAudioSleep, a cross-platform sleep() function
Moved global defines to cAudioDefines
Added defines to disable thread safety or the internal update thread if the user wishes it
Updated tutorials to reflect the changes made
2009-08-29 11:24:31 +00:00

39 lines
886 B
C++

#include "../Headers/cThread.h"
#ifdef _WIN32
#include <windows.h> //Basic windows includes
#include <process.h>
#else
#include <pthread.h> //Assumed linux system
#endif
namespace cAudio
{
#ifdef _WIN32
int cAudioThread::SpawnThread( unsigned __stdcall start_address( void* ), void *arg)
{
HANDLE threadHandle;
unsigned threadID = 0;
threadHandle = (HANDLE) _beginthreadex(NULL,0,start_address,arg,0,&threadID);
int state = (threadHandle==0) ? 1 : 0;
if(state == 0)
CloseHandle( threadHandle );
return state;
}
#else
int cAudioThread::SpawnThread( void* start_address( void* ), void *arg)
{
pthread_t threadHandle;
pthread_attr_t attr;
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
return pthread_create( &threadHandle, &attr, start_address, arg );
}
#endif
};