Changeset 520492a in mainline for libc/generic/psthread.c


Ignore:
Timestamp:
2006-03-24T13:57:43Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c4c5de5
Parents:
4f2c821
Message:

Improve comments in psthread.c
Rename pt→list to pt→link.
Rename ps_preempt() to psthread_schedule_next().
Rename ps_join() to psthread_join().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libc/generic/psthread.c

    r4f2c821 r520492a  
    3737static LIST_INITIALIZE(ready_list);
    3838
    39 static void ps_exit(void) __attribute__ ((noinline));
     39static void psthread_exit(void) __attribute__ ((noinline));
     40static void psthread_main(void);
    4041
    41 /** Function to preempt to other thread without adding
    42  * currently running thread to runqueue
     42/** Function to preempt to other pseudo thread without adding
     43 * currently running pseudo thread to ready_list.
    4344 */
    44 void ps_exit(void)
     45void psthread_exit(void)
    4546{
    4647        psthread_data_t *pt;
     
    5152                _exit(0);
    5253        }
    53         pt = list_get_instance(ready_list.next, psthread_data_t, list);
    54         list_remove(&pt->list);
     54        pt = list_get_instance(ready_list.next, psthread_data_t, link);
     55        list_remove(&pt->link);
    5556        context_restore(&pt->ctx);
    5657}
    5758
    5859/** Function that is called on entry to new uspace thread */
    59 static int psthread_main(void)
     60void psthread_main(void)
    6061{
    6162        psthread_data_t *pt = __tls_get();
     
    6465        pt->finished = 1;
    6566        if (pt->waiter)
    66                 list_append(&pt->waiter->list, &ready_list);
     67                list_append(&pt->waiter->link, &ready_list);
    6768
    68         ps_exit();
     69        psthread_exit();
    6970}
    7071
    71 /** Do a preemption of userpace threads */
    72 int ps_preempt(void)
     72/** Schedule next userspace pseudo thread.
     73 *
     74 * @return 0 if there is no ready pseudo thread, 1 otherwise.
     75 */
     76int psthread_schedule_next(void)
    7377{
    7478        psthread_data_t *pt;
     
    7882
    7983        pt = __tls_get();
    80         if (! context_save(&pt->ctx))
     84        if (!context_save(&pt->ctx))
    8185                return 1;
    8286       
    83         list_append(&pt->list, &ready_list);
    84         pt = list_get_instance(ready_list.next, psthread_data_t, list);
    85         list_remove(&pt->list);
     87        list_append(&pt->link, &ready_list);
     88        pt = list_get_instance(ready_list.next, psthread_data_t, link);
     89        list_remove(&pt->link);
    8690
    8791        context_restore(&pt->ctx);
    8892}
    8993
    90 /** Wait for uspace thread to finish */
    91 int ps_join(pstid_t psthrid)
     94/** Wait for uspace pseudo thread to finish.
     95 *
     96 * @param psthrid Pseudo thread to wait for.
     97 *
     98 * @return Value returned by the finished thread.
     99 */
     100int psthread_join(pstid_t psthrid)
    92101{
    93102        volatile psthread_data_t *pt, *mypt;
     
    102111                if (context_save(&((psthread_data_t *) mypt)->ctx)) {
    103112                        pt->waiter = (psthread_data_t *) mypt;
    104                         ps_exit();
     113                        psthread_exit();
    105114                }
    106115        }
     
    114123
    115124/**
    116  * Create a userspace thread
     125 * Create a userspace thread and append it to ready list.
    117126 *
     127 * @param func Pseudo thread function.
     128 * @param arg Argument to pass to func.
     129 *
     130 * @return 0 on failure, TLS of the new pseudo thread.
    118131 */
    119132pstid_t psthread_create(int (*func)(void *), void *arg)
     
    136149        context_set(&pt->ctx, FADDR(psthread_main), pt->stack, getpagesize(), pt);
    137150
    138         list_append(&pt->list, &ready_list);
     151        list_append(&pt->link, &ready_list);
    139152
    140153        return (pstid_t )pt;
    141154}
    142 
Note: See TracChangeset for help on using the changeset viewer.