Reference counting.  
More...
|  | 
| #define | REF_MAGIC   0x26CB6E4C | 
|  | Magic value used in debug builds to check for corruption or invalid use of the ref_tstructure.
 | 
|  | 
| #define | DEREF_DEFER(ptr)   __attribute__((cleanup(ref_defer_cleanup))) void* CONCAT(p, __COUNTER__) = (ptr) | 
|  | RAII-style cleanup for scoped references. 
 | 
|  | 
| #define | REF(ptr) | 
|  | Increment reference count. 
 | 
|  | 
| #define | DEREF(ptr) | 
|  | Decrement reference count. 
 | 
|  | 
|  | 
| static void | ref_init (ref_t *ref, void *free) | 
|  | Initialize a reference counter. 
 | 
|  | 
| static void * | ref_inc (void *ptr) | 
|  | Increment reference count. 
 | 
|  | 
| static void | ref_dec (void *ptr) | 
|  | Decrement reference count. 
 | 
|  | 
| static void | ref_defer_cleanup (void **ptr) | 
|  | 
Reference counting. 
◆ DEREF
Value:    ({ \
        ref_dec(ref); \
    })
Reference counting structure.
Decrement reference count. 
Atomically decrements the reference counter. Used to avoid the need for a typecast. The magic number checking makes sure we cant accidentally misuse this.
- Parameters
- 
  
    | ptr | Pointer to the struct containing ref_tas its first member, can beNULL. |  
 
Definition at line 80 of file ref.h.
 
 
◆ DEREF_DEFER
RAII-style cleanup for scoped references. 
Uses GCC's cleanup attribute to automatically call ref_dec when going out of scope.
- Parameters
- 
  
    | ptr | Pointer to the struct containing ref_tas its first member, can beNULL. |  
 
Definition at line 54 of file ref.h.
 
 
◆ REF
Value:    ({ \
        ref_inc(ref); \
        ptr; \
    })
Increment reference count. 
Atomically increments the reference counter. Used to avoid the need for a typecast. The magic number checking makes sure we cant accidentally misuse this.
- Parameters
- 
  
    | ptr | Pointer to the struct containing ref_tas its first member, can beNULL. |  
 
- Returns
- The ptrpassed as input
Definition at line 65 of file ref.h.
 
 
◆ REF_MAGIC
      
        
          | #define REF_MAGIC   0x26CB6E4C | 
      
 
Magic value used in debug builds to check for corruption or invalid use of the ref_t structure. 
Definition at line 19 of file ref.h.
 
 
◆ ref_dec()
  
  | 
        
          | static void ref_dec | ( | void * | ptr | ) |  |  | inlinestatic | 
 
Decrement reference count. 
If count reaches zero it calls the registered cleanup function.
- Parameters
- 
  
    | ptr | Pointer to the struct containing ref_tas its first member, can beNULL. |  
 
Definition at line 127 of file ref.h.
References assert, atomic_fetch_sub_explicit, atomic_thread_fence, ref_t::count, count, ref_t::free, ref_t::magic, memory_order_acquire, memory_order_relaxed, NULL, and REF_MAGIC.
Referenced by init_process_spawn(), and ref_defer_cleanup().
 
 
◆ ref_defer_cleanup()
  
  | 
        
          | static void ref_defer_cleanup | ( | void ** | ptr | ) |  |  | inlinestatic | 
 
 
◆ ref_inc()
  
  | 
        
          | static void * ref_inc | ( | void * | ptr | ) |  |  | inlinestatic | 
 
 
◆ ref_init()
  
  | 
        
          | static void ref_init | ( | ref_t * | ref, |  
          |  |  | void * | free |  
          |  | ) |  |  |  | inlinestatic | 
 
Initialize a reference counter. 
- Parameters
- 
  
    | ref | Pointer to the reference counter structure |  | free | Cleanup function to call when count reaches zero |  
 
Definition at line 92 of file ref.h.
References atomic_init, ref_t::count, free(), ref_t::free, ref_t::magic, and REF_MAGIC.
Referenced by aml_object_new(), dentry_new(), file_new(), inode_new(), local_conn_new(), local_listen_new(), mount_new(), process_init(), shmem_object_new(), socket_new(), and superblock_new().