Tools/nativelib - Threading fixes
authorJohn Hodge <[email protected]>
Fri, 8 Feb 2013 10:50:54 +0000 (18:50 +0800)
committerJohn Hodge <[email protected]>
Fri, 8 Feb 2013 10:50:54 +0000 (18:50 +0800)
Tools/nativelib/include/pthread_weak.h
Tools/nativelib/threads.c
Tools/nativelib/threads_int.c
Tools/nativelib/time.c

index 30ac250..ccc4002 100644 (file)
@@ -18,6 +18,7 @@ extern int pthread_mutex_destroy (pthread_mutex_t*) __attribute__ ((weak));
 
 extern int sem_init(sem_t *sem, int pshared, unsigned int value) __attribute__ ((weak));
 extern int sem_wait(sem_t *sem) __attribute__ ((weak));
+extern int sem_trywait(sem_t *sem) __attribute__ ((weak));
 extern int sem_post(sem_t *sem) __attribute__ ((weak));
 extern int sem_getvalue(sem_t *sem, int *sval) __attribute__ ((weak));
 
index b698770..aec7076 100644 (file)
@@ -23,6 +23,7 @@ tShortSpinlock        glThreadListLock;
 void Threads_int_Init(void)
 {
        lpThreads_This = Threads_int_CreateTCB(NULL);
+       Threads_SetName("ThreadZero");
 }
 
 tThread *Proc_GetCurThread(void)
index 324b952..b2ad9f6 100644 (file)
@@ -8,6 +8,7 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdio.h>     // printf debugging
 #include <acess_logging.h>
 #include <threads_int.h>
 #include <pthread_weak.h>
@@ -90,9 +91,9 @@ tThreadIntSem *Threads_int_SemCreate(void)
 
 void Threads_int_SemSignal(tThreadIntSem *Sem)
 {
-       if( sem_wait )
+       if( sem_post )
        {
-               sem_wait( (void*)Sem );
+               sem_post( (void*)Sem );
        }
        else
        {
@@ -102,9 +103,12 @@ void Threads_int_SemSignal(tThreadIntSem *Sem)
 
 void Threads_int_SemWaitAll(tThreadIntSem *Sem)
 {
-       if( sem_post )
+       if( sem_wait )
        {
-               sem_post( (void*)Sem );
+               // TODO: Handle multiples
+               sem_wait( (void*)Sem );
+               while( sem_trywait((void*)Sem) )
+                       ;
        }
        else
        {
@@ -151,7 +155,9 @@ void SHORTLOCK(tShortSpinlock *Lock)
                        *Lock = malloc(sizeof(pthread_mutex_t));
                        pthread_mutex_init(*Lock, NULL);
                }
+//             printf("%p: SHORTLOCK wait\n", lpThreads_This);
                pthread_mutex_lock(*Lock);
+//             printf("%p: SHORTLOCK held %p\n", lpThreads_This, __builtin_return_address(0));
        }
 }
 
@@ -165,6 +171,7 @@ void SHORTREL(tShortSpinlock *Lock)
        else
        {
                pthread_mutex_unlock(*Lock);
+//             printf("%p: SHORTLOCK rel\n", lpThreads_This);
        }
 }
 
index 4eb7463..f2f18d8 100644 (file)
@@ -19,6 +19,7 @@ void Time_ScheduleTimer(tTimer *Timer, int Delta)
        if( !Timer )
        {
                // SIGALRM
+               Log_Warning("Time", "TODO: Alarm event in %i ms", Delta);
        }
        else
        {

UCC git Repository :: git.ucc.asn.au