Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / thread / thread_intern.h
blobcdb8ebe2d3df26cbf82db14597e431f8c671ce82
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 #include <setjmp.h>
26 /* a single thread */
27 struct _Thread {
28 struct Node node; /* node for ThreadBase->threads */
30 struct SignalSemaphore lock; /* lock for the this thread data */
32 uint32_t id; /* numerical thread id. read only,
33 * no need to acquire the lock */
35 struct Task *task; /* the exec task for this thread, or
36 NULL if the thread has completed */
38 void *result; /* storage for the thread exit value
39 * for thread completion waiters */
41 jmp_buf jmp; /* jump point for thread exit */
43 struct _Condition *exit; /* condition for threads waiting for
44 * this thread to finish */
45 void *exit_mutex; /* associated mutex */
46 int exit_count; /* number of threads waitering */
48 BOOL detached; /* flag, thread is detached */
51 /* a condition variable */
52 struct _Condition {
53 struct SignalSemaphore lock; /* lock for this condition data */
55 struct List waiters; /* list of _CondWaiters */
56 int count; /* number of waiters in the list */
59 /* a waiter for a condition */
60 struct _CondWaiter {
61 struct Node node; /* node for cond->waiters */
62 struct Task *task; /* task to signal when the condition
63 * is met */
66 /* the library base. this is a per-opener base */
67 struct ThreadBase {
68 struct Library library;
70 struct ThreadBase *rootbase; /* pointer to the global base */
72 struct SignalSemaphore lock; /* lock for this base */
74 uint32_t nextid; /* numeric identifier to be issued to
75 * the next thread created */
77 struct List threads; /* list of threads */
80 /* helper functions for finding thread data */
81 static inline struct _Thread *_getthreadbyid(uint32_t id, struct ThreadBase *ThreadBase) {
82 struct _Thread *thread, *next;
83 ForeachNodeSafe(&ThreadBase->threads, thread, next) {
84 if (thread->id == id)
85 return thread;
87 return NULL;
90 static inline struct _Thread *_getthreadbytask(struct Task *task, struct ThreadBase *ThreadBase) {
91 struct _Thread *thread, *next;
92 ForeachNodeSafe(&ThreadBase->threads, thread, next) {
93 if (thread->task == task)
94 return thread;
96 return NULL;
99 #endif