List of all members | Public Member Functions | Protected Member Functions
casadi::WeakRefSXElem Class Reference

#include <output_sx.hpp>

Detailed Description

Definition at line 51 of file output_sx.hpp.

Inheritance diagram for casadi::WeakRefSXElem:
Inheritance graph
[legend]
Collaboration diagram for casadi::WeakRefSXElem:
Collaboration graph
[legend]

Public Member Functions

 WeakRefSXElem (int dummy=0)
 
 WeakRefSXElem (SharedSXElem shared)
 
SharedSXElem shared () const
 Get a shared (owning) reference. More...
 
bool alive () const
 Check if alive. More...
 
bool shared_if_alive (SharedSXElem &shared) const
 Thread-safe alternative to alive()/shared() More...
 
GenericWeakRefInternal< SharedSXElem, OutputSX > * operator-> ()
 Access functions of the node. More...
 
const GenericWeakRefInternal< SharedSXElem, OutputSX > * operator-> () const
 Const access functions of the node. More...
 
void own (OutputSX *node)
 
void assign (OutputSX *node)
 Assign the node to a node class pointer without reference counting. More...
 
OutputSXget () const
 Get a const pointer to the node. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedSXElem, OutputSX > * weak ()
 Get a weak reference to the object. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Constructor & Destructor Documentation

◆ WeakRefSXElem() [1/2]

casadi::WeakRefSXElem::WeakRefSXElem ( int  dummy = 0)
inline

Definition at line 54 of file output_sx.hpp.

55  }
template class CASADI_EXPORT GenericWeakRef< SharedSXElem, OutputSX >
Definition: output_sx.cpp:35

◆ WeakRefSXElem() [2/2]

casadi::WeakRefSXElem::WeakRefSXElem ( SharedSXElem  shared)
inline

Definition at line 56 of file output_sx.hpp.

57  }
SharedSXElem shared() const
Get a shared (owning) reference.

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedSXElem , OutputSX >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ alive()

bool casadi::GenericWeakRef< SharedSXElem , OutputSX >::alive
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_b1

Definition at line 165 of file generic_shared_impl.hpp.

158  {
159  return !is_null() && (*this)->raw_ != nullptr;
160  }

◆ assign()

void casadi::GenericShared< SharedSXElem , OutputSX >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

Extra doc: https://github.com/casadi/casadi/wiki/L_at

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ count_down()

void casadi::GenericShared< SharedSXElem , OutputSX >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedSXElem , OutputSX >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ debug_repr()

std::string casadi::GenericShared< SharedSXElem , OutputSX >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ get()

Definition at line 99 of file generic_shared_impl.hpp.

115  {
116  return node;
117  }

◆ getCount()

casadi_int casadi::GenericShared< SharedSXElem , OutputSX >::getCount
inherited

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ is_null()

bool casadi::GenericShared< SharedSXElem , OutputSX >::is_null
inherited

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ operator->() [1/2]

Extra doc: https://github.com/casadi/casadi/wiki/L_b2

Definition at line 175 of file generic_shared_impl.hpp.

194  {
195  return static_cast<GenericWeakRefInternal<Shared, Internal>*>(
196  GenericShared<Shared, Internal>::operator->());
197  }

◆ operator->() [2/2]

Extra doc: https://github.com/casadi/casadi/wiki/L_b3

Definition at line 180 of file generic_shared_impl.hpp.

187  {
188  return static_cast<const GenericWeakRefInternal<Shared, Internal>*>(
189  GenericShared<Shared, Internal>::operator->());
190  }

◆ own()

void casadi::GenericShared< SharedSXElem , OutputSX >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ shared()

Extra doc: https://github.com/casadi/casadi/wiki/L_b0

Definition at line 160 of file generic_shared_impl.hpp.

163  {
164  Shared ret;
165  if (alive()) {
166  ret.own((*this)->raw_);
167  }
168  return ret;
169  }

◆ shared_if_alive()

bool casadi::GenericWeakRef< SharedSXElem , OutputSX >::shared_if_alive ( SharedSXElem shared) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29i

Definition at line 170 of file generic_shared_impl.hpp.

172  {
173  if (is_null()) return false;
174 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
175  // Safe access to ...
176  std::lock_guard<std::mutex> lock(*(*this)->mutex_);
177 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
178  if (alive()) {
179  shared.own((*this)->raw_);
180  return true;
181  }
182  return false;
183  }
void own(Internal *node)

◆ swap()

void casadi::GenericShared< SharedSXElem , OutputSX >::swap ( GenericShared< SharedSXElem, OutputSX > &  other)
inherited

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

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