Changeset 1be7bee in mainline for uspace/lib/c/generic/task.c


Ignore:
Timestamp:
2019-08-07T04:20:30Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
70d28e8
Parents:
fe86d9d
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-10-05 21:17:40)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 04:20:30)
Message:

sysman: Move task retval and waiting logic to taskman (partially)

  • two important sessions: NS and taskman
  • depending on boot task vs spawned task those sessions are initiated differently

Conflicts:

uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/task.c
uspace/lib/c/include/ipc/ns.h
uspace/lib/c/include/task.h
uspace/lib/posix/source/sys/wait.c
uspace/srv/loader/main.c
uspace/srv/ns/ns.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/task.c

    rfe86d9d r1be7bee  
    3535 */
    3636
    37 #include <task.h>
    38 #include <loader/loader.h>
    39 #include <stdarg.h>
    40 #include <str.h>
    41 #include <ipc/ns.h>
    42 #include <macros.h>
    4337#include <assert.h>
    4438#include <async.h>
     
    4640#include <ns.h>
    4741#include <stdlib.h>
     42#include <ipc/taskman.h>
    4843#include <libc.h>
     44#include <loader/loader.h>
     45#include <macros.h>
     46#include <malloc.h>
     47#include <stdarg.h>
     48#include <str.h>
     49#include <task.h>
     50#include <vfs/vfs.h>
    4951#include "private/ns.h"
    50 #include <vfs/vfs.h>
     52#include "private/task.h"
     53
     54static async_sess_t *session_taskman = NULL;
    5155
    5256task_id_t task_get_id(void)
     
    6468}
    6569
     70static async_exch_t *taskman_exchange_begin(void)
     71{
     72        /* Lazy connection */
     73        if (session_taskman == NULL) {
     74                // TODO unify exchange mgmt with taskman_handshake/__init
     75                session_taskman = service_connect_blocking(EXCHANGE_SERIALIZE,
     76                    SERVICE_TASKMAN,
     77                    TASKMAN_CONTROL,
     78                    0);
     79        }
     80
     81        if (session_taskman == NULL) {
     82                return NULL;
     83        }
     84
     85        async_exch_t *exch = async_exchange_begin(session_taskman);
     86        return exch;
     87}
     88
     89static void taskman_exchange_end(async_exch_t *exch)
     90{
     91        async_exchange_end(exch);
     92}
     93
    6694/** Set the task name.
    6795 *
     
    88116{
    89117        return (errno_t) __SYSCALL1(SYS_TASK_KILL, (sysarg_t) &task_id);
     118}
     119
     120/** Setup waiting for a task.
     121 *
     122 * If the task finishes after this call succeeds, it is guaranteed that
     123 * task_wait(wait, &texit, &retval) will return correct return value for
     124 * the task.
     125 *
     126 * @param id   ID of the task to setup waiting for.
     127 * @param wait Information necessary for the later task_wait call is stored here.
     128 *
     129 * @return EOK on success, else error code.
     130 */
     131static errno_t task_setup_wait(task_id_t id, task_wait_t *wait)
     132{
     133        async_exch_t *exch = taskman_exchange_begin();
     134        if (exch == NULL)
     135                        return EIO;
     136
     137        wait->aid = async_send_3(exch, TASKMAN_WAIT, LOWER32(id), UPPER32(id),
     138            wait->flags, &wait->result);
     139        taskman_exchange_end(exch);
     140
     141        return EOK;
    90142}
    91143
     
    312364}
    313365
    314 /** Setup waiting for a task.
    315  *
    316  * If the task finishes after this call succeeds, it is guaranteed that
    317  * task_wait(wait, &texit, &retval) will return correct return value for
    318  * the task.
    319  *
    320  * @param id   ID of the task to setup waiting for.
    321  * @param wait Information necessary for the later task_wait call is stored here.
    322  *
    323  * @return EOK on success, else error code.
    324  */
    325 errno_t task_setup_wait(task_id_t id, task_wait_t *wait)
    326 {
    327         async_sess_t *sess_ns = get_session_primary();
    328         if (sess_ns == NULL)
    329                 return EIO;
    330 
    331         async_exch_t *exch = async_exchange_begin(sess_ns);
    332 
    333         wait->aid = async_send_2(exch, NS_TASK_WAIT, LOWER32(id), UPPER32(id),
    334             &wait->result);
    335         async_exchange_end(exch);
    336 
    337         return EOK;
    338 }
    339 
    340366/** Cancel waiting for a task.
    341367 *
     
    391417 *
    392418 * @param id ID of the task to wait for.
     419 * @param flags  Specify for which task output we wait
    393420 * @param texit  Store type of task exit here.
    394421 * @param retval Store return value of the task here.
     
    396423 * @return EOK on success, else error code.
    397424 */
    398 errno_t task_wait_task_id(task_id_t id, task_exit_t *texit, int *retval)
     425errno_t task_wait_task_id(task_id_t id, int flags, task_exit_t *texit, int *retval)
    399426{
    400427        task_wait_t wait;
     428        wait.flags = flags;
    401429        errno_t rc = task_setup_wait(id, &wait);
     430
    402431        if (rc != EOK)
    403432                return rc;
     
    408437errno_t task_retval(int val)
    409438{
    410         async_sess_t *sess_ns = get_session_primary();
    411         if (sess_ns == NULL)
     439        async_exch_t *exch = taskman_exchange_begin();
     440        if (exch == NULL)
    412441                return EIO;
    413442
    414         async_exch_t *exch = async_exchange_begin(sess_ns);
    415         errno_t rc = (errno_t) async_req_1_0(exch, NS_RETVAL, val);
    416         async_exchange_end(exch);
    417 
     443        int rc = (int) async_req_1_0(exch, TASKMAN_RETVAL, val);
     444        taskman_exchange_end(exch);
     445       
    418446        return rc;
    419447}
    420448
     449
     450void __task_init(async_sess_t *sess)
     451{
     452        assert(session_taskman == NULL);
     453        session_taskman = sess;
     454}
     455
    421456/** @}
    422457 */
Note: See TracChangeset for help on using the changeset viewer.