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));
void Threads_int_Init(void)
{
lpThreads_This = Threads_int_CreateTCB(NULL);
+ Threads_SetName("ThreadZero");
}
tThread *Proc_GetCurThread(void)
#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>
void Threads_int_SemSignal(tThreadIntSem *Sem)
{
- if( sem_wait )
+ if( sem_post )
{
- sem_wait( (void*)Sem );
+ sem_post( (void*)Sem );
}
else
{
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
{
*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));
}
}
else
{
pthread_mutex_unlock(*Lock);
+// printf("%p: SHORTLOCK rel\n", lpThreads_This);
}
}