From: John Hodge Date: Mon, 28 Jan 2013 04:31:26 +0000 (+0800) Subject: nativelib - Compile fixes X-Git-Tag: rel0.15~597^2~8 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=2d39fe63812216118aec6520ccfb6ce2f11d6fd2;p=tpg%2Facess2.git nativelib - Compile fixes --- diff --git a/Tools/NetTest/main.c b/Tools/NetTest/main.c index d614da6c..4f3e9f58 100644 --- a/Tools/NetTest/main.c +++ b/Tools/NetTest/main.c @@ -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 diff --git a/Tools/nativelib/include/threads_int.h b/Tools/nativelib/include/threads_int.h index eb5f9dff..cc0c3e05 100644 --- a/Tools/nativelib/include/threads_int.h +++ b/Tools/nativelib/include/threads_int.h @@ -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 diff --git a/Tools/nativelib/threads.c b/Tools/nativelib/threads.c index d5f04652..eafe87f4 100644 --- a/Tools/nativelib/threads.c +++ b/Tools/nativelib/threads.c @@ -10,7 +10,6 @@ #include // === 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; } }