Changeset 520492a in mainline


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().

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • init/init.c

    r4f2c821 r520492a  
    256256static int ptest(void *arg)
    257257{
    258         printf("Pseudo thread-1\n");
    259         ps_preempt();
    260         printf("Pseudo thread-2\n");
    261         ps_preempt();
    262         printf("Pseudo thread-3\n");
    263         ps_preempt();
    264         printf("Pseudo thread-4\n");
    265         ps_preempt();
    266         printf("Pseudo finish\n");
     258        printf("Pseudo thread stage1.\n");
     259        psthread_schedule_next();
     260        printf("Pseudo thread stage2.\n");
     261        psthread_schedule_next();
     262        printf("Pseudo thread stage3.\n");
     263        psthread_schedule_next();
     264        printf("Pseudo thread stage4.\n");
     265        psthread_schedule_next();
     266        printf("Pseudo thread exiting.\n");
    267267        return 0;       
    268268}
     
    309309
    310310        ptid = psthread_create(ptest, NULL);
    311         printf("main thread-1\n");
    312         ps_preempt();
    313         printf("main thread-2\n");
    314         ps_preempt();
    315         printf("main thread-3\n");
    316 
    317         ps_join(ptid);
    318         printf("Main exiting\n");
     311        printf("Main thread stage1.\n");
     312        psthread_schedule_next();;
     313        printf("Main thread stage2.\n");
     314        psthread_schedule_next();;
     315        printf("Main thread stage3.\n");
     316
     317        psthread_join(ptid);
    319318
    320319        printf("Main thread exiting.\n");
  • 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 
  • libc/include/psthread.h

    r4f2c821 r520492a  
    4545        struct psthread_data *self; /* ia32, amd64 needs to get self address */
    4646
    47         link_t list;
     47        link_t link;
    4848        context_t ctx;
    4949        void *stack;
     
    6262
    6363pstid_t psthread_create(int (*func)(void *), void *arg);
    64 int ps_preempt(void);
    65 int ps_join(pstid_t psthrid);
     64int psthread_schedule_next(void);
     65int psthread_join(pstid_t psthrid);
    6666
    6767#endif
Note: See TracChangeset for help on using the changeset viewer.