Changeset 012dd8e in mainline for uspace/lib/c/generic/taskman.c
- Timestamp:
- 2019-08-07T09:15:30Z (6 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/taskman.c
r780c8ce r012dd8e 33 33 */ 34 34 35 36 #include <async.h> 35 37 #include <errno.h> 38 #include <ipc/common.h> 36 39 #include <ipc/taskman.h> 40 #include <task.h> 37 41 #include <taskman.h> 38 42 39 #include <stdio.h> 43 #include "private/async.h" 44 #include "private/taskman.h" 40 45 41 //TODO better filename? 42 #include "private/ns.h" 46 async_sess_t *session_taskman = NULL; 43 47 44 static int taskman_ask_callback(async_sess_t *session_tm)48 void __task_init(async_sess_t *sess) 45 49 { 46 async_exch_t *exch = async_exchange_begin(session_tm); 50 assert(session_taskman == NULL); 51 session_taskman = sess; 52 } 53 54 async_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 62 void 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 */ 69 async_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 */ 94 async_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 */ 109 async_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 */ 125 int taskman_intro_loader(void) 126 { 127 assert(session_taskman); 128 129 async_exch_t *exch = async_exchange_begin(session_taskman); 47 130 int rc = async_connect_to_me( 48 131 exch, TASKMAN_LOADER_CALLBACK, 0, 0, NULL, NULL); … … 52 135 } 53 136 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 */ 141 int taskman_intro_ns(void) 55 142 { 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); 60 144 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; 62 158 } 63 159 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) 160 async_sess_t *taskman_get_session(void) 74 161 { 75 int rc = taskman_ask_callback(session_primary); 76 if (rc != EOK) { 77 errno = rc; 78 return NULL; 79 } 162 return session_taskman; 163 } 80 164 81 async_sess_t *session_ns = taskman_connect_to_ns(session_primary);82 if (session_ns == NULL) {83 errno = ENOENT;84 }85 165 86 return session_ns;87 }88 166 89 167 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.