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