Changeset 012dd8e in mainline for uspace/lib/c/generic/async/client.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/async/client.c

    r780c8ce r012dd8e  
    124124static fibril_rmutex_t message_mutex;
    125125
    126 /** Primary session (spawn parent, later naming service) */
    127 async_sess_t *session_primary = NULL;
    128 
    129126/** Message data */
    130127typedef struct {
     
    169166
    170167
    171 static async_sess_t *create_session_primary(void)
     168/** Create session for existing phone
     169 *
     170 * @return session on success, NULL on error
     171 */
     172 
     173async_sess_t *create_session(cap_phone_handle_t phone, exch_mgmt_t mgmt,
     174    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
    172175{
    173176        async_sess_t *session = (async_sess_t *) malloc(sizeof(async_sess_t));
    174177
    175178        if (session != NULL) {
    176                 // TODO extract common part with async_connect_me_to
    177                 session_ns->iface = 0;
    178                 session->mgmt = EXCHANGE_ATOMIC;
    179                 session->phone = PHONE_INITIAL;
    180                 session->arg1 = 0;
    181                 session->arg2 = 0;
    182                 session->arg3 = 0;
     179                session->iface = 0;
     180                session->mgmt = mgmt;
     181                session->phone = phone;
     182                session->arg1 = arg1;
     183                session->arg2 = arg2;
     184                session->arg3 = arg3;
    183185               
    184186                fibril_mutex_initialize(&session->remote_state_mtx);
     
    189191                atomic_set(&session->refcnt, 0);
    190192                &session.exchanges = 0;
     193        } else {
     194                errno = ENOMEM;
    191195        }
    192196
     
    196200
    197201/** Initialize the async framework.
    198  * @param arg_session_primary Primary session (to naming service).
    199  *
    200  */
    201 void __async_client_init(async_sess_t *arg_session_primary)
     202 *
     203 */
     204void __async_client_init(void)
    202205{
    203206        if (fibril_rmutex_initialize(&message_mutex) != EOK)
    204                 abort();
    205 
    206         if (arg_session_primary == NULL) {
    207                 session_primary = create_session_primary();
    208         } else {
    209                 session_primary = arg_session_primary;
    210         }
    211 
    212         if (session_primary == NULL)
    213207                abort();
    214208}
     
    832826}
    833827
    834 /** Injects another session instead of original primary session
    835  *
    836  * @param  session  Session to naming service.
    837  *
    838  * @return old primary session (to spawn parent)
    839  */
    840 async_sess_t *async_session_primary_swap(async_sess_t *session)
    841 {
    842         assert(session_primary->phone == PHONE_INITIAL);
    843 
    844         async_sess_t *old_primary = session_primary;
    845         session_primary = session;
    846         return old_primary;
    847 }
    848 
    849828/** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework.
    850829 *
     
    865844        if (exch == NULL) {
    866845                errno = ENOENT;
    867                 return NULL;
    868         }
    869 
    870         async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    871         if (sess == NULL) {
    872                 errno = ENOMEM;
    873846                return NULL;
    874847        }
     
    879852        if (rc != EOK) {
    880853                errno = rc;
    881                 free(sess);
    882854                return NULL;
    883855        }
    884856
    885         sess->iface = iface;
    886         sess->phone = phone;
    887         sess->arg1 = iface;
    888         sess->arg2 = arg2;
    889         sess->arg3 = arg3;
    890 
    891         fibril_mutex_initialize(&sess->remote_state_mtx);
    892         list_initialize(&sess->exch_list);
    893         fibril_mutex_initialize(&sess->mutex);
     857        async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);
     858        if (sess == NULL) {
     859                ipc_hangup(phone);
     860        }
    894861
    895862        return sess;
     
    933900        if (exch == NULL) {
    934901                errno = ENOENT;
    935                 return NULL;
    936         }
    937 
    938         async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    939         if (sess == NULL) {
    940                 errno = ENOMEM;
    941902                return NULL;
    942903        }
     
    951912        }
    952913
    953         sess->iface = iface;
    954         sess->phone = phone;
    955         sess->arg1 = iface;
    956         sess->arg2 = arg2;
    957         sess->arg3 = arg3;
    958 
    959         fibril_mutex_initialize(&sess->remote_state_mtx);
    960         list_initialize(&sess->exch_list);
    961         fibril_mutex_initialize(&sess->mutex);
     914        async_sess_t *sess = create_session(phone, mgmt, iface, arg2, arg3);
     915        if (sess == NULL) {
     916                ipc_hangup(phone);
     917        }
    962918
    963919        return sess;
     
    969925async_sess_t *async_connect_kbox(task_id_t id)
    970926{
    971         async_sess_t *sess = calloc(1, sizeof(async_sess_t));
    972         if (sess == NULL) {
    973                 errno = ENOMEM;
    974                 return NULL;
    975         }
    976 
    977927        cap_phone_handle_t phone;
    978928        errno_t rc = ipc_connect_kbox(id, &phone);
    979929        if (rc != EOK) {
    980930                errno = rc;
    981                 free(sess);
    982931                return NULL;
    983932        }
    984933
    985         sess->iface = 0;
    986         sess->mgmt = EXCHANGE_ATOMIC;
    987         sess->phone = phone;
    988 
    989         fibril_mutex_initialize(&sess->remote_state_mtx);
    990         list_initialize(&sess->exch_list);
    991         fibril_mutex_initialize(&sess->mutex);
     934        async_sess_t *sess = create_session(phone, EXCHANGE_ATOMIC, 0, 0, 0);
     935        if (sess == NULL) {
     936                ipc_hangup(phone);
     937        }
    992938
    993939        return sess;
Note: See TracChangeset for help on using the changeset viewer.