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
Usermode/AxWin3 - Added names to widget types
[tpg/acess2.git]
/
Tools
/
nativelib
/
threads.c
diff --git
a/Tools/nativelib/threads.c
b/Tools/nativelib/threads.c
index
1231c43
..
9a4bfdf
100644
(file)
--- a/
Tools/nativelib/threads.c
+++ b/
Tools/nativelib/threads.c
@@
-16,11
+16,16
@@
tThread *Threads_int_CreateTCB(tThread *Parent);
// === GLOBALS ===
tThread *gThreads_List;
tThread __thread *lpThreads_This;
// === GLOBALS ===
tThread *gThreads_List;
tThread __thread *lpThreads_This;
+ int giThreads_NextTID = 1;
+tShortSpinlock glThreadListLock;
// === CODE ===
void Threads_int_Init(void)
{
// === CODE ===
void Threads_int_Init(void)
{
- lpThreads_This = Threads_int_CreateTCB(NULL);
+ if( !lpThreads_This ) {
+ lpThreads_This = Threads_int_CreateTCB(NULL);
+ Threads_SetName("ThreadZero");
+ }
}
tThread *Proc_GetCurThread(void)
}
tThread *Proc_GetCurThread(void)
@@
-34,16
+39,16
@@
void Threads_PostEvent(tThread *Thread, Uint32 Events)
// nope.avi
return ;
}
// nope.avi
return ;
}
-
Threads_int_MutexLock(Thread->Protector
);
+
SHORTLOCK( &Thread->IsLocked
);
Thread->PendingEvents |= Events;
if( Thread->WaitingEvents & Events )
Threads_int_SemSignal(Thread->WaitSemaphore);
Thread->PendingEvents |= Events;
if( Thread->WaitingEvents & Events )
Threads_int_SemSignal(Thread->WaitSemaphore);
-
Threads_int_MutexRelease(Thread->Protector
);
+
SHORTREL( &Thread->IsLocked
);
}
Uint32 Threads_WaitEvents(Uint32 Events)
{
}
Uint32 Threads_WaitEvents(Uint32 Events)
{
- if( Threads_int_ThreadingEnabled() ) {
+ if(
!
Threads_int_ThreadingEnabled() ) {
Log_Notice("Threads", "_WaitEvents: Threading disabled");
return 0;
}
Log_Notice("Threads", "_WaitEvents: Threading disabled");
return 0;
}
@@
-56,19
+61,19
@@
Uint32 Threads_WaitEvents(Uint32 Events)
void Threads_ClearEvent(Uint32 Mask)
{
void Threads_ClearEvent(Uint32 Mask)
{
- if( Threads_int_ThreadingEnabled() ) {
+ if(
!
Threads_int_ThreadingEnabled() ) {
Log_Notice("Threads", "_ClearEvent: Threading disabled");
return ;
}
Log_Notice("Threads", "_ClearEvent: Threading disabled");
return ;
}
-
Threads_int_MutexLock(lpThreads_This->Protector
);
+
SHORTLOCK(&lpThreads_This->IsLocked
);
lpThreads_This->PendingEvents &= ~Mask;
lpThreads_This->PendingEvents &= ~Mask;
-
Threads_int_MutexRelease(lpThreads_This->Protector
);
+
SHORTREL(&lpThreads_This->IsLocked
);
}
tUID Threads_GetUID(void) { return 0; }
tGID Threads_GetGID(void) { return 0; }
}
tUID Threads_GetUID(void) { return 0; }
tGID Threads_GetGID(void) { return 0; }
-tTID Threads_GetTID(void) { return 0; }
+tTID Threads_GetTID(void) { return
lpThreads_This ? lpThreads_This->TID :
0; }
int *Threads_GetMaxFD(void) { return &lpThreads_This->Process->MaxFDs; }
char **Threads_GetCWD(void) { return &lpThreads_This->Process->CWD; }
int *Threads_GetMaxFD(void) { return &lpThreads_This->Process->MaxFDs; }
char **Threads_GetCWD(void) { return &lpThreads_This->Process->CWD; }
@@
-86,14
+91,20
@@
void Threads_Sleep(void)
Log_Warning("Threads", "Threads_Sleep shouldn't be used");
}
Log_Warning("Threads", "Threads_Sleep shouldn't be used");
}
+void Threads_int_WaitForStatusEnd(enum eThreadStatus Status)
+{
+ while( lpThreads_This->Status != Status )
+ Threads_int_SemWaitAll(lpThreads_This->WaitSemaphore);
+}
+
int Threads_SetName(const char *Name)
{
if( !lpThreads_This )
return 0;
int Threads_SetName(const char *Name)
{
if( !lpThreads_This )
return 0;
- if( lpThreads_This->Name )
- free(lpThreads_This->Name);
- lpThreads_This->Name = strdup(Name);
+ if( lpThreads_This->
Thread
Name )
+ free(lpThreads_This->
Thread
Name);
+ lpThreads_This->
Thread
Name = strdup(Name);
return 0;
}
return 0;
}
@@
-106,6
+117,18
@@
int *Threads_GetErrno(void)
return &a_errno;
}
return &a_errno;
}
+tThread *Threads_RemActive(void)
+{
+ return lpThreads_This;
+}
+
+void Threads_AddActive(tThread *Thread)
+{
+ Thread->Status = THREAD_STAT_ACTIVE;
+ // Increment state-change semaphore
+ Threads_int_SemSignal(Thread->WaitSemaphore);
+}
+
struct sProcess *Threads_int_CreateProcess(void)
{
struct sProcess *ret = calloc(sizeof(struct sProcess), 1);
struct sProcess *Threads_int_CreateProcess(void)
{
struct sProcess *ret = calloc(sizeof(struct sProcess), 1);
@@
-118,8
+141,9
@@
struct sProcess *Threads_int_CreateProcess(void)
tThread *Threads_int_CreateTCB(tThread *Parent)
{
tThread *ret = calloc( sizeof(tThread), 1 );
tThread *Threads_int_CreateTCB(tThread *Parent)
{
tThread *ret = calloc( sizeof(tThread), 1 );
+ ret->TID = giThreads_NextTID ++;
ret->WaitSemaphore = Threads_int_SemCreate();
ret->WaitSemaphore = Threads_int_SemCreate();
- ret->Protector = Threads_int_MutexCreate();
+
//
ret->Protector = Threads_int_MutexCreate();
if( !Parent )
{
if( !Parent )
{
UCC
git Repository :: git.ucc.asn.au