Changeset 79ae36dd in mainline for uspace/lib/c/generic/task.c


Ignore:
Timestamp:
2011-06-08T19:01:55Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
File:
1 edited

Legend:

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

    r764d71e r79ae36dd  
    3535
    3636#include <task.h>
    37 #include <libc.h>
    38 #include <stdlib.h>
    39 #include <errno.h>
    4037#include <loader/loader.h>
    4138#include <stdarg.h>
     
    4340#include <ipc/ns.h>
    4441#include <macros.h>
     42#include <assert.h>
    4543#include <async.h>
     44#include <errno.h>
     45#include <malloc.h>
     46#include <libc.h>
     47#include "private/ns.h"
    4648
    4749task_id_t task_get_id(void)
     
    6870int task_set_name(const char *name)
    6971{
     72        assert(name);
     73       
    7074        return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
    7175}
     
    8892 * loader API. Arguments are passed as a null-terminated array of strings.
    8993 *
    90  * @param id    If not NULL, the ID of the task is stored here on success.
    91  * @param path  Pathname of the binary to execute.
    92  * @param argv  Command-line arguments.
    93  *
    94  * @return      Zero on success or negative error code.
     94 * @param id   If not NULL, the ID of the task is stored here on success.
     95 * @param path Pathname of the binary to execute.
     96 * @param argv Command-line arguments.
     97 *
     98 * @return Zero on success or negative error code.
     99 *
    95100 */
    96101int task_spawnv(task_id_t *id, const char *path, const char *const args[])
    97102{
    98         loader_t *ldr;
    99         task_id_t task_id;
    100         int rc;
    101 
    102103        /* Connect to a program loader. */
    103         ldr = loader_connect();
     104        loader_t *ldr = loader_connect();
    104105        if (ldr == NULL)
    105106                return EREFUSED;
    106107       
    107108        /* Get task ID. */
    108         rc = loader_get_task_id(ldr, &task_id);
     109        task_id_t task_id;
     110        int rc = loader_get_task_id(ldr, &task_id);
    109111        if (rc != EOK)
    110112                goto error;
     
    163165       
    164166        /* Success */
    165         free(ldr);
    166        
    167167        if (id != NULL)
    168168                *id = task_id;
     
    182182 * loader API. Arguments are passed as a null-terminated list of arguments.
    183183 *
    184  * @param id    If not NULL, the ID of the task is stored here on success.
    185  * @param path  Pathname of the binary to execute.
    186  * @param ...   Command-line arguments.
    187  *
    188  * @return      Zero on success or negative error code.
     184 * @param id   If not NULL, the ID of the task is stored here on success.
     185 * @param path Pathname of the binary to execute.
     186 * @param ...  Command-line arguments.
     187 *
     188 * @return Zero on success or negative error code.
     189 *
    189190 */
    190191int task_spawnl(task_id_t *task_id, const char *path, ...)
    191192{
     193        /* Count the number of arguments. */
     194       
    192195        va_list ap;
    193         int rc, cnt;
    194196        const char *arg;
    195197        const char **arglist;
    196 
    197         /* Count the number of arguments. */
    198         cnt = 0;
     198        int cnt = 0;
     199       
    199200        va_start(ap, path);
    200201        do {
     
    203204        } while (arg != NULL);
    204205        va_end(ap);
    205 
     206       
    206207        /* Allocate argument list. */
    207208        arglist = malloc(cnt * sizeof(const char *));
    208209        if (arglist == NULL)
    209210                return ENOMEM;
    210 
     211       
    211212        /* Fill in arguments. */
    212213        cnt = 0;
     
    217218        } while (arg != NULL);
    218219        va_end(ap);
    219 
     220       
    220221        /* Spawn task. */
    221         rc = task_spawnv(task_id, path, arglist);
    222 
     222        int rc = task_spawnv(task_id, path, arglist);
     223       
    223224        /* Free argument list. */
    224225        free(arglist);
     
    228229int task_wait(task_id_t id, task_exit_t *texit, int *retval)
    229230{
     231        assert(texit);
     232        assert(retval);
     233       
     234        async_exch_t *exch = async_exchange_begin(session_ns);
    230235        sysarg_t te, rv;
    231         int rc;
    232 
    233         rc = (int) async_req_2_2(PHONE_NS, NS_TASK_WAIT, LOWER32(id),
     236        int rc = (int) async_req_2_2(exch, NS_TASK_WAIT, LOWER32(id),
    234237            UPPER32(id), &te, &rv);
     238        async_exchange_end(exch);
     239       
    235240        *texit = te;
    236241        *retval = rv;
    237 
     242       
    238243        return rc;
    239244}
     
    241246int task_retval(int val)
    242247{
    243         return (int) async_req_1_0(PHONE_NS, NS_RETVAL, val);
     248        async_exch_t *exch = async_exchange_begin(session_ns);
     249        int rc = (int) async_req_1_0(exch, NS_RETVAL, val);
     250        async_exchange_end(exch);
     251       
     252        return rc;
    244253}
    245254
Note: See TracChangeset for help on using the changeset viewer.