nativelib - Implimenting missing functions
authorJohn Hodge <[email protected]>
Mon, 28 Jan 2013 06:09:55 +0000 (14:09 +0800)
committerJohn Hodge <[email protected]>
Mon, 28 Jan 2013 06:09:55 +0000 (14:09 +0800)
Tools/nativelib/include/acess.h
Tools/nativelib/include/threads_int.h
Tools/nativelib/threads_int.c

index c7f7775..da1693f 100644 (file)
@@ -157,6 +157,7 @@ static inline int  CPU_HAS_LOCK(tShortSpinlock *m) { return *m; }
 #endif
 
 static inline intptr_t MM_GetPhysAddr(void *Ptr) { return 1; }
+static inline int      MM_IsUser(const void *Ptr) { return 1; }
 
 #endif
 
index cc0c3e0..240f525 100644 (file)
@@ -26,6 +26,7 @@ struct sProcess
 struct sThread
 {
        struct sThread  *Next;
+       void    *ThreadHandle;
         int    TID;
 
        tThreadIntMutex *Protector;
index 35125a1..2274eea 100644 (file)
@@ -6,20 +6,98 @@
  * - Internal threading functions
  */
 #include <stddef.h>
+#include <stdlib.h>
 #include <stdint.h>
 #include <acess_logging.h>
 #include <threads_int.h>
 #include <pthread_weak.h>
 
+// === TYPES ===
+typedef struct sThread tThread;
+struct sThreadIntMutex { int lock; };
+struct sThreadIntSem { int val; };
+
 // === CODE ===
-void Threads_int_LockMutex(void *Mutex)
+void Threads_int_MutexLock(tThreadIntMutex *Mutex)
 {
+       if( !Mutex ) {
+               return ;
+       }
        if( pthread_mutex_lock )
        {
+               pthread_mutex_lock( (void*)Mutex );
+       }
+       else
+       {
+               if( Mutex->lock )
+                       Log_KernelPanic("Threads", "Double mutex lock");
+               Mutex->lock = 1;
+       }
+}
+
+void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
+{
+       if( !Mutex ) {
+               return ;
+       }
+
+       if( pthread_mutex_unlock )
+       {
+               pthread_mutex_unlock( (void*)Mutex );
+       }
+       else
+       {
+               if( !Mutex->lock )
+                       Log_Notice("Threads", "Release of non-locked mutex %p", Mutex);
+               Mutex->lock = 0;
+       }
+}
+
+void Threads_int_SemSignal(tThreadIntSem *Sem)
+{
+       if( sem_wait )
+       {
+               sem_wait( (void*)Sem );
+       }
+       else
+       {
+               Sem->val ++;
+       }
+}
+
+void Threads_int_SemWaitAll(tThreadIntSem *Sem)
+{
+       if( sem_post )
+       {
+               sem_post( (void*)Sem );
+       }
+       else
+       {
+               if( !Sem->val )
+                       Log_KernelPanic("Threads", "Waiting on empty semaphre %p", Sem);
+               Sem->val = 0;
+       }
+}
+
+void *Threads_int_ThreadRoot(void *ThreadPtr)
+{
+       tThread *thread = ThreadPtr;
+       thread->SpawnFcn(thread->SpawnData);
+       return NULL;
+}
+
+int Threads_int_CreateThread(tThread *Thread)
+{
+       if( pthread_create )
+       {
+               pthread_t *pthread = malloc(sizeof(pthread_t));
+               Thread->ThreadHandle = pthread;
+               return pthread_create(pthread, NULL, Threads_int_ThreadRoot, Thread);
        }
        else
        {
-               
+               Log_KernelPanic("Threads", "Link with pthreads to use threading");
+               return -1;
        }
 }
 

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