My Project
Data Structures | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
vspace::ZRef< T > Struct Template Reference

#include <vspace.h>

Data Structures

struct  RefCounted
 

Public Member Functions

 ZRef ()
 
 ZRef (internals::vaddr_t vaddr)
 
 operator bool ()
 
bool is_null ()
 
 ZRef (void *ptr)
 
Tas_ptr () const
 
Tas_ref () const
 
Toperator* () const
 
Toperator-> ()
 
ZRef< T > & operator= (ZRef< T > other)
 
template<typename U >
ZRef< U > cast () const
 
void retain ()
 
void release ()
 
void free ()
 

Static Public Member Functions

static internals::vaddr_t alloc ()
 

Private Member Functions

internals::refcount_trefcount ()
 
void * to_ptr ()
 

Private Attributes

internals::vaddr_t vaddr
 

Detailed Description

template<typename T>
struct vspace::ZRef< T >

Definition at line 603 of file vspace.h.

Constructor & Destructor Documentation

◆ ZRef() [1/3]

template<typename T >
vspace::ZRef< T >::ZRef ( )
inline

Definition at line 623 of file vspace.h.

624  }
const vaddr_t VADDR_NULL
Definition: vspace.h:84
internals::vaddr_t vaddr
Definition: vspace.h:614

◆ ZRef() [2/3]

template<typename T >
vspace::ZRef< T >::ZRef ( internals::vaddr_t  vaddr)
inline

Definition at line 625 of file vspace.h.

625  : vaddr(vaddr) {
626  }

◆ ZRef() [3/3]

template<typename T >
vspace::ZRef< T >::ZRef ( void *  ptr)
inline

Definition at line 633 of file vspace.h.

633  {
635  }
static vaddr_t allocated_ptr_to_vaddr(void *ptr)
Definition: vspace.h:362

Member Function Documentation

◆ alloc()

template<typename T >
static internals::vaddr_t vspace::ZRef< T >::alloc ( )
inlinestatic

Definition at line 669 of file vspace.h.

669  {
670  return internals::vmem_alloc(sizeof(RefCounted));
671  }
vaddr_t vmem_alloc(size_t size)
Definition: vspace.cc:243

◆ as_ptr()

template<typename T >
T* vspace::ZRef< T >::as_ptr ( ) const
inline

Definition at line 636 of file vspace.h.

636  {
637  return (T *) to_ptr();
638  }
STATIC_VAR jList * T
Definition: janet.cc:30
void * to_ptr()
Definition: vspace.h:618

◆ as_ref()

template<typename T >
T& vspace::ZRef< T >::as_ref ( ) const
inline

Definition at line 639 of file vspace.h.

639  {
640  return *(T *) to_ptr();
641  }

◆ cast()

template<typename T >
template<typename U >
ZRef<U> vspace::ZRef< T >::cast ( ) const
inline

Definition at line 652 of file vspace.h.

652  {
653  return ZRef<U>(vaddr);
654  }

◆ free()

template<typename T >
void vspace::ZRef< T >::free ( )
inline

Definition at line 664 of file vspace.h.

664  {
665  as_ptr()->~T(); // explicitly call destructor
668  }
void vmem_free(vaddr_t vaddr)
Definition: vspace.cc:195
T * as_ptr() const
Definition: vspace.h:636

◆ is_null()

template<typename T >
bool vspace::ZRef< T >::is_null ( )
inline

Definition at line 630 of file vspace.h.

630  {
631  return vaddr == internals::VADDR_NULL;
632  }

◆ operator bool()

template<typename T >
vspace::ZRef< T >::operator bool ( )
inline

Definition at line 627 of file vspace.h.

627  {
628  return vaddr != internals::VADDR_NULL;
629  }

◆ operator*()

template<typename T >
T& vspace::ZRef< T >::operator* ( ) const
inline

Definition at line 642 of file vspace.h.

642  {
643  return *(T *) to_ptr();
644  }

◆ operator->()

template<typename T >
T* vspace::ZRef< T >::operator-> ( )
inline

Definition at line 645 of file vspace.h.

645  {
646  return (T *) to_ptr();
647  }

◆ operator=()

template<typename T >
ZRef<T>& vspace::ZRef< T >::operator= ( ZRef< T other)
inline

Definition at line 648 of file vspace.h.

648  {
649  vaddr = other.vaddr;
650  }

◆ refcount()

template<typename T >
internals::refcount_t& vspace::ZRef< T >::refcount ( )
inlineprivate

Definition at line 615 of file vspace.h.

615  {
616  return ((RefCounted *) (internals::vmem.to_ptr(vaddr)))->rc;
617  }
static VMem & vmem
Definition: vspace.h:300

◆ release()

template<typename T >
void vspace::ZRef< T >::release ( )
inline

Definition at line 658 of file vspace.h.

658  {
659  if (refcount().dec(vaddr) == 0) {
660  as_ref().~T();
662  }
663  }
T & as_ref() const
Definition: vspace.h:639
internals::refcount_t & refcount()
Definition: vspace.h:615

◆ retain()

template<typename T >
void vspace::ZRef< T >::retain ( )
inline

Definition at line 655 of file vspace.h.

655  {
656  refcount().inc(vaddr);
657  }
ptrdiff_t inc(vaddr_t vaddr)
Definition: vspace.h:331

◆ to_ptr()

template<typename T >
void* vspace::ZRef< T >::to_ptr ( )
inlineprivate

Definition at line 618 of file vspace.h.

618  {
619  return &(((RefCounted *) (internals::vmem.to_ptr(vaddr)))->data);
620  }

Field Documentation

◆ vaddr

template<typename T >
internals::vaddr_t vspace::ZRef< T >::vaddr
private

Definition at line 614 of file vspace.h.


The documentation for this struct was generated from the following file: