Changeset 012dd8e in mainline for uspace/lib/c/generic/taskman.c


Ignore:
Timestamp:
2019-08-07T09:15:30Z (6 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
e8747bd8
Parents:
780c8ce
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-11-01 00:08:04)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 09:15:30)
Message:

taskman: Handle INIT_TASKS as tasks spawned by loader

  • everyone is connected to its spawner, except for INIT_TASKS, they are connected to taskman (first binary)
  • taskman is now aware even of INIT_TASKS and taskman itself
  • refactored taskman handshake — NS session is created lazily
  • refactored async.c with usage of create_session
  • changed EINVAL to EINTR on lost waits
  • removed TODOs from taskman and related libc TODOs

Conflicts:

abi/include/abi/ipc/methods.h
boot/Makefile.common
uspace/lib/c/generic/async.c
uspace/lib/c/generic/libc.c
uspace/lib/c/generic/loader.c
uspace/lib/c/generic/ns.c
uspace/lib/c/generic/private/async.h
uspace/lib/c/generic/private/taskman.h
uspace/lib/c/generic/task.c
uspace/lib/c/include/async.h
uspace/lib/c/include/task.h
uspace/srv/loader/main.c
uspace/srv/ns/ns.c

File:
1 edited

Legend:

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

    r780c8ce r012dd8e  
    3333 */
    3434
     35
     36#include <async.h>
    3537#include <errno.h>
     38#include <ipc/common.h>
    3639#include <ipc/taskman.h>
     40#include <task.h>
    3741#include <taskman.h>
    3842
    39 #include <stdio.h>
     43#include "private/async.h"
     44#include "private/taskman.h"
    4045
    41 //TODO better filename?
    42 #include "private/ns.h"
     46async_sess_t *session_taskman = NULL;
    4347
    44 static int taskman_ask_callback(async_sess_t *session_tm)
     48void __task_init(async_sess_t *sess)
    4549{
    46         async_exch_t *exch = async_exchange_begin(session_tm);
     50        assert(session_taskman == NULL);
     51        session_taskman = sess;
     52}
     53
     54async_exch_t *taskman_exchange_begin(void)
     55{
     56        assert(session_taskman);
     57
     58        async_exch_t *exch = async_exchange_begin(session_taskman);
     59        return exch;
     60}
     61
     62void taskman_exchange_end(async_exch_t *exch)
     63{
     64        async_exchange_end(exch);
     65}
     66
     67/** Wrap PHONE_INITIAL with session and introduce to taskman
     68 */
     69async_sess_t *taskman_connect(void)
     70{
     71        /*
     72         *  EXCHANGE_ATOMIC would require single calls only,
     73         *  EXCHANGE_PARALLEL not sure about implementation via multiple phones,
     74         * >EXCHANGE_SERIALIZE perhaphs no harm, except the client serialization
     75         */
     76        const exch_mgmt_t mgmt = EXCHANGE_SERIALIZE;
     77        async_sess_t *sess = create_session(PHONE_INITIAL, mgmt, 0, 0, 0);
     78
     79        if (sess != NULL) {
     80                /* Introduce ourselves and ignore answer */
     81                async_exch_t *exch = async_exchange_begin(sess);
     82                aid_t req = async_send_0(exch, TASKMAN_NEW_TASK, NULL);
     83                async_exchange_end(exch);
     84               
     85                if (req) {
     86                        async_forget(req);
     87                }
     88        }
     89
     90        return sess;
     91}
     92
     93/** Ask taskman to pass/share its NS */
     94async_sess_t *taskman_session_ns(void)
     95{
     96        assert(session_taskman);
     97
     98        async_exch_t *exch = async_exchange_begin(session_taskman);
     99        assert(exch);
     100
     101        async_sess_t *sess = async_connect_me_to(EXCHANGE_ATOMIC,
     102            exch, TASKMAN_CONNECT_TO_NS, 0, 0);
     103        async_exchange_end(exch);
     104
     105        return sess;
     106}
     107
     108/** Ask taskman to connect to (a new) loader instance */
     109async_sess_t *taskman_session_loader(void)
     110{
     111        assert(session_taskman);
     112
     113        async_exch_t *exch = async_exchange_begin(session_taskman);
     114        async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE,
     115            exch, TASKMAN_CONNECT_TO_LOADER, 0, 0);
     116        async_exchange_end(exch);
     117
     118        return sess;
     119}
     120
     121/** Introduce as loader to taskman
     122 *
     123 * @return EOK on success, otherwise propagated error code
     124 */
     125int taskman_intro_loader(void)
     126{
     127        assert(session_taskman);
     128
     129        async_exch_t *exch = async_exchange_begin(session_taskman);
    47130        int rc = async_connect_to_me(
    48131            exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL);
     
    52135}
    53136
    54 static async_sess_t *taskman_connect_to_ns(async_sess_t *session_tm)
     137/** Tell taskman we are his NS
     138 *
     139 * @return EOK on success, otherwise propagated error code
     140 */
     141int taskman_intro_ns(void)
    55142{
    56         async_exch_t *exch = async_exchange_begin(session_tm);
    57         async_sess_t *session_ns = async_connect_me_to(EXCHANGE_ATOMIC,
    58             exch, TASKMAN_LOADER_TO_NS, 0, 0);
    59         async_exchange_end(exch);
     143        assert(session_taskman);
    60144
    61         return session_ns;
     145        async_exch_t *exch = async_exchange_begin(session_taskman);
     146        aid_t req = async_send_0(exch, TASKMAN_I_AM_NS, NULL);
     147
     148        int rc = async_connect_to_me(exch, 0, 0, 0, NULL, NULL);
     149        taskman_exchange_end(exch);
     150
     151        if (rc != EOK) {
     152                return rc;
     153        }
     154
     155        sysarg_t retval;
     156        async_wait_for(req, &retval);
     157        return retval;
    62158}
    63159
    64 /** Set up phones upon being spawned by taskman
    65  *
    66  * Assumes primary session exists that is connected to taskman.
    67  * After handshake, taskman is connected to us (see, it's opposite) and broker
    68  * session is set up according to taskman.
    69  *
    70  *
    71  * @return Session to broker (naming service) or NULL (sets errno).
    72  */
    73 async_sess_t *taskman_handshake(void)
     160async_sess_t *taskman_get_session(void)
    74161{
    75         int rc = taskman_ask_callback(session_primary);
    76         if (rc != EOK) {
    77                 errno = rc;
    78                 return NULL;
    79         }
     162        return session_taskman;
     163}
    80164
    81         async_sess_t *session_ns = taskman_connect_to_ns(session_primary);
    82         if (session_ns == NULL) {
    83                 errno = ENOENT;
    84         }
    85165
    86         return session_ns;
    87 }
    88166
    89167/** @}
Note: See TracChangeset for help on using the changeset viewer.