added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / libs / thread / thread_intern.h
blob98081a45ef93f0bfe70d9ed5a08916a1eb9f3c2e
1 /*
2 * thread.library - threading and synchronisation primitives
4 * Copyright © 2007 Robert Norris
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
8 */
10 #ifndef THREAD_INTERN_H
11 #define THREAD_INTERN_H 1
13 #define DEBUG 1
14 #include <aros/debug.h>
16 #include <exec/libraries.h>
17 #include <exec/semaphores.h>
18 #include <exec/lists.h>
19 #include <exec/nodes.h>
21 #include <libraries/thread.h>
22 #include <stdint.h>
24 /* a single thread */
25 struct _Thread {
26 struct Node node; /* node for ThreadBase->threads */
28 struct SignalSemaphore lock; /* lock for the this thread data */
30 uint32_t id; /* numerical thread id. read only,
31 * no need to acquire the lock */
33 struct Task *task; /* the exec task for this thread, or
34 NULL if the thread has completed */
36 void *result; /* storage for the thread exit value
37 * for thread completion waiters */
39 struct _Condition *exit; /* condition for threads waiting for
40 * this thread to finish */
41 void *exit_mutex; /* associated mutex */
42 int exit_count; /* number of threads waitering */
44 BOOL detached; /* flag, thread is detached */
47 /* a condition variable */
48 struct _Condition {
49 struct SignalSemaphore lock; /* lock for this condition data */
51 struct List waiters; /* list of _CondWaiters */
52 int count; /* number of waiters in the list */
55 /* a waiter for a condition */
56 struct _CondWaiter {
57 struct Node node; /* node for cond->waiters */
58 struct Task *task; /* task to signal when the condition
59 * is met */
62 /* the library base. this is a per-opener base */
63 struct ThreadBase {
64 struct Library library;
66 struct ThreadBase *rootbase; /* pointer to the global base */
68 struct SignalSemaphore lock; /* lock for this base */
70 uint32_t nextid; /* numeric identifier to be issued to
71 * the next thread created */
73 struct List threads; /* list of threads */
76 /* helper functions for finding thread data */
77 static inline struct _Thread *_getthreadbyid(uint32_t id, struct ThreadBase *ThreadBase) {
78 struct _Thread *thread, *next;
79 ForeachNodeSafe(&ThreadBase->threads, thread, next) {
80 if (thread->id == id)
81 return thread;
83 return NULL;
86 static inline struct _Thread *_getthreadbytask(struct Task *task, struct ThreadBase *ThreadBase) {
87 struct _Thread *thread, *next;
88 ForeachNodeSafe(&ThreadBase->threads, thread, next) {
89 if (thread->task == task)
90 return thread;
92 return NULL;
95 #endif