Ignore:
Timestamp:
2018-08-11T02:43:32Z (7 years ago)
Author:
Jiří Zárevúcky <jiri.zarevucky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
05882233
Parents:
b13d80b
git-author:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-11 02:29:02)
git-committer:
Jiří Zárevúcky <jiri.zarevucky@…> (2018-08-11 02:43:32)
Message:

Unify reference counting and remove some unnecessary instances of <atomic.h>

File:
1 edited

Legend:

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

    rb13d80b r498ced1  
    3333 */
    3434
     35#include <assert.h>
    3536#include <stddef.h>
    3637#include <stdint.h>
     
    4647#include <stdlib.h>
    4748
    48 #include <atomic.h>
     49#include <refcount.h>
    4950#include <fibril_synch.h>
    5051#include <adt/prodcons.h>
     
    9394typedef struct {
    9495        link_t link;
    95         atomic_t ref_cnt;
     96        atomic_refcount_t ref_cnt;
    9697        window_flags_t flags;
    9798        service_id_t in_dsid;
     
    223224
    224225        link_initialize(&win->link);
    225         atomic_set(&win->ref_cnt, 0);
     226        refcount_init(&win->ref_cnt);
    226227        prodcons_initialize(&win->queue);
    227228        transform_identity(&win->transform);
     
    240241static void window_destroy(window_t *win)
    241242{
    242         if ((win) && (atomic_get(&win->ref_cnt) == 0)) {
    243                 while (!list_empty(&win->queue.list)) {
    244                         window_event_t *event = (window_event_t *) list_first(&win->queue.list);
    245                         list_remove(&event->link);
    246                         free(event);
    247                 }
    248 
    249                 if (win->surface)
    250                         surface_destroy(win->surface);
    251 
    252                 free(win);
    253         }
     243        if (!win || !refcount_down(&win->ref_cnt))
     244                return;
     245
     246        while (!list_empty(&win->queue.list)) {
     247                window_event_t *event = (window_event_t *) list_first(&win->queue.list);
     248                list_remove(&event->link);
     249                free(event);
     250        }
     251
     252        if (win->surface)
     253                surface_destroy(win->surface);
     254
     255        free(win);
    254256}
    255257
     
    988990                }
    989991        }
     992
     993        if (win)
     994                refcount_up(&win->ref_cnt);
     995
    990996        fibril_mutex_unlock(&window_list_mtx);
    991997
    992998        if (win) {
    993                 atomic_inc(&win->ref_cnt);
    994999                async_answer_0(icall, EOK);
    9951000        } else {
     
    10051010                        if (!IPC_GET_IMETHOD(call)) {
    10061011                                async_answer_0(&call, EOK);
    1007                                 atomic_dec(&win->ref_cnt);
    10081012                                window_destroy(win);
    10091013                                return;
     
    10241028                        if (!IPC_GET_IMETHOD(call)) {
    10251029                                comp_window_close(win, &call);
    1026                                 atomic_dec(&win->ref_cnt);
    10271030                                window_destroy(win);
    10281031                                return;
Note: See TracChangeset for help on using the changeset viewer.