GCSIM
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
thread_local_stack Class Referencefinal

local memory of a thread. More...

#include <thread-local-stack.hpp>

Public Member Functions

 thread_local_stack ()
 creates the instance of the thread_local_stack.
 
 thread_local_stack (size_t hash_map_capacity)
 creates the instance of the thread_local_stack.
 
 ~thread_local_stack ()
 deletes the thread_local_stack.
 
 thread_local_stack (const thread_local_stack &)=delete
 deleted copy constructor.
 
thread_local_stackoperator= (const thread_local_stack &)=delete
 deleted assignment operator.
 
 thread_local_stack (thread_local_stack &&other) noexcept
 constructs the thread_local_stack instance from an existing one.
 
thread_local_stackoperator= (thread_local_stack &&other) noexcept
 constructs new thread_local_stack by assigning it an existing one.
 
void init (std::string variable_name, header *heap_ptr=nullptr)
 initializes new variable.
 
void reassign_ref (const std::string &variable_name, header *new_ref_to)
 assigns new value to a variable.
 
void remove_ref (const std::string &variable_name)
 removes the reference to a value on the heap.
 
void push_scope () noexcept
 simulates entering new scope.
 
void pop_scope (bool destr=false)
 simulates exiting scope.
 
virtual void accept (gc_visitor &visitor) noexcept override
 accepts the gc visitor.
 
- Public Member Functions inherited from root_set_base
virtual ~root_set_base ()=default
 deletes the root_set_base object.
 

Private Member Functions

indexed_stack< thread_local_stack_entry > & get_thread_stack_unlocked () noexcept
 getter for the thread_stack.
 

Private Attributes

std::mutex tls_mutex
 used for tls synchronization.
 
size_t scope
 id of the last pushed scope.
 
indexed_stack< thread_local_stack_entrythread_stack
 stack of initialized variables.
 
hash_map< std::string, size_t > var_to_idx
 mapping the variable name to its index inside of the thread_stack.
 

Friends

class garbage_collector
 allowing gc to access getter for the variable.
 

Detailed Description

local memory of a thread.

Constructor & Destructor Documentation

◆ thread_local_stack() [1/4]

thread_local_stack::thread_local_stack ( )

creates the instance of the thread_local_stack.

scope defaults to 1.

◆ thread_local_stack() [2/4]

thread_local_stack::thread_local_stack ( size_t  hash_map_capacity)

creates the instance of the thread_local_stack.

Parameters
hash_map_capacity- number of buckets in the hash_map.

scope defaults to 1.

◆ ~thread_local_stack()

thread_local_stack::~thread_local_stack ( )

deletes the thread_local_stack.

frees final scope if not freed manually.

◆ thread_local_stack() [3/4]

thread_local_stack::thread_local_stack ( const thread_local_stack )
delete

deleted copy constructor.

◆ thread_local_stack() [4/4]

thread_local_stack::thread_local_stack ( thread_local_stack &&  other)
noexcept

constructs the thread_local_stack instance from an existing one.

Parameters
other- rvalue of the existing thread_local_stack.

moves the ownership of the scope, thread_stack and var_to_idx map from other to this.

Member Function Documentation

◆ accept()

void thread_local_stack::accept ( gc_visitor visitor)
overridevirtualnoexcept

accepts the gc visitor.

Parameters
visitor- reference to a gc visitor. Calls marking on the gc visitor for thread-local elements.

Implements root_set_base.

◆ get_thread_stack_unlocked()

indexed_stack< thread_local_stack_entry > & thread_local_stack::get_thread_stack_unlocked ( )
privatenoexcept

getter for the thread_stack.

Warning
must be called when lock is held already.
Returns
reference to thread_stack.

◆ init()

void thread_local_stack::init ( std::string  variable_name,
header heap_ptr = nullptr 
)

initializes new variable.

Parameters
variable_name- name of the variable.
heap_ptr- pointer to the value of the variable on the heap.
Exceptions
std::invalid_argumentwhen variable already exists.

◆ operator=() [1/2]

thread_local_stack & thread_local_stack::operator= ( const thread_local_stack )
delete

deleted assignment operator.

◆ operator=() [2/2]

thread_local_stack & thread_local_stack::operator= ( thread_local_stack &&  other)
noexcept

constructs new thread_local_stack by assigning it an existing one.

Parameters
other- rvalue of the existing thread_local_stack.

moves the ownership of the scope, thread_stack and var_to_idx map from other to this.

◆ pop_scope()

void thread_local_stack::pop_scope ( bool  destr = false)

simulates exiting scope.

Parameters
destr- flag if pop_scope is called by destructor, defaults to false.
Note
simulation purposes.

◆ push_scope()

void thread_local_stack::push_scope ( )
noexcept

simulates entering new scope.

Note
simulation purposes.

◆ reassign_ref()

void thread_local_stack::reassign_ref ( const std::string &  variable_name,
header new_ref_to 
)

assigns new value to a variable.

Parameters
variable_name- name of the variable.
new_ref_to- pointer to a new value on the heap.
Exceptions
std::invalid_argumentwhen variable_name is not previously initialized.

◆ remove_ref()

void thread_local_stack::remove_ref ( const std::string &  variable_name)

removes the reference to a value on the heap.

Parameters
variable_name- name of the variable.
Exceptions
std::invalid_argumentwhen variable_name is not previously initialized.

Friends And Related Symbol Documentation

◆ garbage_collector

friend class garbage_collector
friend

allowing gc to access getter for the variable.

Member Data Documentation

◆ scope

size_t thread_local_stack::scope
private

id of the last pushed scope.

◆ thread_stack

indexed_stack<thread_local_stack_entry> thread_local_stack::thread_stack
private

stack of initialized variables.

◆ tls_mutex

std::mutex thread_local_stack::tls_mutex
mutableprivate

used for tls synchronization.

◆ var_to_idx

hash_map<std::string, size_t> thread_local_stack::var_to_idx
private

mapping the variable name to its index inside of the thread_stack.


The documentation for this class was generated from the following files: