Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/synch/syswaitq.c

    r111b9b9 r455241b  
    4848static slab_cache_t *waitq_cache;
    4949
    50 static void waitq_destroy(void *arg)
     50typedef struct {
     51        kobject_t kobject;
     52        waitq_t waitq;
     53} waitq_kobject_t;
     54
     55static void waitq_destroy(kobject_t *arg)
    5156{
    52         waitq_t *wq = (waitq_t *) arg;
     57        waitq_kobject_t *wq = (waitq_kobject_t *) arg;
    5358        slab_free(waitq_cache, wq);
    5459}
    5560
    5661kobject_ops_t waitq_kobject_ops = {
    57         .destroy = waitq_destroy
     62        .destroy = waitq_destroy,
    5863};
    59 
    60 static bool waitq_cap_cleanup_cb(cap_t *cap, void *arg)
    61 {
    62         kobject_t *kobj = cap_unpublish(cap->task, cap->handle,
    63             KOBJECT_TYPE_WAITQ);
    64         kobject_put(kobj);
    65         cap_free(cap->task, cap->handle);
    66         return true;
    67 }
    6864
    6965/** Initialize the user waitq subsystem */
    7066void sys_waitq_init(void)
    7167{
    72         waitq_cache = slab_cache_create("waitq_t", sizeof(waitq_t), 0, NULL,
    73             NULL, 0);
    74 }
    75 
    76 /** Clean-up all waitq capabilities held by the exiting task */
    77 void sys_waitq_task_cleanup(void)
    78 {
    79         caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_WAITQ,
    80             waitq_cap_cleanup_cb, NULL);
     68        waitq_cache = slab_cache_create("syswaitq_t", sizeof(waitq_kobject_t),
     69            0, NULL, NULL, 0);
    8170}
    8271
     
    9079sys_errno_t sys_waitq_create(uspace_ptr_cap_waitq_handle_t whandle)
    9180{
    92         waitq_t *wq = slab_alloc(waitq_cache, FRAME_ATOMIC);
    93         if (!wq)
     81        waitq_kobject_t *kobj = slab_alloc(waitq_cache, FRAME_ATOMIC);
     82        if (!kobj)
    9483                return (sys_errno_t) ENOMEM;
    95         waitq_initialize(wq);
    9684
    97         kobject_t *kobj = kobject_alloc(0);
    98         if (!kobj) {
    99                 slab_free(waitq_cache, wq);
    100                 return (sys_errno_t) ENOMEM;
    101         }
    102         kobject_initialize(kobj, KOBJECT_TYPE_WAITQ, wq);
     85        kobject_initialize(&kobj->kobject, KOBJECT_TYPE_WAITQ);
     86        waitq_initialize(&kobj->waitq);
    10387
    10488        cap_handle_t handle;
    10589        errno_t rc = cap_alloc(TASK, &handle);
    10690        if (rc != EOK) {
    107                 slab_free(waitq_cache, wq);
    108                 kobject_free(kobj);
     91                slab_free(waitq_cache, kobj);
    10992                return (sys_errno_t) rc;
    11093        }
     
    11396        if (rc != EOK) {
    11497                cap_free(TASK, handle);
    115                 kobject_free(kobj);
    116                 slab_free(waitq_cache, wq);
     98                slab_free(waitq_cache, kobj);
    11799                return (sys_errno_t) rc;
    118100        }
    119101
    120         cap_publish(TASK, handle, kobj);
     102        cap_publish(TASK, handle, &kobj->kobject);
    121103
    122104        return (sys_errno_t) EOK;
     
    151133    unsigned int flags)
    152134{
    153         kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
     135        waitq_kobject_t *kobj =
     136            (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
    154137        if (!kobj)
    155138                return (sys_errno_t) ENOENT;
     
    159142#endif
    160143
    161         errno_t rc = _waitq_sleep_timeout(kobj->waitq, timeout,
     144        errno_t rc = _waitq_sleep_timeout(&kobj->waitq, timeout,
    162145            SYNCH_FLAGS_INTERRUPTIBLE | flags);
    163146
     
    166149#endif
    167150
    168         kobject_put(kobj);
     151        kobject_put(&kobj->kobject);
    169152
    170153        return (sys_errno_t) rc;
     
    179162sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t whandle)
    180163{
    181         kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
     164        waitq_kobject_t *kobj =
     165            (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
    182166        if (!kobj)
    183167                return (sys_errno_t) ENOENT;
    184168
    185         waitq_wake_one(kobj->waitq);
     169        waitq_wake_one(&kobj->waitq);
    186170
    187         kobject_put(kobj);
     171        kobject_put(&kobj->kobject);
    188172        return (sys_errno_t) EOK;
    189173}
Note: See TracChangeset for help on using the changeset viewer.