39,27 → 39,6 |
static void psthread_exit(void) __attribute__ ((noinline)); |
static void psthread_main(void); |
|
/** Setup PSthread information into TCB structure */ |
psthread_data_t * psthread_setup(tcb_t *tcb) |
{ |
psthread_data_t *pt; |
|
pt = malloc(sizeof(*pt)); |
if (!pt) { |
return NULL; |
} |
|
tcb->pst_data = pt; |
pt->tcb = tcb; |
|
return pt; |
} |
|
void psthread_teardown(psthread_data_t *pt) |
{ |
free(pt); |
} |
|
/** Function to preempt to other pseudo thread without adding |
* currently running pseudo thread to ready_list. |
*/ |
80,8 → 59,7 |
/** Function that is called on entry to new uspace thread */ |
void psthread_main(void) |
{ |
psthread_data_t *pt = __tcb_get()->pst_data; |
|
psthread_data_t *pt = __tls_get(); |
pt->retval = pt->func(pt->arg); |
|
pt->finished = 1; |
102,7 → 80,7 |
if (list_empty(&ready_list)) |
return 0; |
|
pt = __tcb_get()->pst_data; |
pt = __tls_get(); |
if (!context_save(&pt->ctx)) |
return 1; |
|
125,10 → 103,11 |
volatile int retval; |
|
/* Handle psthrid = Kernel address -> it is wait for call */ |
|
pt = (psthread_data_t *) psthrid; |
|
if (!pt->finished) { |
mypt = __tcb_get()->pst_data; |
mypt = __tls_get(); |
if (context_save(&((psthread_data_t *) mypt)->ctx)) { |
pt->waiter = (psthread_data_t *) mypt; |
psthread_exit(); |
137,8 → 116,7 |
retval = pt->retval; |
|
free(pt->stack); |
__free_tls(pt->tcb); |
psthread_teardown((void *)pt); |
__free_tls((psthread_data_t *) pt); |
|
return retval; |
} |
154,22 → 132,11 |
pstid_t psthread_create(int (*func)(void *), void *arg) |
{ |
psthread_data_t *pt; |
tcb_t *tcb; |
|
tcb = __make_tls(); |
if (!tcb) |
return 0; |
|
pt = psthread_setup(tcb); |
if (!pt) { |
__free_tls(tcb); |
return 0; |
} |
pt = __make_tls(); |
pt->stack = (char *) malloc(getpagesize()); |
|
if (!pt->stack) { |
__free_tls(tcb); |
psthread_teardown(pt); |
return 0; |
} |
|
179,8 → 146,7 |
pt->waiter = NULL; |
|
context_save(&pt->ctx); |
context_set(&pt->ctx, FADDR(psthread_main), pt->stack, getpagesize(), |
tcb); |
context_set(&pt->ctx, FADDR(psthread_main), pt->stack, getpagesize(), pt); |
|
list_append(&pt->link, &ready_list); |
|