Changeset 7114d83 in mainline


Ignore:
Timestamp:
2009-07-06T16:02:27Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5d96851
Parents:
d68e4d5
Message:

Allow task to return value (will be improved).

Location:
uspace
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/exec.c

    rd68e4d5 r7114d83  
    114114        task_id_t tid;
    115115        char *tmp;
     116        int retval;
    116117
    117118        tmp = str_dup(find_command(cmd));
     
    126127        }
    127128       
    128         task_wait(tid);
     129        task_wait(tid, &retval);
     130        if (retval != 0)
     131                printf("Command failed (return value %d).\n", retval);
     132
    129133        return 0;
    130134}
  • uspace/app/getvc/getvc.c

    rd68e4d5 r7114d83  
    7474int main(int argc, char *argv[])
    7575{
     76        int retval;
     77
    7678        if (argc < 3) {
    7779                usage();
     
    98100        version_print(argv[1]);
    99101        task_id_t id = spawn(argv[2]);
    100         task_wait(id);
     102        task_wait(id, &retval);
    101103       
    102104        return 0;
  • uspace/lib/libc/generic/libc.c

    rd68e4d5 r7114d83  
    6262void __main(void *pcb_ptr)
    6363{
     64        int retval;
     65
    6466        __heap_init();
    6567        __async_init();
     
    8385        }
    8486       
    85         main(argc, argv);
     87        retval = main(argc, argv);
     88
    8689        __stdio_done();
     90        (void) task_retval(retval);
    8791}
    8892
  • uspace/lib/libc/generic/task.c

    rd68e4d5 r7114d83  
    149149}
    150150
    151 int task_wait(task_id_t id)
     151int task_wait(task_id_t id, int *retval)
    152152{
    153         return (int) async_req_2_0(PHONE_NS, NS_TASK_WAIT, LOWER32(id), UPPER32(id));
     153        ipcarg_t rv;
     154        int rc;
     155
     156        rc = (int) async_req_2_1(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
     157            UPPER32(id), &rv);
     158        *retval = rv;
     159
     160        return rc;
     161}
     162
     163int task_retval(int val)
     164{
     165        task_id_t id;
     166
     167        id = task_get_id();
     168        return (int) async_req_3_0(PHONE_NS, NS_RETVAL, LOWER32(id),
     169            UPPER32(id), val);
    154170}
    155171
  • uspace/lib/libc/include/ipc/ns.h

    rd68e4d5 r7114d83  
    4040typedef enum {
    4141        NS_PING = IPC_FIRST_USER_METHOD,
    42         NS_TASK_WAIT
     42        NS_TASK_WAIT,
     43        NS_RETVAL
    4344} ns_request_t;
    4445
  • uspace/lib/libc/include/task.h

    rd68e4d5 r7114d83  
    4343extern int task_set_name(const char *name);
    4444extern task_id_t task_spawn(const char *path, char *const argv[]);
    45 extern int task_wait(task_id_t id);
     45extern int task_wait(task_id_t id, int *retval);
     46extern int task_retval(int val);
     47
    4648
    4749#endif
  • uspace/srv/ns/ns.c

    rd68e4d5 r7114d83  
    171171                        wait_for_task(id, &call, callid);
    172172                        continue;
     173                case NS_RETVAL:
     174                        retval = ns_task_retval(&call);
     175                        break;
    173176                default:
    174177                        retval = ENOENT;
  • uspace/srv/ns/task.c

    rd68e4d5 r7114d83  
    6464        link_t link;
    6565        task_id_t id;    /**< Task ID. */
     66        int retval;
    6667        bool destroyed;
    6768} hashed_task_t;
     
    174175               
    175176                if (!(pr->callid & IPC_CALLID_NOTIFICATION))
    176                         ipc_answer_0(pr->callid, EOK);
     177                        ipc_answer_1(pr->callid, EOK, ht->retval);
    177178               
    178179                hash_table_remove(&task_hash_table, keys, 2);
     
    222223                ht->id = id;
    223224                ht->destroyed = (et == TASK_CREATE) ? false : true;
     225                ht->retval = -1;
    224226                hash_table_insert(&task_hash_table, keys, &ht->link);
    225227        } else {
     
    262264out:
    263265        if (!(callid & IPC_CALLID_NOTIFICATION))
    264                 ipc_answer_0(callid, retval);
     266                ipc_answer_1(callid, retval, ht->retval);
     267}
     268
     269int ns_task_retval(ipc_call_t *call)
     270{
     271        task_id_t id;
     272        unsigned long keys[2];
     273
     274        id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call));
     275
     276        keys[0] = LOWER32(id);
     277        keys[1] = UPPER32(id);
     278       
     279        link_t *link = hash_table_find(&task_hash_table, keys);
     280        hashed_task_t *ht = (link != NULL) ?
     281            hash_table_get_instance(link, hashed_task_t, link) : NULL;
     282       
     283        if ((ht == NULL) || ht->destroyed)
     284                return EINVAL;
     285
     286        ht->retval = IPC_GET_ARG3(*call);
     287
     288        return EOK;
    265289}
    266290
  • uspace/srv/ns/task.h

    rd68e4d5 r7114d83  
    4343extern void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid);
    4444
     45extern int ns_task_retval(ipc_call_t *call);
     46
    4547#endif
    4648
Note: See TracChangeset for help on using the changeset viewer.