Ignore:
File:
1 edited

Legend:

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

    r455241b r111b9b9  
    4848static slab_cache_t *waitq_cache;
    4949
    50 typedef struct {
    51         kobject_t kobject;
    52         waitq_t waitq;
    53 } waitq_kobject_t;
    54 
    55 static void waitq_destroy(kobject_t *arg)
     50static void waitq_destroy(void *arg)
    5651{
    57         waitq_kobject_t *wq = (waitq_kobject_t *) arg;
     52        waitq_t *wq = (waitq_t *) arg;
    5853        slab_free(waitq_cache, wq);
    5954}
    6055
    6156kobject_ops_t waitq_kobject_ops = {
    62         .destroy = waitq_destroy,
     57        .destroy = waitq_destroy
    6358};
     59
     60static 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}
    6468
    6569/** Initialize the user waitq subsystem */
    6670void sys_waitq_init(void)
    6771{
    68         waitq_cache = slab_cache_create("syswaitq_t", sizeof(waitq_kobject_t),
    69             0, NULL, NULL, 0);
     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 */
     77void sys_waitq_task_cleanup(void)
     78{
     79        caps_apply_to_kobject_type(TASK, KOBJECT_TYPE_WAITQ,
     80            waitq_cap_cleanup_cb, NULL);
    7081}
    7182
     
    7990sys_errno_t sys_waitq_create(uspace_ptr_cap_waitq_handle_t whandle)
    8091{
    81         waitq_kobject_t *kobj = slab_alloc(waitq_cache, FRAME_ATOMIC);
    82         if (!kobj)
     92        waitq_t *wq = slab_alloc(waitq_cache, FRAME_ATOMIC);
     93        if (!wq)
    8394                return (sys_errno_t) ENOMEM;
     95        waitq_initialize(wq);
    8496
    85         kobject_initialize(&kobj->kobject, KOBJECT_TYPE_WAITQ);
    86         waitq_initialize(&kobj->waitq);
     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);
    87103
    88104        cap_handle_t handle;
    89105        errno_t rc = cap_alloc(TASK, &handle);
    90106        if (rc != EOK) {
    91                 slab_free(waitq_cache, kobj);
     107                slab_free(waitq_cache, wq);
     108                kobject_free(kobj);
    92109                return (sys_errno_t) rc;
    93110        }
     
    96113        if (rc != EOK) {
    97114                cap_free(TASK, handle);
    98                 slab_free(waitq_cache, kobj);
     115                kobject_free(kobj);
     116                slab_free(waitq_cache, wq);
    99117                return (sys_errno_t) rc;
    100118        }
    101119
    102         cap_publish(TASK, handle, &kobj->kobject);
     120        cap_publish(TASK, handle, kobj);
    103121
    104122        return (sys_errno_t) EOK;
     
    133151    unsigned int flags)
    134152{
    135         waitq_kobject_t *kobj =
    136             (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
     153        kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
    137154        if (!kobj)
    138155                return (sys_errno_t) ENOENT;
     
    142159#endif
    143160
    144         errno_t rc = _waitq_sleep_timeout(&kobj->waitq, timeout,
     161        errno_t rc = _waitq_sleep_timeout(kobj->waitq, timeout,
    145162            SYNCH_FLAGS_INTERRUPTIBLE | flags);
    146163
     
    149166#endif
    150167
    151         kobject_put(&kobj->kobject);
     168        kobject_put(kobj);
    152169
    153170        return (sys_errno_t) rc;
     
    162179sys_errno_t sys_waitq_wakeup(cap_waitq_handle_t whandle)
    163180{
    164         waitq_kobject_t *kobj =
    165             (waitq_kobject_t *) kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
     181        kobject_t *kobj = kobject_get(TASK, whandle, KOBJECT_TYPE_WAITQ);
    166182        if (!kobj)
    167183                return (sys_errno_t) ENOENT;
    168184
    169         waitq_wake_one(&kobj->waitq);
     185        waitq_wake_one(kobj->waitq);
    170186
    171         kobject_put(&kobj->kobject);
     187        kobject_put(kobj);
    172188        return (sys_errno_t) EOK;
    173189}
Note: See TracChangeset for help on using the changeset viewer.