Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4619 → Rev 4620

/trunk/uspace/app/bdsh/exec.c
112,6 → 112,7
unsigned int try_exec(char *cmd, char **argv)
{
task_id_t tid;
task_exit_t texit;
char *tmp;
int retval;
 
126,9 → 127,12
return 1;
}
task_wait(tid, &retval);
if (retval != 0)
task_wait(tid, &texit, &retval);
if (texit != TASK_EXIT_NORMAL) {
printf("Command failed (unexpectedly terminated).\n");
} else if (retval != 0) {
printf("Command failed (return value %d).\n", retval);
}
 
return 0;
}
/trunk/uspace/app/getvc/getvc.c
73,6 → 73,7
 
int main(int argc, char *argv[])
{
task_exit_t texit;
int retval;
 
if (argc < 3) {
99,7 → 100,7
version_print(argv[1]);
task_id_t id = spawn(argv[2]);
task_wait(id, &retval);
task_wait(id, &texit, &retval);
return 0;
}
/trunk/uspace/lib/libc/include/task.h
39,10 → 39,15
 
typedef uint64_t task_id_t;
 
typedef enum {
TASK_EXIT_NORMAL,
TASK_EXIT_UNEXPECTED
} task_exit_t;
 
extern task_id_t task_get_id(void);
extern int task_set_name(const char *name);
extern task_id_t task_spawn(const char *path, char *const argv[]);
extern int task_wait(task_id_t id, int *retval);
extern int task_wait(task_id_t id, task_exit_t *texit, int *retval);
extern int task_retval(int val);
 
 
/trunk/uspace/lib/libc/generic/task.c
148,13 → 148,14
return 0;
}
 
int task_wait(task_id_t id, int *retval)
int task_wait(task_id_t id, task_exit_t *texit, int *retval)
{
ipcarg_t rv;
ipcarg_t te, rv;
int rc;
 
rc = (int) async_req_2_1(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
UPPER32(id), &rv);
rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
UPPER32(id), &te, &rv);
*texit = te;
*retval = rv;
 
return rc;
/trunk/uspace/srv/ns/task.c
56,9 → 56,10
/** Task hash table item. */
typedef struct {
link_t link;
task_id_t id; /**< Task ID. */
int retval;
bool destroyed;
task_id_t id; /**< Task ID. */
bool finished; /**< Task is done. */
bool have_rval; /**< Task returned a value. */
int retval; /**< The return value. */
} hashed_task_t;
 
/** Compute hash index into task hash table.
211,6 → 212,7
void process_pending_wait(void)
{
link_t *cur;
task_exit_t texit;
loop:
for (cur = pending_wait.next; cur != &pending_wait; cur = cur->next) {
226,12 → 228,16
continue;
hashed_task_t *ht = hash_table_get_instance(link, hashed_task_t, link);
if (!ht->destroyed)
if (!ht->finished)
continue;
if (!(pr->callid & IPC_CALLID_NOTIFICATION))
ipc_answer_1(pr->callid, EOK, ht->retval);
if (!(pr->callid & IPC_CALLID_NOTIFICATION)) {
texit = ht->have_rval ? TASK_EXIT_NORMAL :
TASK_EXIT_UNEXPECTED;
ipc_answer_2(pr->callid, EOK, texit,
ht->retval);
}
 
hash_table_remove(&task_hash_table, keys, 2);
list_remove(cur);
free(pr);
242,6 → 248,8
void wait_for_task(task_id_t id, ipc_call_t *call, ipc_callid_t callid)
{
ipcarg_t retval;
task_exit_t texit;
 
unsigned long keys[2] = {
LOWER32(id),
UPPER32(id)
257,7 → 265,7
goto out;
}
 
if (!ht->destroyed) {
if (!ht->finished) {
/* Add to pending list */
pending_wait_t *pr =
(pending_wait_t *) malloc(sizeof(pending_wait_t));
276,8 → 284,10
retval = EOK;
out:
if (!(callid & IPC_CALLID_NOTIFICATION))
ipc_answer_1(callid, retval, ht->retval);
if (!(callid & IPC_CALLID_NOTIFICATION)) {
texit = ht->have_rval ? TASK_EXIT_NORMAL : TASK_EXIT_UNEXPECTED;
ipc_answer_2(callid, retval, texit, ht->retval);
}
}
 
int ns_task_id_intro(ipc_call_t *call)
318,7 → 328,8
 
link_initialize(&ht->link);
ht->id = id;
ht->destroyed = false;
ht->finished = false;
ht->have_rval = false;
ht->retval = -1;
hash_table_insert(&task_hash_table, keys, &ht->link);
 
342,9 → 353,11
hashed_task_t *ht = (link != NULL) ?
hash_table_get_instance(link, hashed_task_t, link) : NULL;
if ((ht == NULL) || ht->destroyed)
if ((ht == NULL) || ht->finished)
return EINVAL;
 
ht->finished = true;
ht->have_rval = true;
ht->retval = IPC_GET_ARG1(*call);
 
return EOK;
371,9 → 384,10
link_t *link = hash_table_find(&task_hash_table, keys);
hashed_task_t *ht =
hash_table_get_instance(link, hashed_task_t, link);
assert(ht != NULL);
if (ht == NULL)
return EOK;
 
ht->destroyed = true;
ht->finished = true;
 
return EOK;
}