MySQL 8.0.39
Source Code Documentation
net::impl::Callstack< Key, Value > Class Template Reference

callstack of a thread. More...

#include <callstack.h>

Classes

class  Context
 
class  Iterator
 forward-iterator over stack frames. More...
 

Public Types

using value_type = Context *
 
using iterator = Iterator
 
using const_iterator = Iterator
 

Static Public Member Functions

static constexpr Valuecontains (const Key *k)
 check if a callstack contains a pointer already. More...
 
static Iterator begin ()
 begin() iterator More...
 
static Iterator end ()
 end() iterator More...
 

Static Private Attributes

static thread_local Contextstack_top_
 

Detailed Description

template<class Key, class Value = unsigned char>
class net::impl::Callstack< Key, Value >

callstack of a thread.

use-cases:

  • track debuginfo of call chains
  • check if the function calls itself

Each new stackframe links to the previous stackframe and sets itself as stacktop. As callstacks are per-thread, no locking is needed.

Usage

struct Frame {
const char *filename;
int line;
const char *func;
Frame(const char *f, int l, const char *fun):
filename(f), line(l), func(fun) {}
};
void a() {
Frame frame(__FILE__, __LINE__, __func__);
Callstack<Frame>::Context stackframe(&frame);
}
void b() {
// store a frame on the functions stack
Frame frame(__FILE__, __LINE__, __func__);
// link the 'frame' to the callstack
Callstack<Frame>::Context stackframe(&frame);
a();
}
const char * filename
Definition: pfs_example_component_population.cc:67
Template Parameters
Keykey-type
Valuevalue-type to assign to the key

Member Typedef Documentation

◆ const_iterator

template<class Key , class Value = unsigned char>
using net::impl::Callstack< Key, Value >::const_iterator = Iterator

◆ iterator

template<class Key , class Value = unsigned char>
using net::impl::Callstack< Key, Value >::iterator = Iterator

◆ value_type

template<class Key , class Value = unsigned char>
using net::impl::Callstack< Key, Value >::value_type = Context *

Member Function Documentation

◆ begin()

template<class Key , class Value = unsigned char>
static Iterator net::impl::Callstack< Key, Value >::begin ( )
inlinestatic

begin() iterator

◆ contains()

template<class Key , class Value = unsigned char>
static constexpr Value * net::impl::Callstack< Key, Value >::contains ( const Key *  k)
inlinestaticconstexpr

check if a callstack contains a pointer already.

walks the stack from the top the last element and checks if a frames key makes k

Parameters
kkey to search for in the callstack
Returns
stored value if key is found
Return values
nullptrif not found.

◆ end()

template<class Key , class Value = unsigned char>
static Iterator net::impl::Callstack< Key, Value >::end ( )
inlinestatic

end() iterator

Member Data Documentation

◆ stack_top_

template<class Key , class Value >
thread_local Callstack< Key, Value >::Context * net::impl::Callstack< Key, Value >::stack_top_
staticprivate
Initial value:
=
nullptr

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