Tools/nativelib - Many features implimented
[tpg/acess2.git] / Tools / nativelib / include / threads_int.h
1 /*
2  * Acess2 libnative (Kernel Simulation Library)
3  * - By John Hodge (thePowersGang)
4  *
5  * threads_int.h
6  * - Threads handling definitions
7  */
8 #ifndef _THREADS_INT_H_
9 #define _THREADS_INT_H_
10
11 #define THREAD_EVENT_RWLOCK     (1 << 8)
12
13 typedef struct sThreadIntMutex  tThreadIntMutex;        // actually pthreads
14 typedef struct sThreadIntSem    tThreadIntSem;
15
16 struct sProcess
17 {
18         struct sProcess *Next;
19         struct sThread  *Threads;
20
21          int    PID;
22          int    UID, GID;
23         
24         char    *CWD;
25         char    *Chroot;
26
27          int    MaxFDs;
28         void    *Handles;
29 };
30
31 struct sThread
32 {
33         struct sThread  *Next;
34         struct sThread  *ListNext;
35
36         struct sProcess *Process;
37         struct sThread  *ProcNext;
38
39         void    *ThreadHandle;
40          int    TID;
41
42         tThreadIntMutex *Protector;
43
44         uint32_t        PendingEvents;
45         uint32_t        WaitingEvents;
46         tThreadIntSem   *WaitSemaphore; // pthreads
47
48         char    *Name;
49
50         // Init Only
51         void    (*SpawnFcn)(void*);
52         void    *SpawnData;
53 };
54
55 extern struct sThread __thread  *lpThreads_This;
56
57 extern int      Threads_int_CreateThread(struct sThread *Thread);
58 extern int      Threads_int_ThreadingEnabled(void);
59
60 extern tThreadIntMutex  *Threads_int_MutexCreate(void);
61 extern void     Threads_int_MutexDestroy(tThreadIntMutex *Mutex);
62 extern void     Threads_int_MutexLock(tThreadIntMutex *Mutex);
63 extern void     Threads_int_MutexRelease(tThreadIntMutex *Mutex);
64
65 extern tThreadIntSem    *Threads_int_SemCreate(void);
66 extern void     Threads_int_SemDestroy(tThreadIntSem *Sem);
67 extern void     Threads_int_SemSignal(tThreadIntSem *Sem);
68 extern void     Threads_int_SemWait(tThreadIntSem *Sem);
69 extern void     Threads_int_SemWaitAll(tThreadIntSem *Sem);
70
71 #endif
72

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