summaryrefslogtreecommitdiff
path: root/src/common/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/thread.c')
-rw-r--r--src/common/thread.c37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/common/thread.c b/src/common/thread.c
index 1d0285302..a00bd6333 100644
--- a/src/common/thread.c
+++ b/src/common/thread.c
@@ -36,7 +36,7 @@
struct rAthread {
unsigned int myID;
-
+
RATHREAD_PRIO prio;
rAthreadProc proc;
void *param;
@@ -62,7 +62,7 @@ static struct rAthread l_threads[RA_THREADS_MAX];
void rathread_init(void) {
register unsigned int i;
memset(&l_threads, 0x00, RA_THREADS_MAX * sizeof(struct rAthread) );
-
+
for(i = 0; i < RA_THREADS_MAX; i++){
l_threads[i].myID = i;
}
@@ -80,7 +80,7 @@ void rathread_init(void) {
void rathread_final(void) {
register unsigned int i;
-
+
// Unterminated Threads Left?
// Shouldn't happen ..
// Kill 'em all!
@@ -91,8 +91,7 @@ void rathread_final(void) {
rathread_destroy(&l_threads[i]);
}
}
-
-
+
}//end: rathread_final()
@@ -112,7 +111,7 @@ static void *raThreadMainRedirector( void *p ){
sigset_t set; // on Posix Thread platforms
#endif
void *ret;
-
+
// Update myID @ TLS to right id.
#ifdef HAS_TLS
g_rathread_ID = ((rAthread*)p)->myID;
@@ -129,7 +128,7 @@ static void *raThreadMainRedirector( void *p ){
sigaddset(&set, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set, NULL);
-
+
#endif
@@ -181,14 +180,12 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
break;
}
}
-
+
if(handle == NULL){
ShowError("rAthread: cannot create new thread (entryPoint: %p) - no free thread slot found!", entryPoint);
return NULL;
}
-
-
-
+
handle->proc = entryPoint;
handle->param = param;
@@ -197,7 +194,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
#else
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, szStack);
-
+
if(pthread_create(&handle->hThread, &attr, raThreadMainRedirector, (void*)handle) != 0){
handle->proc = NULL;
handle->param = NULL;
@@ -207,7 +204,7 @@ rAthread *rathread_createEx(rAthreadProc entryPoint, void *param, size_t szStack
#endif
rathread_prio_set( handle, prio );
-
+
return handle;
}//end: rathread_createEx
@@ -220,10 +217,9 @@ void rathread_destroy(rAthread *handle) {
}
#else
if( pthread_cancel( handle->hThread ) == 0){
-
// We have to join it, otherwise pthread wont re-cycle its internal resources assoc. with this thread.
pthread_join( handle->hThread, NULL );
-
+
// Tell our manager to release resources ;)
rat_thread_terminated(handle);
}
@@ -233,7 +229,7 @@ void rathread_destroy(rAthread *handle) {
rAthread *rathread_self(void) {
#ifdef HAS_TLS
rAthread *handle = &l_threads[g_rathread_ID];
-
+
if(handle->proc != NULL) // entry point set, so its used!
return handle;
#else
@@ -247,14 +243,13 @@ rAthread *rathread_self(void) {
pthread_t hSelf;
hSelf = pthread_self();
#endif
-
+
for(i = 0; i < RA_THREADS_MAX; i++){
if(l_threads[i].hThread == hSelf && l_threads[i].proc != NULL)
return &l_threads[i];
}
-
#endif
-
+
return NULL;
}//end: rathread_self()
@@ -270,14 +265,12 @@ int rathread_get_tid(void) {
#else
return (intptr_t)pthread_self();
#endif
-
#endif
-
+
}//end: rathread_get_tid()
bool rathread_wait(rAthread *handle, void **out_exitCode) {
-
// Hint:
// no thread data cleanup routine call here!
// its managed by the callProxy itself..