nativelib - Compile fixes
authorJohn Hodge <[email protected]>
Mon, 28 Jan 2013 04:31:26 +0000 (12:31 +0800)
committerJohn Hodge <[email protected]>
Mon, 28 Jan 2013 04:31:26 +0000 (12:31 +0800)
Tools/NetTest/main.c
Tools/nativelib/include/threads_int.h
Tools/nativelib/threads.c

index d614da6..4f3e9f5 100644 (file)
@@ -46,6 +46,11 @@ int main(int argc, char *argv[])
                        if( ++i == argc ) { PrintUsage(argv[0]); return 1; }
                        NativeNic_AddDev(argv[i]);
                }
+               else if( strcmp(argv[i], "-ip") == 0 )
+               {
+                       if( ++i == argc ) { PrintUsage(argv[0]); return 1; }
+                       // TODO: parse argument and poke ipstack
+               }
        }
 
        // Run suite
index eb5f9df..cc0c3e0 100644 (file)
@@ -8,6 +8,9 @@
 #ifndef _THREADS_INT_H_
 #define _THREADS_INT_H_
 
+typedef struct sThreadIntMutex tThreadIntMutex;        // actually pthreads
+typedef struct sThreadIntSem   tThreadIntSem;
+
 struct sProcess
 {
        struct sProcess *Next;
@@ -24,10 +27,12 @@ struct sThread
 {
        struct sThread  *Next;
         int    TID;
-       
+
+       tThreadIntMutex *Protector;
+
        uint32_t        PendingEvents;
        uint32_t        WaitingEvents;
-       void    *WaitSemaphore; // pthreads
+       tThreadIntSem   *WaitSemaphore; // pthreads
        
        // Init Only
        void    (*SpawnFcn)(void*);
@@ -36,5 +41,16 @@ struct sThread
 
 extern int     Threads_int_CreateThread(struct sThread *Thread);
 
+extern tThreadIntMutex *Threads_int_MutexCreate(void);
+extern void    Threads_int_MutexDestroy(tThreadIntMutex *Mutex);
+extern void    Threads_int_MutexLock(tThreadIntMutex *Mutex);
+extern void    Threads_int_MutexRelease(tThreadIntMutex *Mutex);
+
+extern tThreadIntSem   *Threads_int_SemCreate(void);
+extern void    Threads_int_SemDestroy(tThreadIntSem *Sem);
+extern void    Threads_int_SemSignal(tThreadIntSem *Sem);
+extern void    Threads_int_SemWait(tThreadIntSem *Sem);
+extern void    Threads_int_SemWaitAll(tThreadIntSem *Sem);
+
 #endif
 
index d5f0465..eafe87f 100644 (file)
@@ -10,7 +10,6 @@
 #include <threads_int.h>
 
 // === GLOBALS ===
- int   gbThreads_MultithreadingEnabled;
 tThread __thread       *lpThreads_This;
 
 // === CODE ===
@@ -21,27 +20,39 @@ tThread *Proc_GetCurThread(void)
 
 void Threads_PostEvent(tThread *Thread, Uint32 Events)
 {
-       Threads_int_LockMutex(Thread->Protector);
+       if( !Thread ) {
+               // nope.avi
+               return ;
+       }
+       Threads_int_MutexLock(Thread->Protector);
        Thread->PendingEvents |= Events;
        if( Thread->WaitingEvents & Events )
-               Threads_int_SemaphoreSignal(Thread->WaitSemaphore);
-       Threads_int_ReleaseMutex(Thread->Protector);
+               Threads_int_SemSignal(Thread->WaitSemaphore);
+       Threads_int_MutexRelease(Thread->Protector);
 }
 
 Uint32 Threads_WaitEvents(Uint32 Events)
 {
-       Thread->WaitingEvents = Events;
-       Threads_int_SemaphoreWaitAll(Thread->WaitSemaphore);
-       Thread->WaitingEvents = 0;
-       Uint32  rv = Thread->PendingEvents;
+       if( !lpThreads_This ) {
+               Log_Notice("Threads", "_WaitEvents: Threading disabled");
+               return 0;
+       }
+       lpThreads_This->WaitingEvents = Events;
+       Threads_int_SemWaitAll(lpThreads_This->WaitSemaphore);
+       lpThreads_This->WaitingEvents = 0;
+       Uint32  rv = lpThreads_This->PendingEvents;
        return rv;
 }
 
 void Threads_ClearEvent(Uint32 Mask)
 {
-       Threads_int_LockMutex(Thread->Protector);
+       if( !lpThreads_This ) {
+               Log_Notice("Threads", "_ClearEvent: Threading disabled");
+               return ;
+       }
+       Threads_int_MutexLock(lpThreads_This->Protector);
        lpThreads_This->PendingEvents &= ~Mask;
-       Threads_int_ReleaseMutex(Thread->Protector);
+       Threads_int_MutexRelease(lpThreads_This->Protector);
 }
 
 tUID Threads_GetUID(void) { return 0; }
@@ -79,7 +90,7 @@ int *Threads_GetErrno(void)// __attribute__ ((weak))
 
 struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
 {
-       if( !gbThreads_MultithreadingEnabled )
+       if( !lpThreads_This )
        {
                Log_Error("Threads", "Multithreading is disabled in this build");
                return NULL;
@@ -90,8 +101,7 @@ struct sThread *Proc_SpawnWorker(void (*Fcn)(void*), void *Data)
                ret->SpawnFcn = Fcn;
                ret->SpawnData = Data;
                Threads_int_CreateThread(ret);
-               Log_Error("Threads", "TODO - Use pthreads to impliment Proc_SpawnWorker");
-               return NULL;
+               return ret;
        }
 }
 

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