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.
10 #ifndef THREAD_INTERN_H
11 #define THREAD_INTERN_H 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>
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 */
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 */
57 struct Node node
; /* node for cond->waiters */
58 struct Task
*task
; /* task to signal when the condition
62 /* the library base. this is a per-opener base */
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
) {
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
)