Changeset af2a76c in mainline for uspace/lib


Ignore:
Timestamp:
2014-07-13T17:25:15Z (12 years ago)
Author:
Agnieszka Tabaka <nufcia@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7493e7b
Parents:
b8e75319 (diff), 78192cc7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/lib
Files:
2 deleted
19 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/arch/amd64/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/arm32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ia32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ppc32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/sparc32/src/stacktrace.c

    rb8e75319 raf2a76c  
    5353{
    5454        uintptr_t bprev;
    55         int rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
     55        int rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
    5656            &bprev);
    5757        if (rc == EOK)
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/arch/sparc64/src/stacktrace.c

    rb8e75319 raf2a76c  
    5555        int rc;
    5656
    57         rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
     57        rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
    5858        if (rc == EOK)
    5959                *prev = bprev + STACK_BIAS;
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/generic/fibril.c

    rb8e75319 raf2a76c  
    5959static LIST_INITIALIZE(serialized_list);
    6060static LIST_INITIALIZE(manager_list);
     61static LIST_INITIALIZE(fibril_list);
    6162
    6263/** Number of threads that are executing a manager fibril. */
     
    116117       
    117118        fibril->waits_for = NULL;
     119        list_append(&fibril->all_link, &fibril_list);
    118120       
    119121        return fibril;
     
    122124void fibril_teardown(fibril_t *fibril)
    123125{
     126        list_remove(&fibril->all_link);
    124127        tls_free(fibril->tcb);
    125128        free(fibril);
  • uspace/lib/c/generic/fibril_synch.c

    rb8e75319 raf2a76c  
    448448        int rc;
    449449
    450         fibril_mutex_lock(&timer->lock);
    451 
    452         while (true) {
    453                 while (timer->state != fts_active &&
    454                     timer->state != fts_cleanup) {
    455 
    456                         if (timer->state == fts_cleanup)
    457                                 break;
    458 
    459                         fibril_condvar_wait(&timer->cv, &timer->lock);
     450        fibril_mutex_lock(timer->lockp);
     451
     452        while (timer->state != fts_cleanup) {
     453                switch (timer->state) {
     454                case fts_not_set:
     455                case fts_fired:
     456                        fibril_condvar_wait(&timer->cv, timer->lockp);
     457                        break;
     458                case fts_active:
     459                        rc = fibril_condvar_wait_timeout(&timer->cv,
     460                            timer->lockp, timer->delay);
     461                        if (rc == ETIMEOUT && timer->state == fts_active) {
     462                                timer->state = fts_fired;
     463                                timer->handler_running = true;
     464                                fibril_mutex_unlock(timer->lockp);
     465                                timer->fun(timer->arg);
     466                                fibril_mutex_lock(timer->lockp);
     467                                timer->handler_running = false;
     468                        }
     469                        break;
     470                case fts_cleanup:
     471                case fts_clean:
     472                        assert(false);
     473                        break;
    460474                }
    461 
    462                 if (timer->state == fts_cleanup)
    463                         break;
    464 
    465                 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock,
    466                     timer->delay);
    467                 if (rc == ETIMEOUT) {
    468                         timer->state = fts_fired;
    469                         fibril_mutex_unlock(&timer->lock);
    470                         timer->fun(timer->arg);
    471                         fibril_mutex_lock(&timer->lock);
    472                 }
    473         }
    474 
    475         fibril_mutex_unlock(&timer->lock);
     475        }
     476
     477        /* Acknowledge timer fibril has finished cleanup. */
     478        timer->state = fts_clean;
     479        fibril_mutex_unlock(timer->lockp);
     480        free(timer);
     481
    476482        return 0;
    477483}
     
    481487 * @return              New timer on success, @c NULL if out of memory.
    482488 */
    483 fibril_timer_t *fibril_timer_create(void)
     489fibril_timer_t *fibril_timer_create(fibril_mutex_t *lock)
    484490{
    485491        fid_t fid;
     
    501507        timer->fibril = fid;
    502508        timer->state = fts_not_set;
     509        timer->lockp = (lock != NULL) ? lock : &timer->lock;
    503510
    504511        fibril_add_ready(fid);
    505 
    506512        return timer;
    507513}
     
    513519void fibril_timer_destroy(fibril_timer_t *timer)
    514520{
    515         fibril_mutex_lock(&timer->lock);
    516         assert(timer->state != fts_active);
     521        fibril_mutex_lock(timer->lockp);
     522        assert(timer->state == fts_not_set || timer->state == fts_fired);
     523
     524        /* Request timer fibril to terminate. */
    517525        timer->state = fts_cleanup;
    518526        fibril_condvar_broadcast(&timer->cv);
    519         fibril_mutex_unlock(&timer->lock);
     527        fibril_mutex_unlock(timer->lockp);
    520528}
    521529
     
    533541    fibril_timer_fun_t fun, void *arg)
    534542{
    535         fibril_mutex_lock(&timer->lock);
     543        fibril_mutex_lock(timer->lockp);
     544        fibril_timer_set_locked(timer, delay, fun, arg);
     545        fibril_mutex_unlock(timer->lockp);
     546}
     547
     548/** Set locked timer.
     549 *
     550 * Set timer to execute a callback function after the specified
     551 * interval. Must be called when the timer is locked.
     552 *
     553 * @param timer         Timer
     554 * @param delay         Delay in microseconds
     555 * @param fun           Callback function
     556 * @param arg           Argument for @a fun
     557 */
     558void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay,
     559    fibril_timer_fun_t fun, void *arg)
     560{
     561        assert(fibril_mutex_is_locked(timer->lockp));
     562        assert(timer->state == fts_not_set || timer->state == fts_fired);
    536563        timer->state = fts_active;
    537564        timer->delay = delay;
     
    539566        timer->arg = arg;
    540567        fibril_condvar_broadcast(&timer->cv);
    541         fibril_mutex_unlock(&timer->lock);
    542568}
    543569
     
    557583        fibril_timer_state_t old_state;
    558584
    559         fibril_mutex_lock(&timer->lock);
     585        fibril_mutex_lock(timer->lockp);
     586        old_state = fibril_timer_clear_locked(timer);
     587        fibril_mutex_unlock(timer->lockp);
     588
     589        return old_state;
     590}
     591
     592/** Clear locked timer.
     593 *
     594 * Clears (cancels) timer and returns last state of the timer.
     595 * This can be one of:
     596 *    - fts_not_set     If the timer has not been set or has been cleared
     597 *    - fts_active      Timer was set but did not fire
     598 *    - fts_fired       Timer fired
     599 * Must be called when the timer is locked.
     600 *
     601 * @param timer         Timer
     602 * @return              Last timer state
     603 */
     604fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *timer)
     605{
     606        fibril_timer_state_t old_state;
     607
     608        assert(fibril_mutex_is_locked(timer->lockp));
     609
     610        while (timer->handler_running)
     611                fibril_condvar_wait(&timer->cv, timer->lockp);
     612
    560613        old_state = timer->state;
    561614        timer->state = fts_not_set;
     
    565618        timer->arg = NULL;
    566619        fibril_condvar_broadcast(&timer->cv);
    567         fibril_mutex_unlock(&timer->lock);
    568620
    569621        return old_state;
  • uspace/lib/c/generic/inet.c

    rb8e75319 raf2a76c  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3434#include <ipc/services.h>
    3535#include <loc.h>
     36#include <stdlib.h>
    3637
    3738static void inet_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     
    224225       
    225226        rc = inet_ev_ops->recv(&dgram);
     227        free(dgram.data);
    226228        async_answer_0(iid, rc);
    227229}
  • uspace/lib/c/generic/stacktrace.c

    rb8e75319 raf2a76c  
    4242static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data);
    4343
    44 void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     44static stacktrace_ops_t basic_ops = {
     45        .read_uintptr = stacktrace_read_uintptr
     46};
     47
     48void stacktrace_print_generic(stacktrace_ops_t *ops, void *arg, uintptr_t fp,
     49    uintptr_t pc)
    4550{
    4651        stacktrace_t st;
    4752        uintptr_t nfp;
     53        int rc;
    4854
    49         st.op_arg = NULL;
    50         st.read_uintptr = stacktrace_read_uintptr;
     55        st.op_arg = arg;
     56        st.ops = ops;
    5157
    5258        while (stacktrace_fp_valid(&st, fp)) {
    5359                printf("%p: %p()\n", (void *) fp, (void *) pc);
    54                 (void) stacktrace_ra_get(&st, fp, &pc);
    55                 (void) stacktrace_fp_prev(&st, fp, &nfp);
     60                rc =  stacktrace_ra_get(&st, fp, &pc);
     61                if (rc != EOK)
     62                        break;
     63                rc = stacktrace_fp_prev(&st, fp, &nfp);
     64                if (rc != EOK)
     65                        break;
    5666                fp = nfp;
    5767        }
     68}
     69
     70void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     71{
     72        stacktrace_print_generic(&basic_ops, NULL, fp, pc);
    5873}
    5974
  • uspace/lib/c/generic/str.c

    rb8e75319 raf2a76c  
    13601360}
    13611361
    1362 char *strtok(char *s, const char *delim)
    1363 {
    1364         static char *next;
    1365 
    1366         return strtok_r(s, delim, &next);
    1367 }
    1368 
    1369 char *strtok_r(char *s, const char *delim, char **next)
     1362/** Split string by delimiters.
     1363 *
     1364 * @param s             String to be tokenized. May not be NULL.
     1365 * @param delim         String with the delimiters.
     1366 * @param next          Variable which will receive the pointer to the
     1367 *                      continuation of the string following the first
     1368 *                      occurrence of any of the delimiter characters.
     1369 *                      May be NULL.
     1370 * @return              Pointer to the prefix of @a s before the first
     1371 *                      delimiter character. NULL if no such prefix
     1372 *                      exists.
     1373 */
     1374char *str_tok(char *s, const char *delim, char **next)
    13701375{
    13711376        char *start, *end;
    13721377
    1373         if (s == NULL)
    1374                 s = *next;
     1378        if (!s)
     1379                return NULL;
     1380       
     1381        size_t len = str_size(s);
     1382        size_t cur;
     1383        size_t tmp;
     1384        wchar_t ch;
    13751385
    13761386        /* Skip over leading delimiters. */
    1377         while (*s && (str_chr(delim, *s) != NULL)) ++s;
    1378         start = s;
     1387        for (tmp = cur = 0;
     1388            (ch = str_decode(s, &tmp, len)) && str_chr(delim, ch); /**/)
     1389                cur = tmp;
     1390        start = &s[cur];
    13791391
    13801392        /* Skip over token characters. */
    1381         while (*s && (str_chr(delim, *s) == NULL)) ++s;
    1382         end = s;
    1383         *next = (*s ? s + 1 : s);
    1384 
    1385         if (start == end) {
     1393        for (tmp = cur;
     1394            (ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch); /**/)
     1395                cur = tmp;
     1396        end = &s[cur];
     1397        if (next)
     1398                *next = (ch ? &s[tmp] : &s[cur]);
     1399
     1400        if (start == end)
    13861401                return NULL;    /* No more tokens. */
    1387         }
    13881402
    13891403        /* Overwrite delimiter with NULL terminator. */
  • uspace/lib/c/include/fibril.h

    rb8e75319 raf2a76c  
    6767typedef struct fibril {
    6868        link_t link;
     69        link_t all_link;
    6970        context_t ctx;
    7071        void *stack;
  • uspace/lib/c/include/fibril_synch.h

    rb8e75319 raf2a76c  
    116116        /** Timer has fired and has not been cleared since */
    117117        fts_fired,
    118         /** Timer is being destroyed */
    119         fts_cleanup
     118        /** Timer fibril is requested to terminate */
     119        fts_cleanup,
     120        /** Timer fibril acknowledged termination */
     121        fts_clean
    120122} fibril_timer_state_t;
    121123
     
    129131typedef struct {
    130132        fibril_mutex_t lock;
     133        fibril_mutex_t *lockp;
    131134        fibril_condvar_t cv;
    132135        fid_t fibril;
    133136        fibril_timer_state_t state;
     137        bool handler_running;
    134138
    135139        suseconds_t delay;
     
    160164extern void fibril_condvar_broadcast(fibril_condvar_t *);
    161165
    162 extern fibril_timer_t *fibril_timer_create(void);
     166extern fibril_timer_t *fibril_timer_create(fibril_mutex_t *);
    163167extern void fibril_timer_destroy(fibril_timer_t *);
    164168extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t,
    165169    void *);
     170extern void fibril_timer_set_locked(fibril_timer_t *, suseconds_t,
     171    fibril_timer_fun_t, void *);
    166172extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
     173extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *);
    167174
    168175#endif
  • uspace/lib/c/include/ipc/dev_iface.h

    rb8e75319 raf2a76c  
    4040        /** Character device interface */
    4141        CHAR_DEV_IFACE,
    42 
    43         /** Graphic device interface */
    44         GRAPH_DEV_IFACE,
    4542
    4643        /** Audio device mixer interface */
  • uspace/lib/c/include/stacktrace.h

    rb8e75319 raf2a76c  
    4141
    4242typedef struct {
     43        int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     44} stacktrace_ops_t;
     45
     46typedef struct {
    4347        void *op_arg;
    44         int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     48        stacktrace_ops_t *ops;
    4549} stacktrace_t;
    4650
    4751extern void stacktrace_print(void);
    4852extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t);
     53extern void stacktrace_print_generic(stacktrace_ops_t *, void *, uintptr_t,
     54    uintptr_t);
    4955
    5056/*
  • uspace/lib/c/include/str.h

    rb8e75319 raf2a76c  
    109109extern char *str_ndup(const char *, size_t max_size);
    110110
     111extern char *str_tok(char *, const char *, char **);
     112
    111113extern int str_uint8_t(const char *, const char **, unsigned int, bool,
    112114    uint8_t *);
     
    132134extern unsigned long strtoul(const char *, char **, int);
    133135
    134 extern char * strtok_r(char *, const char *, char **);
    135 extern char * strtok(char *, const char *);
    136 
    137136#endif
    138137
  • uspace/lib/drv/Makefile

    rb8e75319 raf2a76c  
    4747        generic/remote_pio_window.c \
    4848        generic/remote_char_dev.c \
    49         generic/remote_graph_dev.c \
    5049        generic/remote_nic.c \
    5150        generic/remote_usb.c \
  • uspace/lib/drv/generic/dev_iface.c

    rb8e75319 raf2a76c  
    4545#include "remote_led_dev.h"
    4646#include "remote_battery_dev.h"
    47 #include "remote_graph_dev.h"
    4847#include "remote_nic.h"
    4948#include "remote_usb.h"
     
    6261                [PIO_WINDOW_DEV_IFACE] = &remote_pio_window_iface,
    6362                [CHAR_DEV_IFACE] = &remote_char_dev_iface,
    64                 [GRAPH_DEV_IFACE] = &remote_graph_dev_iface,
    6563                [NIC_DEV_IFACE] = &remote_nic_iface,
    6664                [PCI_DEV_IFACE] = &remote_pci_iface,
  • uspace/lib/graph/graph.c

    rb8e75319 raf2a76c  
    5858visualizer_t *graph_alloc_visualizer(void)
    5959{
    60         visualizer_t *vs = (visualizer_t *) malloc(sizeof(visualizer_t));
    61         if (vs == NULL) {
    62                 return NULL;
    63         }
    64        
    65         return vs;
     60        return ((visualizer_t *) malloc(sizeof(visualizer_t)));
    6661}
    6762
     
    6964{
    7065        // TODO
    71         renderer_t *rnd = (renderer_t *) malloc(sizeof(renderer_t));
    72         if (rnd == NULL) {
    73                 return NULL;
    74         }
    75 
    76         return rnd;
     66        return ((renderer_t *) malloc(sizeof(renderer_t)));
    7767}
    7868
     
    9888int graph_register_visualizer(visualizer_t *vs)
    9989{
    100         int rc = EOK;
    101        
    10290        char node[LOC_NAME_MAXLEN + 1];
    10391        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    10492            namespace_idx, VISUALIZER_NAME, visualizer_idx++);
    105 
     93       
    10694        category_id_t cat;
    107         rc = loc_category_get_id("visualizer", &cat, 0);
    108         if (rc != EOK) {
     95        int rc = loc_category_get_id("visualizer", &cat, 0);
     96        if (rc != EOK)
    10997                return rc;
    110         }
    111 
     98       
    11299        rc = loc_service_register(node, &vs->reg_svc_handle);
    113         if (rc != EOK) {
     100        if (rc != EOK)
    114101                return rc;
    115         }
    116 
     102       
    117103        rc = loc_service_add_to_cat(vs->reg_svc_handle, cat);
    118104        if (rc != EOK) {
     
    120106                return rc;
    121107        }
    122 
     108       
    123109        fibril_mutex_lock(&visualizer_list_mtx);
    124110        list_append(&vs->link, &visualizer_list);
    125111        fibril_mutex_unlock(&visualizer_list_mtx);
    126 
     112       
    127113        return rc;
    128114}
     
    130116int graph_register_renderer(renderer_t *rnd)
    131117{
    132         int rc = EOK;
    133 
    134118        char node[LOC_NAME_MAXLEN + 1];
    135119        snprintf(node, LOC_NAME_MAXLEN, "%s%zu/%s%zu", NAMESPACE,
    136120            namespace_idx, RENDERER_NAME, renderer_idx++);
    137 
     121       
    138122        category_id_t cat;
    139         rc = loc_category_get_id("renderer", &cat, 0);
    140         if (rc != EOK) {
     123        int rc = loc_category_get_id("renderer", &cat, 0);
     124        if (rc != EOK)
    141125                return rc;
    142         }
    143 
     126       
    144127        rc = loc_service_register(node, &rnd->reg_svc_handle);
    145         if (rc != EOK) {
     128        if (rc != EOK)
    146129                return rc;
    147         }
    148 
     130       
    149131        rc = loc_service_add_to_cat(rnd->reg_svc_handle, cat);
    150132        if (rc != EOK) {
     
    152134                return rc;
    153135        }
    154 
     136       
    155137        fibril_mutex_lock(&renderer_list_mtx);
    156138        list_append(&rnd->link, &renderer_list);
    157139        fibril_mutex_unlock(&renderer_list_mtx);
    158 
     140       
    159141        return rc;
    160142}
     
    163145{
    164146        visualizer_t *vs = NULL;
    165 
     147       
    166148        fibril_mutex_lock(&visualizer_list_mtx);
     149       
    167150        list_foreach(visualizer_list, link, visualizer_t, vcur) {
    168151                if (vcur->reg_svc_handle == handle) {
     
    171154                }
    172155        }
     156       
    173157        fibril_mutex_unlock(&visualizer_list_mtx);
    174 
     158       
    175159        return vs;
    176160}
     
    179163{
    180164        renderer_t *rnd = NULL;
    181 
     165       
    182166        fibril_mutex_lock(&renderer_list_mtx);
     167       
    183168        list_foreach(renderer_list, link, renderer_t, rcur) {
    184169                if (rcur->reg_svc_handle == handle) {
     
    187172                }
    188173        }
     174       
    189175        fibril_mutex_unlock(&renderer_list_mtx);
    190 
     176       
    191177        return rnd;
    192178}
     
    194180int graph_unregister_visualizer(visualizer_t *vs)
    195181{
    196         int rc = EOK;
    197 
    198182        fibril_mutex_lock(&visualizer_list_mtx);
    199         rc = loc_service_unregister(vs->reg_svc_handle);
     183        int rc = loc_service_unregister(vs->reg_svc_handle);
    200184        list_remove(&vs->link);
    201185        fibril_mutex_unlock(&visualizer_list_mtx);
    202 
     186       
    203187        return rc;
    204188}
     
    206190int graph_unregister_renderer(renderer_t *rnd)
    207191{
    208         int rc = EOK;
    209 
    210192        fibril_mutex_lock(&renderer_list_mtx);
    211         rc = loc_service_unregister(rnd->reg_svc_handle);
     193        int rc = loc_service_unregister(rnd->reg_svc_handle);
    212194        list_remove(&rnd->link);
    213195        fibril_mutex_unlock(&renderer_list_mtx);
    214 
     196       
    215197        return rc;
    216198}
     
    225207        assert(vs->cells.data == NULL);
    226208        assert(vs->dev_ctx == NULL);
    227 
     209       
    228210        free(vs);
    229211}
     
    233215        // TODO
    234216        assert(atomic_get(&rnd->ref_cnt) == 0);
    235 
     217       
    236218        free(rnd);
    237219}
     
    242224        int ret = async_req_2_0(exch, VISUALIZER_MODE_CHANGE, handle, mode_idx);
    243225        async_exchange_end(exch);
    244 
     226       
    245227        return ret;
    246228}
     
    251233        int ret = async_req_1_0(exch, VISUALIZER_DISCONNECT, handle);
    252234        async_exchange_end(exch);
    253 
     235       
    254236        async_hangup(sess);
    255 
     237       
    256238        return ret;
    257239}
     
    273255                }
    274256        }
    275 
     257       
    276258        /* Driver might also deallocate resources for the current mode. */
    277259        int rc = vs->ops.yield(vs);
    278 
     260       
    279261        /* Now that the driver was given a chance to deallocate resources,
    280262         * current mode can be unset. */
    281         if (vs->mode_set) {
     263        if (vs->mode_set)
    282264                vs->mode_set = false;
    283         }
    284 
     265       
    285266        async_answer_0(iid, rc);
    286267}
     
    288269static void vs_enumerate_modes(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    289270{
     271        ipc_callid_t callid;
     272        size_t len;
     273       
     274        if (!async_data_read_receive(&callid, &len)) {
     275                async_answer_0(callid, EREFUSED);
     276                async_answer_0(iid, EREFUSED);
     277                return;
     278        }
     279       
    290280        fibril_mutex_lock(&vs->mode_mtx);
    291281        link_t *link = list_nth(&vs->modes, IPC_GET_ARG1(*icall));
    292 
     282       
    293283        if (link != NULL) {
    294284                vslmode_list_element_t *mode_elem =
    295285                    list_get_instance(link, vslmode_list_element_t, link);
    296                 vslmode_t mode = mode_elem->mode;
    297                 fibril_mutex_unlock(&vs->mode_mtx);
    298 
    299                 ipc_callid_t callid;
    300                 size_t len;
    301 
    302         if (!async_data_read_receive(&callid, &len)) {
    303                         async_answer_0(iid, EINVAL);
    304                         return;
    305         }
    306         int rc = async_data_read_finalize(callid, &mode, len);
    307                 if (rc != EOK) {
    308                         async_answer_0(iid, ENOMEM);
    309                         return;
    310                 }
    311 
    312                 async_answer_0(iid, EOK);
     286               
     287                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     288                async_answer_0(iid, rc);
    313289        } else {
     290                async_answer_0(callid, ENOENT);
    314291                async_answer_0(iid, ENOENT);
    315292        }
     293       
     294        fibril_mutex_unlock(&vs->mode_mtx);
    316295}
    317296
    318297static void vs_get_default_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    319298{
     299        ipc_callid_t callid;
     300        size_t len;
     301       
     302        if (!async_data_read_receive(&callid, &len)) {
     303                async_answer_0(callid, EREFUSED);
     304                async_answer_0(iid, EREFUSED);
     305                return;
     306        }
     307       
    320308        fibril_mutex_lock(&vs->mode_mtx);
    321309        vslmode_list_element_t *mode_elem = NULL;
     310       
    322311        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    323312                if (cur->mode.index == vs->def_mode_idx) {
     
    326315                }
    327316        }
    328 
    329         vslmode_t mode;
     317       
    330318        if (mode_elem != NULL) {
    331                 mode = mode_elem->mode;
    332                 fibril_mutex_unlock(&vs->mode_mtx);
    333 
    334                 ipc_callid_t callid;
    335                 size_t len;
    336 
    337                 if (!async_data_read_receive(&callid, &len)) {
    338                         async_answer_0(iid, EINVAL);
    339                         return;
    340                 }
    341                 int rc = async_data_read_finalize(callid, &mode, len);
    342                 if (rc != EOK) {
    343                         async_answer_0(iid, ENOMEM);
    344                         return;
    345                 }
    346                 async_answer_0(iid, EOK);
     319                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     320                async_answer_0(iid, rc);
    347321        } else {
    348322                fibril_mutex_unlock(&vs->mode_mtx);
     323                async_answer_0(callid, ENOENT);
    349324                async_answer_0(iid, ENOENT);
    350325        }
     326       
     327        fibril_mutex_unlock(&vs->mode_mtx);
    351328}
    352329
    353330static void vs_get_current_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    354331{
     332        ipc_callid_t callid;
     333        size_t len;
     334       
     335        if (!async_data_read_receive(&callid, &len)) {
     336                async_answer_0(callid, EREFUSED);
     337                async_answer_0(iid, EREFUSED);
     338                return;
     339        }
     340       
    355341        if (vs->mode_set) {
    356                 ipc_callid_t callid;
    357                 size_t len;
    358 
    359                 if (!async_data_read_receive(&callid, &len)) {
    360                         async_answer_0(iid, EINVAL);
    361                         return;
    362                 }
    363342                int rc = async_data_read_finalize(callid, &vs->cur_mode, len);
    364                 if (rc != EOK) {
    365                         async_answer_0(iid, ENOMEM);
    366                         return;
    367                 }
    368 
    369                 async_answer_0(iid, EOK);
     343                async_answer_0(iid, rc);
    370344        } else {
     345                async_answer_0(callid, ENOENT);
    371346                async_answer_0(iid, ENOENT);
    372347        }
     
    375350static void vs_get_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    376351{
     352        ipc_callid_t callid;
     353        size_t len;
     354       
     355        if (!async_data_read_receive(&callid, &len)) {
     356                async_answer_0(callid, EREFUSED);
     357                async_answer_0(iid, EREFUSED);
     358                return;
     359        }
     360       
    377361        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    378 
     362       
    379363        fibril_mutex_lock(&vs->mode_mtx);
    380364        vslmode_list_element_t *mode_elem = NULL;
     365       
    381366        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    382367                if (cur->mode.index == mode_idx) {
     
    385370                }
    386371        }
    387 
    388         vslmode_t mode;
     372       
    389373        if (mode_elem != NULL) {
    390                 mode = mode_elem->mode;
    391                 fibril_mutex_unlock(&vs->mode_mtx);
    392 
    393                 ipc_callid_t callid;
    394                 size_t len;
    395 
    396                 if (!async_data_read_receive(&callid, &len)) {
    397                         async_answer_0(iid, EINVAL);
    398                         return;
    399                 }
    400                 int rc = async_data_read_finalize(callid, &mode, len);
    401                 if (rc != EOK) {
    402                         async_answer_0(iid, ENOMEM);
    403                         return;
    404                 }
    405                 async_answer_0(iid, EOK);
     374                int rc = async_data_read_finalize(callid, &mode_elem->mode, len);
     375                async_answer_0(iid, rc);
    406376        } else {
    407                 fibril_mutex_unlock(&vs->mode_mtx);
     377                async_answer_0(callid, ENOENT);
    408378                async_answer_0(iid, ENOENT);
    409379        }
     380       
     381        fibril_mutex_unlock(&vs->mode_mtx);
    410382}
    411383
    412384static void vs_set_mode(visualizer_t *vs, ipc_callid_t iid, ipc_call_t *icall)
    413385{
    414         int rc = EOK;
    415 
     386        ipc_callid_t callid;
     387        size_t size;
     388        unsigned int flags;
     389       
     390        /* Retrieve the shared cell storage for the new mode. */
     391        if (!async_share_out_receive(&callid, &size, &flags)) {
     392                async_answer_0(callid, EREFUSED);
     393                async_answer_0(iid, EREFUSED);
     394                return;
     395        }
     396       
    416397        /* Retrieve mode index and version. */
    417398        sysarg_t mode_idx = IPC_GET_ARG1(*icall);
    418399        sysarg_t mode_version = IPC_GET_ARG2(*icall);
    419 
     400       
    420401        /* Find mode in the list. */
    421402        fibril_mutex_lock(&vs->mode_mtx);
    422403        vslmode_list_element_t *mode_elem = NULL;
     404       
    423405        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    424406                if (cur->mode.index == mode_idx) {
     
    427409                }
    428410        }
    429 
     411       
     412        if (mode_elem == NULL) {
     413                fibril_mutex_unlock(&vs->mode_mtx);
     414                async_answer_0(callid, ENOENT);
     415                async_answer_0(iid, ENOENT);
     416                return;
     417        }
     418       
    430419        /* Extract mode description from the list node. */
    431         vslmode_t new_mode;
    432         if (mode_elem != NULL) {
    433                 new_mode = mode_elem->mode;
    434                 fibril_mutex_unlock(&vs->mode_mtx);
    435         } else {
    436                 fibril_mutex_unlock(&vs->mode_mtx);
    437                 async_answer_0(iid, ENOENT);
    438                 return;
    439         }
    440 
     420        vslmode_t new_mode = mode_elem->mode;
     421        fibril_mutex_unlock(&vs->mode_mtx);
     422       
    441423        /* Check whether the mode is still up-to-date. */
    442424        if (new_mode.version != mode_version) {
     425                async_answer_0(callid, EINVAL);
    443426                async_answer_0(iid, EINVAL);
    444427                return;
    445428        }
    446 
    447         ipc_callid_t callid;
    448         size_t size;
    449         unsigned int flags;
    450 
    451         /* Retrieve the shared cell storage for the new mode. */
    452         if (!async_share_out_receive(&callid, &size, &flags)) {
    453                 async_answer_0(iid, EINVAL);
    454                 return;
    455         }
     429       
    456430        void *new_cell_storage;
    457         rc = async_share_out_finalize(callid, &new_cell_storage);
     431        int rc = async_share_out_finalize(callid, &new_cell_storage);
    458432        if ((rc != EOK) || (new_cell_storage == AS_MAP_FAILED)) {
    459433                async_answer_0(iid, ENOMEM);
    460434                return;
    461435        }
    462 
     436       
    463437        /* Change device internal state. */
    464438        rc = vs->ops.change_mode(vs, new_mode);
    465 
     439       
    466440        /* Device driver could not establish new mode. Rollback. */
    467441        if (rc != EOK) {
     
    470444                return;
    471445        }
    472 
    473         /* Because resources for the new mode were successfully claimed,
    474          * it is finally possible to free resources allocated for the old mode. */
     446       
     447        /*
     448         * Because resources for the new mode were successfully
     449         * claimed, it is finally possible to free resources
     450         * allocated for the old mode.
     451         */
    475452        if (vs->mode_set) {
    476453                if (vs->cells.data != NULL) {
     
    479456                }
    480457        }
    481 
     458       
    482459        /* Insert new mode into the visualizer. */
    483460        vs->cells.width = new_mode.screen_width;
     
    486463        vs->cur_mode = new_mode;
    487464        vs->mode_set = true;
    488 
     465       
    489466        async_answer_0(iid, EOK);
    490467}
     
    499476        sysarg_t y_offset = (IPC_GET_ARG5(*icall) & 0xffffffff);
    500477#endif
    501 
     478       
    502479        int rc = vs->ops.handle_damage(vs,
    503480            IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall),
    504481            IPC_GET_ARG3(*icall), IPC_GET_ARG4(*icall),
    505                 x_offset, y_offset);
     482            x_offset, y_offset);
    506483        async_answer_0(iid, rc);
    507484}
     
    524501        ipc_call_t call;
    525502        ipc_callid_t callid;
    526 
     503       
    527504        /* Claim the visualizer. */
    528505        if (!cas(&vs->ref_cnt, 0, 1)) {
     
    530507                return;
    531508        }
    532 
     509       
    533510        /* Accept the connection. */
    534511        async_answer_0(iid, EOK);
    535 
     512       
    536513        /* Establish callback session. */
    537514        callid = async_get_call(&call);
    538515        vs->notif_sess = async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
    539         if (vs->notif_sess != NULL) {
     516        if (vs->notif_sess != NULL)
    540517                async_answer_0(callid, EOK);
    541         } else {
     518        else
    542519                async_answer_0(callid, ELIMIT);
    543         }
    544 
     520       
    545521        /* Enter command loop. */
    546522        while (true) {
    547523                callid = async_get_call(&call);
    548 
     524               
    549525                if (!IPC_GET_IMETHOD(call)) {
    550526                        async_answer_0(callid, EINVAL);
    551527                        break;
    552528                }
    553 
     529               
    554530                switch (IPC_GET_IMETHOD(call)) {
    555531                case VISUALIZER_CLAIM:
     
    588564                }
    589565        }
    590 
     566       
    591567terminate:
    592568        async_hangup(vs->notif_sess);
     
    599575{
    600576        // TODO
    601 
     577       
    602578        ipc_call_t call;
    603579        ipc_callid_t callid;
    604 
     580       
    605581        /* Accept the connection. */
    606582        atomic_inc(&rnd->ref_cnt);
    607583        async_answer_0(iid, EOK);
    608 
     584       
    609585        /* Enter command loop. */
    610586        while (true) {
    611587                callid = async_get_call(&call);
    612 
     588               
    613589                if (!IPC_GET_IMETHOD(call)) {
    614590                        async_answer_0(callid, EINVAL);
    615591                        break;
    616592                }
    617 
     593               
    618594                switch (IPC_GET_IMETHOD(call)) {
    619595                default:
     
    622598                }
    623599        }
    624 
     600       
    625601terminate:
    626602        atomic_dec(&rnd->ref_cnt);
     
    632608        visualizer_t *vs = graph_get_visualizer(IPC_GET_ARG1(*icall));
    633609        renderer_t *rnd = graph_get_renderer(IPC_GET_ARG1(*icall));
    634 
    635         if (vs != NULL) {
     610       
     611        if (vs != NULL)
    636612                graph_visualizer_connection(vs, iid, icall, arg);
    637         } else if (rnd != NULL) {
     613        else if (rnd != NULL)
    638614                graph_renderer_connection(rnd, iid, icall, arg);
    639         } else {
     615        else
    640616                async_answer_0(iid, ENOENT);
    641         }
    642617}
    643618
Note: See TracChangeset for help on using the changeset viewer.