aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
eigen-macros.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include "macros.hpp"
6
7#ifdef ALIGATOR_EIGEN_CHECK_MALLOC
10#define ALIGATOR_EIGEN_ALLOW_MALLOC(allowed) \
11 ::Eigen::internal::set_is_malloc_allowed(allowed)
16#define ALIGATOR_NOMALLOC_SCOPED \
17 const ::aligator::internal::scoped_nomalloc ___aligator_nomalloc_zone {}
19#define ALIGATOR_NOMALLOC_RESTORE \
20 ALIGATOR_EIGEN_ALLOW_MALLOC(::aligator::internal::get_cached_malloc_status())
21#else
22#define ALIGATOR_EIGEN_ALLOW_MALLOC(allowed)
23#define ALIGATOR_NOMALLOC_SCOPED
24#define ALIGATOR_NOMALLOC_RESTORE
25#endif
26
28#define ALIGATOR_NOMALLOC_BEGIN ALIGATOR_EIGEN_ALLOW_MALLOC(false)
30#define ALIGATOR_NOMALLOC_END ALIGATOR_EIGEN_ALLOW_MALLOC(true)
31
32#ifdef ALIGATOR_EIGEN_CHECK_MALLOC
33namespace aligator::internal {
34thread_local static bool g_cached_malloc_status = true;
35
36inline void set_malloc_status(bool status) { g_cached_malloc_status = status; }
37
38inline void save_malloc_status() {
39 set_malloc_status(
40#ifdef ALIGATOR_EIGEN_CHECK_MALLOC
41 ::Eigen::internal::is_malloc_allowed()
42#else
43 false
44#endif
45 );
46}
47
48inline bool get_cached_malloc_status() { return g_cached_malloc_status; }
49
50struct scoped_nomalloc {
51 scoped_nomalloc(const scoped_nomalloc &) = delete;
52 scoped_nomalloc(scoped_nomalloc &&) = delete;
53 ALIGATOR_INLINE scoped_nomalloc() {
54 save_malloc_status();
56 }
57 // reset to value from before the scope
58 ~scoped_nomalloc() { ALIGATOR_NOMALLOC_RESTORE; }
59};
60
61} // namespace aligator::internal
62#endif
#define ALIGATOR_NOMALLOC_RESTORE
#define ALIGATOR_EIGEN_ALLOW_MALLOC(allowed)
#define ALIGATOR_INLINE
Definition macros.hpp:13