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 1938 of file vspace.h.

Constructor & Destructor Documentation

◆ ZRef() [1/3]

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

Definition at line 1958 of file vspace.h.

1959 }
const vaddr_t VADDR_NULL
Definition: vspace.h:1417
internals::vaddr_t vaddr
Definition: vspace.h:1949

◆ ZRef() [2/3]

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

Definition at line 1960 of file vspace.h.

1960 : vaddr(vaddr) {
1961 }

◆ ZRef() [3/3]

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

Definition at line 1968 of file vspace.h.

1968 {
1970 }
static vaddr_t allocated_ptr_to_vaddr(void *ptr)
Definition: vspace.h:1697

Member Function Documentation

◆ alloc()

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

Definition at line 2004 of file vspace.h.

2004 {
2005 return internals::vmem_alloc(sizeof(RefCounted));
2006 }
vaddr_t vmem_alloc(size_t size)
Definition: vspace.cc:808

◆ as_ptr()

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

Definition at line 1971 of file vspace.h.

1971 {
1972 return (T *) to_ptr();
1973 }
STATIC_VAR jList * T
Definition: janet.cc:30
void * to_ptr()
Definition: vspace.h:1953

◆ as_ref()

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

Definition at line 1974 of file vspace.h.

1974 {
1975 return *(T *) to_ptr();
1976 }

◆ cast()

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

Definition at line 1987 of file vspace.h.

1987 {
1988 return ZRef<U>(vaddr);
1989 }

◆ free()

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

Definition at line 1999 of file vspace.h.

1999 {
2000 as_ptr()->~T(); // explicitly call destructor
2003 }
void vmem_free(vaddr_t vaddr)
Definition: vspace.cc:756
T * as_ptr() const
Definition: vspace.h:1971

◆ is_null()

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

Definition at line 1965 of file vspace.h.

1965 {
1966 return vaddr == internals::VADDR_NULL;
1967 }

◆ operator bool()

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

Definition at line 1962 of file vspace.h.

1962 {
1963 return vaddr != internals::VADDR_NULL;
1964 }

◆ operator*()

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

Definition at line 1977 of file vspace.h.

1977 {
1978 return *(T *) to_ptr();
1979 }

◆ operator->()

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

Definition at line 1980 of file vspace.h.

1980 {
1981 return (T *) to_ptr();
1982 }

◆ operator=()

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

Definition at line 1983 of file vspace.h.

1983 {
1984 vaddr = other.vaddr;
1985 }

◆ refcount()

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

Definition at line 1950 of file vspace.h.

1950 {
1951 return ((RefCounted *) (internals::vmem.to_ptr(vaddr)))->rc;
1952 }
static VMem & vmem
Definition: vspace.h:1635

◆ release()

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

Definition at line 1993 of file vspace.h.

1993 {
1994 if (refcount().dec(vaddr) == 0) {
1995 as_ref().~T();
1997 }
1998 }
T & as_ref() const
Definition: vspace.h:1974
internals::refcount_t & refcount()
Definition: vspace.h:1950

◆ retain()

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

Definition at line 1990 of file vspace.h.

1990 {
1991 refcount().inc(vaddr);
1992 }
std::ptrdiff_t inc(vaddr_t vaddr)
Definition: vspace.h:1666

◆ to_ptr()

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

Definition at line 1953 of file vspace.h.

1953 {
1954 return &(((RefCounted *) (internals::vmem.to_ptr(vaddr)))->data);
1955 }

Field Documentation

◆ vaddr

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

Definition at line 1949 of file vspace.h.


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