Changeset 96368f56 in mainline


Ignore:
Timestamp:
2025-01-16T13:33:58Z (32 hours ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
fa3ed5b
Parents:
e0e2264
Message:

Use <lib/refcount.h> for kobject reference counting

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/cap/cap.h

    re0e2264 r96368f56  
    3737
    3838#include <abi/cap.h>
     39#include <adt/hash_table.h>
     40#include <adt/hash.h>
     41#include <adt/list.h>
     42#include <atomic.h>
     43#include <lib/ra.h>
     44#include <lib/refcount.h>
     45#include <synch/mutex.h>
    3946#include <typedefs.h>
    40 #include <adt/list.h>
    41 #include <adt/hash.h>
    42 #include <adt/hash_table.h>
    43 #include <lib/ra.h>
    44 #include <synch/mutex.h>
    45 #include <atomic.h>
    4647
    4748typedef enum {
     
    8081typedef struct kobject {
    8182        kobject_type_t type;
    82         atomic_size_t refcnt;
     83        atomic_refcount_t refcnt;
    8384
    8485        /** Mutex protecting caps_list */
  • kernel/generic/src/cap/cap.c

    re0e2264 r96368f56  
    426426void kobject_initialize(kobject_t *kobj, kobject_type_t type, void *raw)
    427427{
    428         atomic_store(&kobj->refcnt, 1);
     428        refcount_init(&kobj->refcnt);
    429429
    430430        mutex_initialize(&kobj->caps_list_lock, MUTEX_PASSIVE);
     
    455455                if (cap->kobject->type == type) {
    456456                        kobj = cap->kobject;
    457                         atomic_inc(&kobj->refcnt);
     457                        refcount_up(&kobj->refcnt);
    458458                }
    459459        }
     
    469469void kobject_add_ref(kobject_t *kobj)
    470470{
    471         atomic_inc(&kobj->refcnt);
     471        refcount_up(&kobj->refcnt);
    472472}
    473473
     
    481481void kobject_put(kobject_t *kobj)
    482482{
    483         if (atomic_postdec(&kobj->refcnt) == 1) {
     483        if (refcount_down(&kobj->refcnt)) {
    484484                KOBJECT_OP(kobj)->destroy(kobj->raw);
    485485                kobject_free(kobj);
Note: See TracChangeset for help on using the changeset viewer.