Changeset adb49f58 in mainline


Ignore:
Timestamp:
2009-07-06T20:16:15Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
95bc57c
Parents:
0315679
Message:

Allow to determine whether a task returned value before terminatign.

Location:
uspace
Files:
5 edited

Legend:

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

    r0315679 radb49f58  
    113113{
    114114        task_id_t tid;
     115        task_exit_t texit;
    115116        char *tmp;
    116117        int retval;
     
    127128        }
    128129       
    129         task_wait(tid, &retval);
    130         if (retval != 0)
     130        task_wait(tid, &texit, &retval);
     131        if (texit != TASK_EXIT_NORMAL) {
     132                printf("Command failed (unexpectedly terminated).\n");
     133        } else if (retval != 0) {
    131134                printf("Command failed (return value %d).\n", retval);
     135        }
    132136
    133137        return 0;
  • uspace/app/getvc/getvc.c

    r0315679 radb49f58  
    7474int main(int argc, char *argv[])
    7575{
     76        task_exit_t texit;
    7677        int retval;
    7778
     
    100101        version_print(argv[1]);
    101102        task_id_t id = spawn(argv[2]);
    102         task_wait(id, &retval);
     103        task_wait(id, &texit, &retval);
    103104       
    104105        return 0;
  • uspace/lib/libc/generic/task.c

    r0315679 radb49f58  
    149149}
    150150
    151 int task_wait(task_id_t id, int *retval)
     151int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    152152{
    153         ipcarg_t rv;
     153        ipcarg_t te, rv;
    154154        int rc;
    155155
    156         rc = (int) async_req_2_1(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
    157             UPPER32(id), &rv);
     156        rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
     157            UPPER32(id), &te, &rv);
     158        *texit = te;
    158159        *retval = rv;
    159160
  • uspace/lib/libc/include/task.h

    r0315679 radb49f58  
    4040typedef uint64_t task_id_t;
    4141
     42typedef enum {
     43        TASK_EXIT_NORMAL,
     44        TASK_EXIT_UNEXPECTED
     45} task_exit_t;
     46
    4247extern task_id_t task_get_id(void);
    4348extern int task_set_name(const char *name);
    4449extern task_id_t task_spawn(const char *path, char *const argv[]);
    45 extern int task_wait(task_id_t id, int *retval);
     50extern int task_wait(task_id_t id, task_exit_t *texit, int *retval);
    4651extern int task_retval(int val);
    4752
  • uspace/srv/ns/task.c

    r0315679 radb49f58  
    5757typedef struct {
    5858        link_t link;
    59         task_id_t id;    /**< Task ID. */
    60         int retval;
    61         bool destroyed;
     59        task_id_t id;   /**< Task ID. */
     60        bool finished;  /**< Task is done. */
     61        bool have_rval; /**< Task returned a value. */
     62        int retval;     /**< The return value. */
    6263} hashed_task_t;
    6364
     
    212213{
    213214        link_t *cur;
     215        task_exit_t texit;
    214216       
    215217loop:
     
    227229               
    228230                hashed_task_t *ht = hash_table_get_instance(link, hashed_task_t, link);
    229                 if (!ht->destroyed)
     231                if (!ht->finished)
    230232                        continue;
    231233               
    232                 if (!(pr->callid & IPC_CALLID_NOTIFICATION))
    233                         ipc_answer_1(pr->callid, EOK, ht->retval);
    234                
     234                if (!(pr->callid & IPC_CALLID_NOTIFICATION)) {
     235                        texit = ht->have_rval ? TASK_EXIT_NORMAL :
     236                            TASK_EXIT_UNEXPECTED;
     237                        ipc_answer_2(pr->callid, EOK, texit,
     238                            ht->retval);
     239                }
     240
    235241                hash_table_remove(&task_hash_table, keys, 2);
    236242                list_remove(cur);
     
    243249{
    244250        ipcarg_t retval;
     251        task_exit_t texit;
     252
    245253        unsigned long keys[2] = {
    246254                LOWER32(id),
     
    258266        }
    259267
    260         if (!ht->destroyed) {
     268        if (!ht->finished) {
    261269                /* Add to pending list */
    262270                pending_wait_t *pr =
     
    277285       
    278286out:
    279         if (!(callid & IPC_CALLID_NOTIFICATION))
    280                 ipc_answer_1(callid, retval, ht->retval);
     287        if (!(callid & IPC_CALLID_NOTIFICATION)) {
     288                texit = ht->have_rval ? TASK_EXIT_NORMAL : TASK_EXIT_UNEXPECTED;
     289                ipc_answer_2(callid, retval, texit, ht->retval);
     290        }
    281291}
    282292
     
    319329        link_initialize(&ht->link);
    320330        ht->id = id;
    321         ht->destroyed = false;
     331        ht->finished = false;
     332        ht->have_rval = false;
    322333        ht->retval = -1;
    323334        hash_table_insert(&task_hash_table, keys, &ht->link);
     
    343354            hash_table_get_instance(link, hashed_task_t, link) : NULL;
    344355       
    345         if ((ht == NULL) || ht->destroyed)
     356        if ((ht == NULL) || ht->finished)
    346357                return EINVAL;
    347358
     359        ht->finished = true;
     360        ht->have_rval = true;
    348361        ht->retval = IPC_GET_ARG1(*call);
    349362
     
    372385        hashed_task_t *ht =
    373386            hash_table_get_instance(link, hashed_task_t, link);
    374         assert(ht != NULL);
    375 
    376         ht->destroyed = true;
     387        if (ht == NULL)
     388                return EOK;
     389
     390        ht->finished = true;
    377391
    378392        return EOK;
Note: See TracChangeset for help on using the changeset viewer.