Loading...
Searching...
No Matches
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)
T * | as_ptr () const
T & | as_ref () const
T & | operator* () const
T * | operator-> ()
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_t & | refcount ()
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.

: vaddr(internals::VADDR_NULL) {
}
vspace::ZRef
Definition vspace.h:1938
vspace::ZRef::vaddr
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.

: vaddr(vaddr) {
}

## ZRef() [3/3]

template<typename T>

vspace::ZRef< T >::ZRef | ( | void * | ptr | ) |

inline

Definition at line 1968 of file vspace.h.

{
vaddr = internals::allocated_ptr_to_vaddr(ptr);
}
vspace::internals::allocated_ptr_to_vaddr
static vaddr_t allocated_ptr_to_vaddr(void *ptr)
Definition vspace.h:1697

## Member Function Documentation

## alloc()

template<typename T>

internals::vaddr_t vspace::ZRef< T >::alloc | ( |  | ) |

inline static

Definition at line 2004 of file vspace.h.

{
return internals::vmem_alloc(sizeof(RefCounted));
}
vspace::internals::vmem_alloc
vaddr_t vmem_alloc(size_t size)
Definition vspace.cc:854
vspace::ZRef::RefCounted
Definition vspace.h:1940

## as_ptr()

template<typename T>

T * vspace::ZRef< T >::as_ptr | ( |  | ) | const

inline

Definition at line 1971 of file vspace.h.

{
return (T *) to_ptr();
}
vspace::ZRef::to_ptr
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.

{
return *(T *) to_ptr();
}

## cast()

template<typename T>
template<typename U>

ZRef< U > vspace::ZRef< T >::cast | ( |  | ) | const

inline

Definition at line 1987 of file vspace.h.

{
return ZRef<U>(vaddr);
}
vspace::ZRef::ZRef
ZRef()
Definition vspace.h:1958

## free()

template<typename T>

void vspace::ZRef< T >::free | ( |  | ) |

inline

Definition at line 1999 of file vspace.h.

{
as_ptr()->~T(); // explicitly call destructor
internals::vmem_free(vaddr);
vaddr = internals::VADDR_NULL;
}
vspace::internals::vmem_free
void vmem_free(vaddr_t vaddr)
Definition vspace.cc:802
vspace::ZRef::as_ptr
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.

{
return vaddr == internals::VADDR_NULL;
}

## operator bool()

template<typename T>

vspace::ZRef< T >::operator bool | ( |  | ) |

inline

Definition at line 1962 of file vspace.h.

{
return vaddr != internals::VADDR_NULL;
}

## operator*()

template<typename T>

T & vspace::ZRef< T >::operator* | ( |  | ) | const

inline

Definition at line 1977 of file vspace.h.

{
return *(T *) to_ptr();
}

## operator->()

template<typename T>

T * vspace::ZRef< T >::operator-> | ( |  | ) |

inline

Definition at line 1980 of file vspace.h.

{
return (T *) to_ptr();
}

## operator=()

template<typename T>

ZRef< T > & vspace::ZRef< T >::operator= | ( | ZRef< T > | other | ) |

inline

Definition at line 1983 of file vspace.h.

{
vaddr = other.vaddr;
}

## refcount()

template<typename T>

internals::refcount_t & vspace::ZRef< T >::refcount | ( |  | ) |

inline private

Definition at line 1950 of file vspace.h.

{
return ((RefCounted *) (internals::vmem.to_ptr(vaddr)))->rc;
}

## release()

template<typename T>

void vspace::ZRef< T >::release | ( |  | ) |

inline

Definition at line 1993 of file vspace.h.

{
if (refcount().dec(vaddr) == 0) {
as_ref().~T();
internals::vmem_free(vaddr);
}
}
vspace::ZRef::as_ref
T & as_ref() const
Definition vspace.h:1974
vspace::ZRef::refcount
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.

{
refcount().inc(vaddr);
}
vspace::internals::refcount_t::inc
std::ptrdiff_t inc(vaddr_t vaddr)
Definition vspace.h:1666

## to_ptr()

template<typename T>

void * vspace::ZRef< T >::to_ptr | ( |  | ) |

inline private

Definition at line 1953 of file vspace.h.

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

## 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:

- kernel/oswrapper/vspace.h