Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 2 | |
| 3 | #include <common.h> |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 4 | #include <exports.h> |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 5 | |
| 6 | /* |
| 7 | * Author: Arun Dharankar <ADharankar@ATTBI.Com> |
| 8 | * |
| 9 | * A very simple thread/schedular model: |
| 10 | * - only one master thread, and no parent child relation maintained |
| 11 | * - parent thread cannot be stopped or deleted |
| 12 | * - no permissions or credentials |
| 13 | * - no elaborate safety checks |
| 14 | * - cooperative multi threading |
| 15 | * - Simple round-robin scheduleing with no priorities |
| 16 | * - no metering/statistics collection |
| 17 | * |
| 18 | * Basic idea of implementing this is to allow more than one tests to |
| 19 | * execute "simultaneously". |
| 20 | * |
| 21 | * This may be modified such thread_yield may be called in syscalls, and |
| 22 | * timer interrupts. |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #define MAX_THREADS 8 |
| 27 | |
| 28 | #define CTX_SIZE 512 |
| 29 | #define STK_SIZE 8*1024 |
| 30 | |
| 31 | #define STATE_EMPTY 0 |
| 32 | #define STATE_RUNNABLE 1 |
| 33 | #define STATE_STOPPED 2 |
| 34 | #define STATE_TERMINATED 2 |
| 35 | |
| 36 | #define MASTER_THREAD 0 |
| 37 | |
| 38 | #define RC_FAILURE (-1) |
| 39 | #define RC_SUCCESS (0) |
| 40 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 41 | typedef vu_char *jmp_ctx; |
| 42 | unsigned long setctxsp (vu_char *sp); |
| 43 | int ppc_setjmp(jmp_ctx env); |
| 44 | void ppc_longjmp(jmp_ctx env, int val); |
| 45 | #define setjmp ppc_setjmp |
| 46 | #define longjmp ppc_longjmp |
| 47 | |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 48 | struct lthread { |
| 49 | int state; |
| 50 | int retval; |
| 51 | char stack[STK_SIZE]; |
| 52 | uchar context[CTX_SIZE]; |
| 53 | int (*func) (void *); |
| 54 | void *arg; |
| 55 | }; |
| 56 | static volatile struct lthread lthreads[MAX_THREADS]; |
| 57 | static volatile int current_tid = MASTER_THREAD; |
| 58 | |
| 59 | |
| 60 | static uchar dbg = 0; |
| 61 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 62 | #define PDEBUG(fmt, args...) { \ |
| 63 | if(dbg != 0) { \ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 64 | printf("[%s %d %s]: ",__FILE__,__LINE__,__FUNCTION__);\ |
| 65 | printf(fmt, ##args); \ |
| 66 | printf("\n"); \ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 67 | } \ |
| 68 | } |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 69 | |
| 70 | static int testthread (void *); |
| 71 | static void sched_init (void); |
| 72 | static int thread_create (int (*func) (void *), void *arg); |
| 73 | static int thread_start (int id); |
| 74 | static void thread_yield (void); |
| 75 | static int thread_delete (int id); |
| 76 | static int thread_join (int *ret); |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 77 | |
| 78 | #if 0 /* not used yet */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 79 | static int thread_stop (int id); |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 80 | #endif /* not used yet */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 81 | |
| 82 | /* An example of schedular test */ |
| 83 | |
| 84 | #define NUMTHREADS 7 |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 85 | int sched (int ac, char *av[]) |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 86 | { |
| 87 | int i, j; |
| 88 | int tid[NUMTHREADS]; |
| 89 | int names[NUMTHREADS]; |
| 90 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 91 | app_startup(av); |
| 92 | |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 93 | sched_init (); |
| 94 | |
| 95 | for (i = 0; i < NUMTHREADS; i++) { |
| 96 | names[i] = i; |
| 97 | j = thread_create (testthread, (void *) &names[i]); |
| 98 | if (j == RC_FAILURE) |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 99 | printf ("schedtest: Failed to create thread %d\n", i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 100 | if (j > 0) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 101 | printf ("schedtest: Created thread with id %d, name %d\n", |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 102 | j, i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 103 | tid[i] = j; |
| 104 | } |
| 105 | } |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 106 | printf ("schedtest: Threads created\n"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 107 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 108 | printf ("sched_test: function=0x%08x\n", (unsigned)testthread); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 109 | for (i = 0; i < NUMTHREADS; i++) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 110 | printf ("schedtest: Setting thread %d runnable\n", tid[i]); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 111 | thread_start (tid[i]); |
| 112 | thread_yield (); |
| 113 | } |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 114 | printf ("schedtest: Started %d threads\n", NUMTHREADS); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 115 | |
| 116 | while (1) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 117 | printf ("schedtest: Waiting for threads to complete\n"); |
| 118 | if (tstc () && getc () == 0x3) { |
| 119 | printf ("schedtest: Aborting threads...\n"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 120 | for (i = 0; i < NUMTHREADS; i++) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 121 | printf ("schedtest: Deleting thread %d\n", tid[i]); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 122 | thread_delete (tid[i]); |
| 123 | } |
| 124 | return RC_SUCCESS; |
| 125 | } |
| 126 | j = -1; |
| 127 | i = thread_join (&j); |
| 128 | if (i == RC_FAILURE) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 129 | printf ("schedtest: No threads pending, " |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 130 | "exiting schedular test\n"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 131 | return RC_SUCCESS; |
| 132 | } |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 133 | printf ("schedtest: thread is %d returned %d\n", i, j); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 134 | thread_yield (); |
| 135 | } |
| 136 | |
| 137 | return RC_SUCCESS; |
| 138 | } |
| 139 | |
| 140 | static int testthread (void *name) |
| 141 | { |
| 142 | int i; |
| 143 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 144 | printf ("testthread: Begin executing thread, myname %d, &i=0x%08x\n", |
| 145 | *(int *) name, (unsigned)&i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 146 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 147 | printf ("Thread %02d, i=%d\n", *(int *) name, i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 148 | |
| 149 | for (i = 0; i < 0xffff * (*(int *) name + 1); i++) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 150 | if (tstc () && getc () == 0x3) { |
| 151 | printf ("testthread: myname %d terminating.\n", |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 152 | *(int *) name); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 153 | return *(int *) name + 1; |
| 154 | } |
| 155 | |
| 156 | if (i % 100 == 0) |
| 157 | thread_yield (); |
| 158 | } |
| 159 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 160 | printf ("testthread: returning %d, i=0x%x\n", |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 161 | *(int *) name + 1, i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 162 | |
| 163 | return *(int *) name + 1; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | static void sched_init (void) |
| 168 | { |
| 169 | int i; |
| 170 | |
| 171 | for (i = MASTER_THREAD + 1; i < MAX_THREADS; i++) |
| 172 | lthreads[i].state = STATE_EMPTY; |
| 173 | |
| 174 | current_tid = MASTER_THREAD; |
| 175 | lthreads[current_tid].state = STATE_RUNNABLE; |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 176 | PDEBUG ("sched_init: master context = 0x%08x", |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 177 | (unsigned)lthreads[current_tid].context); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 178 | return; |
| 179 | } |
| 180 | |
| 181 | static void thread_yield (void) |
| 182 | { |
| 183 | static int i; |
| 184 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 185 | PDEBUG ("thread_yield: current tid=%d", current_tid); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 186 | |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 187 | #define SWITCH(new) \ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 188 | if(lthreads[new].state == STATE_RUNNABLE) { \ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 189 | PDEBUG("thread_yield: %d match, ctx=0x%08x", \ |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 190 | new, \ |
| 191 | (unsigned)lthreads[current_tid].context); \ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 192 | if(setjmp(lthreads[current_tid].context) == 0) { \ |
| 193 | current_tid = new; \ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 194 | PDEBUG("thread_yield: tid %d returns 0", \ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 195 | new); \ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 196 | longjmp(lthreads[new].context, 1); \ |
| 197 | } else { \ |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 198 | PDEBUG("thread_yield: tid %d returns 1", \ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 199 | new); \ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 200 | return; \ |
| 201 | } \ |
| 202 | } |
| 203 | |
| 204 | for (i = current_tid + 1; i < MAX_THREADS; i++) { |
| 205 | SWITCH (i); |
| 206 | } |
| 207 | |
| 208 | if (current_tid != 0) { |
| 209 | for (i = 0; i <= current_tid; i++) { |
| 210 | SWITCH (i); |
| 211 | } |
| 212 | } |
| 213 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 214 | PDEBUG ("thread_yield: returning from thread_yield"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | |
| 218 | static int thread_create (int (*func) (void *), void *arg) |
| 219 | { |
| 220 | int i; |
| 221 | |
| 222 | for (i = MASTER_THREAD + 1; i < MAX_THREADS; i++) { |
| 223 | if (lthreads[i].state == STATE_EMPTY) { |
| 224 | lthreads[i].state = STATE_STOPPED; |
| 225 | lthreads[i].func = func; |
| 226 | lthreads[i].arg = arg; |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 227 | PDEBUG ("thread_create: returns new tid %d", i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 228 | return i; |
| 229 | } |
| 230 | } |
| 231 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 232 | PDEBUG ("thread_create: returns failure"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 233 | return RC_FAILURE; |
| 234 | } |
| 235 | |
| 236 | static int thread_delete (int id) |
| 237 | { |
| 238 | if (id <= MASTER_THREAD || id > MAX_THREADS) |
| 239 | return RC_FAILURE; |
| 240 | |
| 241 | if (current_tid == id) |
| 242 | return RC_FAILURE; |
| 243 | |
| 244 | lthreads[id].state = STATE_EMPTY; |
| 245 | return RC_SUCCESS; |
| 246 | } |
| 247 | |
| 248 | static void thread_launcher (void) |
| 249 | { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 250 | PDEBUG ("thread_launcher: invoking func=0x%08x", |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 251 | (unsigned)lthreads[current_tid].func); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 252 | |
| 253 | lthreads[current_tid].retval = |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 254 | lthreads[current_tid].func (lthreads[current_tid].arg); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 255 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 256 | PDEBUG ("thread_launcher: tid %d terminated", current_tid); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 257 | |
| 258 | lthreads[current_tid].state = STATE_TERMINATED; |
| 259 | thread_yield (); |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 260 | printf ("thread_launcher: should NEVER get here!\n"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 261 | |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | static int thread_start (int id) |
| 266 | { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 267 | PDEBUG ("thread_start: id=%d", id); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 268 | if (id <= MASTER_THREAD || id > MAX_THREADS) { |
| 269 | return RC_FAILURE; |
| 270 | } |
| 271 | |
| 272 | if (lthreads[id].state != STATE_STOPPED) |
| 273 | return RC_FAILURE; |
| 274 | |
| 275 | if (setjmp (lthreads[current_tid].context) == 0) { |
| 276 | lthreads[id].state = STATE_RUNNABLE; |
| 277 | current_tid = id; |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 278 | PDEBUG ("thread_start: to be stack=0%08x", |
| 279 | (unsigned)lthreads[id].stack); |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 280 | setctxsp ((vu_char *)<hreads[id].stack[STK_SIZE]); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 281 | thread_launcher (); |
| 282 | } |
| 283 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 284 | PDEBUG ("thread_start: Thread id=%d started, parent returns", id); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 285 | |
| 286 | return RC_SUCCESS; |
| 287 | } |
| 288 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 289 | #if 0 /* not used so far */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 290 | static int thread_stop (int id) |
| 291 | { |
| 292 | if (id <= MASTER_THREAD || id >= MAX_THREADS) |
| 293 | return RC_FAILURE; |
| 294 | |
| 295 | if (current_tid == id) |
| 296 | return RC_FAILURE; |
| 297 | |
| 298 | lthreads[id].state = STATE_STOPPED; |
| 299 | return RC_SUCCESS; |
| 300 | } |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 301 | #endif /* not used so far */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 302 | |
| 303 | static int thread_join (int *ret) |
| 304 | { |
| 305 | int i, j = 0; |
| 306 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 307 | PDEBUG ("thread_join: *ret = %d", *ret); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 308 | |
| 309 | if (!(*ret == -1 || *ret > MASTER_THREAD || *ret < MAX_THREADS)) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 310 | PDEBUG ("thread_join: invalid tid %d", *ret); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 311 | return RC_FAILURE; |
| 312 | } |
| 313 | |
| 314 | if (*ret == -1) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 315 | PDEBUG ("Checking for tid = -1"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 316 | while (1) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 317 | /* PDEBUG("thread_join: start while-loopn"); */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 318 | j = 0; |
| 319 | for (i = MASTER_THREAD + 1; i < MAX_THREADS; i++) { |
| 320 | if (lthreads[i].state == STATE_TERMINATED) { |
| 321 | *ret = lthreads[i].retval; |
| 322 | lthreads[i].state = STATE_EMPTY; |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 323 | /* PDEBUG("thread_join: returning retval %d of tid %d", |
| 324 | ret, i); */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 325 | return RC_SUCCESS; |
| 326 | } |
| 327 | |
| 328 | if (lthreads[i].state != STATE_EMPTY) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 329 | PDEBUG ("thread_join: %d used slots tid %d state=%d", |
| 330 | j, i, lthreads[i].state); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 331 | j++; |
| 332 | } |
| 333 | } |
| 334 | if (j == 0) { |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 335 | PDEBUG ("thread_join: all slots empty!"); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 336 | return RC_FAILURE; |
| 337 | } |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 338 | /* PDEBUG("thread_join: yielding"); */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 339 | thread_yield (); |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 340 | /* PDEBUG("thread_join: back from yield"); */ |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | if (lthreads[*ret].state == STATE_TERMINATED) { |
| 345 | i = *ret; |
| 346 | *ret = lthreads[*ret].retval; |
| 347 | lthreads[*ret].state = STATE_EMPTY; |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 348 | PDEBUG ("thread_join: returing %d for tid %d", *ret, i); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 349 | return RC_SUCCESS; |
| 350 | } |
| 351 | |
wdenk | 3e38691 | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 352 | PDEBUG ("thread_join: thread %d is not terminated!", *ret); |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 353 | return RC_FAILURE; |
| 354 | } |