- added more safety code arouind SDL threads in case we get failures from SDL itself
This commit is contained in:
parent
f7d9cd50a6
commit
de82843e73
|
@ -35,6 +35,7 @@ Thread::~Thread() {
|
||||||
|
|
||||||
void Thread::start() {
|
void Thread::start() {
|
||||||
thread = SDL_CreateThread(beginExecution, this);
|
thread = SDL_CreateThread(beginExecution, this);
|
||||||
|
assert(thread != NULL);
|
||||||
if(thread == NULL) {
|
if(thread == NULL) {
|
||||||
char szBuf[1024]="";
|
char szBuf[1024]="";
|
||||||
snprintf(szBuf,1023,"In [%s::%s Line: %d] thread == NULL",__FILE__,__FUNCTION__,__LINE__);
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] thread == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
@ -72,19 +73,39 @@ void Thread::resume() {
|
||||||
|
|
||||||
Mutex::Mutex() {
|
Mutex::Mutex() {
|
||||||
mutex = SDL_CreateMutex();
|
mutex = SDL_CreateMutex();
|
||||||
if(mutex == 0)
|
assert(mutex != NULL);
|
||||||
throw std::runtime_error("Couldn't initialize mutex");
|
if(mutex == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mutex::~Mutex() {
|
Mutex::~Mutex() {
|
||||||
|
if(mutex == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
SDL_DestroyMutex(mutex);
|
SDL_DestroyMutex(mutex);
|
||||||
|
mutex=NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mutex::p() {
|
void Mutex::p() {
|
||||||
|
if(mutex == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
SDL_mutexP(mutex);
|
SDL_mutexP(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mutex::v() {
|
void Mutex::v() {
|
||||||
|
if(mutex == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] mutex == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
SDL_mutexV(mutex);
|
SDL_mutexV(mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,18 +115,38 @@ void Mutex::v() {
|
||||||
|
|
||||||
Semaphore::Semaphore(Uint32 initialValue) {
|
Semaphore::Semaphore(Uint32 initialValue) {
|
||||||
semaphore = SDL_CreateSemaphore(initialValue);
|
semaphore = SDL_CreateSemaphore(initialValue);
|
||||||
|
if(semaphore == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] semaphore == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Semaphore::~Semaphore() {
|
Semaphore::~Semaphore() {
|
||||||
|
if(semaphore == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] semaphore == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
SDL_DestroySemaphore(semaphore);
|
SDL_DestroySemaphore(semaphore);
|
||||||
semaphore = NULL;
|
semaphore = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Semaphore::signal() {
|
void Semaphore::signal() {
|
||||||
|
if(semaphore == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] semaphore == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
SDL_SemPost(semaphore);
|
SDL_SemPost(semaphore);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Semaphore::waitTillSignalled() {
|
int Semaphore::waitTillSignalled() {
|
||||||
|
if(semaphore == NULL) {
|
||||||
|
char szBuf[1024]="";
|
||||||
|
snprintf(szBuf,1023,"In [%s::%s Line: %d] semaphore == NULL",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
throw runtime_error(szBuf);
|
||||||
|
}
|
||||||
int semValue = SDL_SemWait(semaphore);
|
int semValue = SDL_SemWait(semaphore);
|
||||||
return semValue;
|
return semValue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user