source: mainline/uspace/lib/c/generic/taskman.c@ 012dd8e

Last change on this file since 012dd8e was 012dd8e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

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

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[40313e4]1/*
[0a8f070]2 * Copyright (c) 2015 Michal Koutny
[40313e4]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[0a8f070]29/** @addtogroup libc
[40313e4]30 * @{
31 */
[0a8f070]32/** @file
33 */
34
[012dd8e]35
36#include <async.h>
[0a8f070]37#include <errno.h>
[012dd8e]38#include <ipc/common.h>
[0a8f070]39#include <ipc/taskman.h>
[012dd8e]40#include <task.h>
[0a8f070]41#include <taskman.h>
42
[012dd8e]43#include "private/async.h"
44#include "private/taskman.h"
[0a8f070]45
[012dd8e]46async_sess_t *session_taskman = NULL;
[0a8f070]47
[012dd8e]48void __task_init(async_sess_t *sess)
49{
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)
[0a8f070]63{
64 async_exchange_end(exch);
[012dd8e]65}
[0a8f070]66
[012dd8e]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;
[0a8f070]91}
[40313e4]92
[012dd8e]93/** Ask taskman to pass/share its NS */
94async_sess_t *taskman_session_ns(void)
[0a8f070]95{
[012dd8e]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);
[0a8f070]103 async_exchange_end(exch);
[40313e4]104
[012dd8e]105 return sess;
[0a8f070]106}
107
[012dd8e]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
[0a8f070]122 *
[012dd8e]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);
130 int rc = async_connect_to_me(
131 exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL);
132 async_exchange_end(exch);
133
134 return rc;
135}
136
137/** Tell taskman we are his NS
[0a8f070]138 *
[012dd8e]139 * @return EOK on success, otherwise propagated error code
[0a8f070]140 */
[012dd8e]141int taskman_intro_ns(void)
[0a8f070]142{
[012dd8e]143 assert(session_taskman);
144
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
[0a8f070]151 if (rc != EOK) {
[012dd8e]152 return rc;
[0a8f070]153 }
[40313e4]154
[012dd8e]155 sysarg_t retval;
156 async_wait_for(req, &retval);
157 return retval;
158}
[40313e4]159
[012dd8e]160async_sess_t *taskman_get_session(void)
161{
162 return session_taskman;
[0a8f070]163}
[40313e4]164
[012dd8e]165
166
[0a8f070]167/** @}
[40313e4]168 */
Note: See TracBrowser for help on using the repository browser.