Changeset c11ee605 in mainline


Ignore:
Timestamp:
2020-05-11T15:36:46Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
83cb672
Parents:
e49b7997
Message:

Display server needs some locking

Sometimes destroying a window would race with event delivery. We add
one big lock for the display object that is taken before servicing
any client request or input event.

Location:
uspace/srv/hid/display
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/display.c

    re49b7997 rc11ee605  
    6565        }
    6666
     67        fibril_mutex_initialize(&disp->lock);
    6768        list_initialize(&disp->clients);
    6869        disp->next_wnd_id = 1;
     
    8485        gfx_color_delete(disp->bg_color);
    8586        free(disp);
     87}
     88
     89/** Lock display.
     90 *
     91 * This should be called in any thread that wishes to access the display
     92 * or its child objects (e.g. windows).
     93 *
     94 * @param disp Display
     95 */
     96void ds_display_lock(ds_display_t *disp)
     97{
     98        fibril_mutex_lock(&disp->lock);
     99}
     100
     101/** Unlock display.
     102 *
     103 * @param disp Display
     104 */
     105void ds_display_unlock(ds_display_t *disp)
     106{
     107        fibril_mutex_unlock(&disp->lock);
    86108}
    87109
  • uspace/srv/hid/display/display.h

    re49b7997 rc11ee605  
    5050extern errno_t ds_display_create(gfx_context_t *, ds_display_t **);
    5151extern void ds_display_destroy(ds_display_t *);
     52extern void ds_display_lock(ds_display_t *);
     53extern void ds_display_unlock(ds_display_t *);
    5254extern void ds_display_get_info(ds_display_t *, display_info_t *);
    5355extern void ds_display_add_client(ds_display_t *, ds_client_t *);
  • uspace/srv/hid/display/dsops.c

    re49b7997 rc11ee605  
    7676        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
    7777
     78        ds_display_lock(client->display);
     79
    7880        rc = ds_window_create(client, params, &wnd);
    7981        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
    80         if (rc != EOK)
     82        if (rc != EOK) {
     83                ds_display_unlock(client->display);
    8184                return rc;
     85        }
    8286
    8387        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
     
    9296        (void) ds_display_paint(wnd->display, NULL);
    9397
     98        ds_display_unlock(client->display);
     99
    94100        *rwnd_id = wnd->id;
    95101        return EOK;
     
    101107        ds_window_t *wnd;
    102108
    103         wnd = ds_client_find_window(client, wnd_id);
    104         if (wnd == NULL)
    105                 return ENOENT;
     109        ds_display_lock(client->display);
     110
     111        wnd = ds_client_find_window(client, wnd_id);
     112        if (wnd == NULL) {
     113                ds_display_unlock(client->display);
     114                return ENOENT;
     115        }
    106116
    107117        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
    108118        ds_client_remove_window(wnd);
    109119        ds_window_destroy(wnd);
     120        ds_display_unlock(client->display);
    110121        return EOK;
    111122}
     
    117128        ds_window_t *wnd;
    118129
    119         wnd = ds_client_find_window(client, wnd_id);
    120         if (wnd == NULL)
    121                 return ENOENT;
     130        ds_display_lock(client->display);
     131
     132        wnd = ds_client_find_window(client, wnd_id);
     133        if (wnd == NULL) {
     134                ds_display_unlock(client->display);
     135                return ENOENT;
     136        }
    122137
    123138        log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_move_req()");
    124139        ds_window_move_req(wnd, pos);
     140        ds_display_unlock(client->display);
    125141        return EOK;
    126142}
     
    131147        ds_window_t *wnd;
    132148
    133         wnd = ds_client_find_window(client, wnd_id);
    134         if (wnd == NULL)
    135                 return ENOENT;
     149        ds_display_lock(client->display);
     150
     151        wnd = ds_client_find_window(client, wnd_id);
     152        if (wnd == NULL) {
     153                ds_display_unlock(client->display);
     154                return ENOENT;
     155        }
    136156
    137157        log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_move()");
    138158        ds_window_move(wnd, pos);
     159        ds_display_unlock(client->display);
    139160        return EOK;
    140161}
     
    146167        ds_window_t *wnd;
    147168
    148         wnd = ds_client_find_window(client, wnd_id);
    149         if (wnd == NULL)
    150                 return ENOENT;
     169        ds_display_lock(client->display);
     170
     171        wnd = ds_client_find_window(client, wnd_id);
     172        if (wnd == NULL) {
     173                ds_display_unlock(client->display);
     174                return ENOENT;
     175        }
    151176
    152177        log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_resize_req()");
    153178        ds_window_resize_req(wnd, rsztype, pos);
     179        ds_display_unlock(client->display);
    154180        return EOK;
    155181}
     
    160186        ds_client_t *client = (ds_client_t *) arg;
    161187        ds_window_t *wnd;
    162 
    163         wnd = ds_client_find_window(client, wnd_id);
    164         if (wnd == NULL)
    165                 return ENOENT;
     188        errno_t rc;
     189
     190        ds_display_lock(client->display);
     191
     192        wnd = ds_client_find_window(client, wnd_id);
     193        if (wnd == NULL) {
     194                ds_display_unlock(client->display);
     195                return ENOENT;
     196        }
    166197
    167198        log_msg(LOG_DEFAULT, LVL_NOTE, "disp_window_resize()");
    168         return ds_window_resize(wnd, offs, nbound);
     199        rc = ds_window_resize(wnd, offs, nbound);
     200        ds_display_unlock(client->display);
     201        return rc;
    169202}
    170203
     
    178211        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
    179212
     213        ds_display_lock(client->display);
     214
    180215        rc = ds_client_get_event(client, &wnd, event);
    181         if (rc != EOK)
     216        if (rc != EOK) {
     217                ds_display_unlock(client->display);
    182218                return rc;
     219        }
    183220
    184221        *wnd_id = wnd->id;
     222        ds_display_unlock(client->display);
    185223        return EOK;
    186224}
     
    192230        log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
    193231
     232        ds_display_lock(client->display);
    194233        ds_display_get_info(client->display, info);
     234        ds_display_unlock(client->display);
    195235        return EOK;
    196236}
  • uspace/srv/hid/display/input.c

    re49b7997 rc11ee605  
    7373        ds_display_t *disp = (ds_display_t *) input->user;
    7474        kbd_event_t event;
     75        errno_t rc;
    7576
    7677        event.type = type;
     
    7980        event.c = c;
    8081
    81         return ds_display_post_kbd_event(disp, &event);
     82        ds_display_lock(disp);
     83        rc = ds_display_post_kbd_event(disp, &event);
     84        ds_display_unlock(disp);
     85        return rc;
    8286}
    8387
     
    8690        ds_display_t *disp = (ds_display_t *) input->user;
    8791        ptd_event_t event;
     92        errno_t rc;
    8893
    8994        event.type = PTD_MOVE;
     
    9196        event.dmove.y = dy;
    9297
    93         return ds_display_post_ptd_event(disp, &event);
     98        ds_display_lock(disp);
     99        rc = ds_display_post_ptd_event(disp, &event);
     100        ds_display_unlock(disp);
     101        return rc;
    94102}
    95103
     
    99107        ds_display_t *disp = (ds_display_t *) input->user;
    100108        ptd_event_t event;
     109        errno_t rc;
    101110
    102111        event.type = PTD_ABS_MOVE;
     
    108117        event.abounds.p1.y = max_y + 1;
    109118
    110         return ds_display_post_ptd_event(disp, &event);
     119        ds_display_lock(disp);
     120        rc = ds_display_post_ptd_event(disp, &event);
     121        ds_display_unlock(disp);
     122        return rc;
    111123}
    112124
     
    115127        ds_display_t *disp = (ds_display_t *) input->user;
    116128        ptd_event_t event;
     129        errno_t rc;
    117130
    118131        event.type = bpress ? PTD_PRESS : PTD_RELEASE;
     
    121134        event.dmove.y = 0;
    122135
    123         return ds_display_post_ptd_event(disp, &event);
     136        ds_display_lock(disp);
     137        rc = ds_display_post_ptd_event(disp, &event);
     138        ds_display_unlock(disp);
     139        return rc;
    124140}
    125141
  • uspace/srv/hid/display/types/display/display.h

    re49b7997 rc11ee605  
    3838
    3939#include <adt/list.h>
     40#include <fibril_synch.h>
    4041#include <gfx/color.h>
    4142#include <gfx/coord.h>
     
    4546/** Display server display */
    4647typedef struct ds_display {
     48        /** Synchronize access to display */
     49        fibril_mutex_t lock;
    4750        /** Clients (of ds_client_t) */
    4851        list_t clients;
Note: See TracChangeset for help on using the changeset viewer.