Rev 1113 | Rev 1128 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1113 | Rev 1125 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | #include <psthread.h> |
30 | #include <psthread.h> |
31 | #include <malloc.h> |
31 | #include <malloc.h> |
32 | #include <unistd.h> |
32 | #include <unistd.h> |
33 | #include <thread.h> |
33 | #include <thread.h> |
34 | #include <stdio.h> |
34 | #include <stdio.h> |
- | 35 | #include <kernel/arch/faddr.h> |
|
35 | 36 | ||
36 | static LIST_INITIALIZE(ready_list); |
37 | static LIST_INITIALIZE(ready_list); |
37 | 38 | ||
- | 39 | static void ps_exit(void) __attribute__ ((noinline)); |
|
- | 40 | ||
38 | /** Function to preempt to other thread without adding |
41 | /** Function to preempt to other thread without adding |
39 | * currently running thread to runqueue |
42 | * currently running thread to runqueue |
40 | */ |
43 | */ |
41 | static void ps_exit(void) |
44 | void ps_exit(void) |
42 | { |
45 | { |
43 | psthread_data_t *pt; |
46 | psthread_data_t *pt; |
44 | 47 | ||
45 | if (list_empty(&ready_list)) { |
48 | if (list_empty(&ready_list)) { |
46 | /* Wait on IPC queue etc... */ |
49 | /* Wait on IPC queue etc... */ |
Line 85... | Line 88... | ||
85 | } |
88 | } |
86 | 89 | ||
87 | /** Wait for uspace thread to finish */ |
90 | /** Wait for uspace thread to finish */ |
88 | int ps_join(pstid_t psthrid) |
91 | int ps_join(pstid_t psthrid) |
89 | { |
92 | { |
90 | psthread_data_t *pt, *mypt; |
93 | volatile psthread_data_t *pt, *mypt; |
91 | int retval; |
94 | volatile int retval; |
92 | 95 | ||
93 | /* Handle psthrid = Kernel address -> it is wait for call */ |
96 | /* Handle psthrid = Kernel address -> it is wait for call */ |
94 | 97 | ||
95 | pt = (psthread_data_t *) psthrid; |
98 | pt = (psthread_data_t *) psthrid; |
96 | 99 | ||
97 | if (!pt->finished) { |
100 | if (!pt->finished) { |
98 | mypt = __tls_get(); |
101 | mypt = __tls_get(); |
99 | if (context_save(&mypt->ctx)) { |
102 | if (context_save(&((psthread_data_t *) mypt)->ctx)) { |
100 | pt->waiter = mypt; |
103 | pt->waiter = (psthread_data_t *) mypt; |
101 | ps_exit(); |
104 | ps_exit(); |
102 | } |
105 | } |
103 | } |
106 | } |
104 | retval = pt->retval; |
107 | retval = pt->retval; |
105 | 108 | ||
106 | free(pt->stack); |
109 | free(pt->stack); |
107 | __free_tls(pt); |
110 | __free_tls((psthread_data_t *) pt); |
108 | 111 | ||
109 | return retval; |
112 | return retval; |
110 | } |
113 | } |
111 | 114 | ||
112 | /** |
115 | /** |
Line 128... | Line 131... | ||
128 | pt->func = func; |
131 | pt->func = func; |
129 | pt->finished = 0; |
132 | pt->finished = 0; |
130 | pt->waiter = NULL; |
133 | pt->waiter = NULL; |
131 | 134 | ||
132 | context_save(&pt->ctx); |
135 | context_save(&pt->ctx); |
133 | context_set(&pt->ctx, psthread_main, pt->stack, getpagesize(), pt); |
136 | context_set(&pt->ctx, FADDR(psthread_main), pt->stack, getpagesize(), pt); |
134 | 137 | ||
135 | list_append(&pt->list, &ready_list); |
138 | list_append(&pt->list, &ready_list); |
136 | 139 | ||
137 | return (pstid_t )pt; |
140 | return (pstid_t )pt; |
138 | } |
141 | } |