8 #define TWHMASK (TWHSIZE - 1)
10 typedef struct ThreadWait {
11 struct tdlist tw_List;
14 typedef struct ThreadCall {
16 void (*func)(void *args, void *res);
21 static ThreadWait TWArray[TWHSIZE];
25 hashptr(uintptr_t wchan)
32 return (hv & TWHMASK);
36 * Threaded call support, wraps threaded procedure call
38 void RuneRunTime_ThreadedCall(void *args, void *res,
39 void (*func)(void *, void *));
40 void RuneRunTime_ThreadedDetach(void);
44 startThreadedCall(void *data)
46 ThreadCall *tc = data;
48 tc->func(tc->args, tc->res);
49 /* tc invalid after this point */
52 * Reload tc, target may have detached
54 tc = CurThread->th_StartData;
56 threadWakeup1(&tc->list);
57 /* tc invalid after this point */
61 * Called from generated code at run-time, cothread placed on run-queue
62 * but guaranteed not to run immediately. We then stop our current thread
63 * and wait for the cothread to detach.
66 RuneRunTime_ThreadedCall(void *args, void *res, void (*func)(void *, void *))
70 printf("ThreadedCall %p(%p,%p)\n", func, args, res);
75 threadCreate(startThreadedCall, &tc);
76 threadStop(&tc.list, 0);
77 printf("ThreadedResult\n");
81 RuneRunTime_ThreadedDetach(void)
85 printf("ThreadedDetach\n");
86 tc = CurThread->th_StartData;
88 CurThread->th_StartData = NULL;
89 threadWakeup1(&tc->list);
96 void RuneSysCall_waitThreads(void *args, void *rval);
99 RuneSysCall_waitThreads(void *args, void *rval)
101 threadWaitTerminate();
109 void RuneSysCall_wakeup(struct wakeup_args *args, void *rval);
112 RuneSysCall_wakeup(struct wakeup_args *args, void *rval)
117 wchan = (uintptr_t)args->s.s_Addr;
118 tw = &TWArray[hashptr(wchan)];
120 threadWakeupWChan(&tw->tw_List, wchan);
127 void RuneSysCall_sleep(struct sleep_args *args, void *rval);
130 RuneSysCall_sleep(struct sleep_args *args, void *rval)
134 RUNE_INIT(&tw.tw_List);
137 threadSleep(&tw.tw_List, args->ms);
146 void RuneSysCall_tsleep(struct tsleep_args *args, void *rval);
149 RuneSysCall_tsleep(struct tsleep_args *args, void *rval)
154 wchan = (uintptr_t)args->s.s_Addr;
156 tw = &TWArray[hashptr(wchan)];
158 threadSleepWChan(&tw->tw_List, wchan, args->ms);