git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tools/NetTest - Add a runner to test networking stack
[tpg/acess2.git]
/
Tools
/
nativelib
/
threads_int.c
diff --git
a/Tools/nativelib/threads_int.c
b/Tools/nativelib/threads_int.c
index
324b952
..
8ab9b34
100644
(file)
--- a/
Tools/nativelib/threads_int.c
+++ b/
Tools/nativelib/threads_int.c
@@
-4,10
+4,14
@@
*
* threads_int.c
* - Internal threading functions
*
* threads_int.c
* - Internal threading functions
+ *
+ * POSIX Mutex/Semaphore management
+ * Wait state
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
*/
#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>
#include <acess_logging.h>
#include <threads_int.h>
#include <pthread_weak.h>
@@
-27,7
+31,7
@@
int Threads_int_ThreadingEnabled(void)
tThreadIntMutex *Threads_int_MutexCreate(void)
{
tThreadIntMutex *Threads_int_MutexCreate(void)
{
- if(
pthread_mutex_init
)
+ if(
Threads_int_ThreadingEnabled()
)
{
tThreadIntMutex *ret = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init( (void*)ret, NULL );
{
tThreadIntMutex *ret = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init( (void*)ret, NULL );
@@
-44,7
+48,7
@@
void Threads_int_MutexLock(tThreadIntMutex *Mutex)
if( !Mutex ) {
return ;
}
if( !Mutex ) {
return ;
}
- if(
pthread_mutex_lock
)
+ if(
Threads_int_ThreadingEnabled()
)
{
pthread_mutex_lock( (void*)Mutex );
}
{
pthread_mutex_lock( (void*)Mutex );
}
@@
-62,7
+66,7
@@
void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
return ;
}
return ;
}
- if(
pthread_mutex_unlock
)
+ if(
Threads_int_ThreadingEnabled()
)
{
pthread_mutex_unlock( (void*)Mutex );
}
{
pthread_mutex_unlock( (void*)Mutex );
}
@@
-76,7
+80,7
@@
void Threads_int_MutexRelease(tThreadIntMutex *Mutex)
tThreadIntSem *Threads_int_SemCreate(void)
{
tThreadIntSem *Threads_int_SemCreate(void)
{
- if(
sem_init
)
+ if(
Threads_int_ThreadingEnabled()
)
{
tThreadIntSem *ret = malloc(sizeof(sem_t));
sem_init( (void*)ret, 0, 0 );
{
tThreadIntSem *ret = malloc(sizeof(sem_t));
sem_init( (void*)ret, 0, 0 );
@@
-90,9
+94,9
@@
tThreadIntSem *Threads_int_SemCreate(void)
void Threads_int_SemSignal(tThreadIntSem *Sem)
{
void Threads_int_SemSignal(tThreadIntSem *Sem)
{
- if(
sem_wait
)
+ if(
Threads_int_ThreadingEnabled()
)
{
{
- sem_
wai
t( (void*)Sem );
+ sem_
pos
t( (void*)Sem );
}
else
{
}
else
{
@@
-102,9
+106,12
@@
void Threads_int_SemSignal(tThreadIntSem *Sem)
void Threads_int_SemWaitAll(tThreadIntSem *Sem)
{
void Threads_int_SemWaitAll(tThreadIntSem *Sem)
{
- if(
sem_post
)
+ if(
Threads_int_ThreadingEnabled()
)
{
{
- sem_post( (void*)Sem );
+ // TODO: Handle multiples
+ sem_wait( (void*)Sem );
+ while( sem_trywait((void*)Sem) )
+ ;
}
else
{
}
else
{
@@
-125,7
+132,7
@@
void *Threads_int_ThreadRoot(void *ThreadPtr)
int Threads_int_CreateThread(tThread *Thread)
{
int Threads_int_CreateThread(tThread *Thread)
{
- if(
pthread_create
)
+ if(
Threads_int_ThreadingEnabled()
)
{
pthread_t *pthread = malloc(sizeof(pthread_t));
Thread->ThreadHandle = pthread;
{
pthread_t *pthread = malloc(sizeof(pthread_t));
Thread->ThreadHandle = pthread;
@@
-140,36
+147,46
@@
int Threads_int_CreateThread(tThread *Thread)
void SHORTLOCK(tShortSpinlock *Lock)
{
void SHORTLOCK(tShortSpinlock *Lock)
{
- if( !pthread_mutex_init )
- {
- if(*Lock) Log_KernelPanic("---", "Double short lock");
- *Lock = (void*)1;
- }
- else
+ if( Threads_int_ThreadingEnabled() )
{
if( !*Lock ) {
*Lock = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(*Lock, NULL);
}
{
if( !*Lock ) {
*Lock = malloc(sizeof(pthread_mutex_t));
pthread_mutex_init(*Lock, NULL);
}
+// printf("%p: SHORTLOCK wait\n", lpThreads_This);
pthread_mutex_lock(*Lock);
pthread_mutex_lock(*Lock);
+// printf("%p: SHORTLOCK held %p\n", lpThreads_This, __builtin_return_address(0));
+ }
+ else
+ {
+ if(*Lock) Log_KernelPanic("---", "Double short lock");
+ *Lock = (void*)1;
}
}
void SHORTREL(tShortSpinlock *Lock)
{
}
}
void SHORTREL(tShortSpinlock *Lock)
{
- if(
!pthread_mutex_init
)
+ if(
Threads_int_ThreadingEnabled()
)
{
{
-
if(!*Lock) Log_Notice("---", "Short release when not held"
);
-
*Lock = NULL
;
+
pthread_mutex_unlock(*Lock
);
+
// printf("%p: SHORTLOCK rel\n", lpThreads_This)
;
}
else
{
}
else
{
- pthread_mutex_unlock(*Lock);
+ if(!*Lock) Log_Notice("---", "Short release when not held");
+ *Lock = NULL;
}
}
int CPU_HAS_LOCK(tShortSpinlock *Lock)
{
}
}
int CPU_HAS_LOCK(tShortSpinlock *Lock)
{
- return 0;
+ if( Threads_int_ThreadingEnabled() )
+ {
+ Log_KernelPanic("---", "TODO: CPU_HAS_LOCK with threading enabled");
+ return 0;
+ }
+ else
+ {
+ return 0;
+ }
}
}
-
UCC
git Repository :: git.ucc.asn.au