mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-08 00:17:49 +00:00
Added thirdparty: boost library
This commit is contained in:
+33
@@ -0,0 +1,33 @@
|
||||
#ifndef BOOST_LEAF_CONFIG_TLS_HPP_INCLUDED
|
||||
#define BOOST_LEAF_CONFIG_TLS_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#if defined(BOOST_LEAF_TLS_FREERTOS)
|
||||
# include <boost/leaf/config/tls_freertos.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_LEAF_USE_TLS_ARRAY
|
||||
# ifdef BOOST_LEAF_CFG_TLS_INDEX_TYPE
|
||||
# warning "BOOST_LEAF_CFG_TLS_INDEX_TYPE" is ignored if BOOST_LEAF_USE_TLS_ARRAY is not defined.
|
||||
# endif
|
||||
# ifdef BOOST_LEAF_CFG_TLS_ARRAY_SIZE
|
||||
# warning "BOOST_LEAF_CFG_TLS_ARRAY_SIZE" is ignored if BOOST_LEAF_USE_TLS_ARRAY is not defined.
|
||||
# endif
|
||||
# ifdef BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX
|
||||
# warning "BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX" is ignored if BOOST_LEAF_USE_TLS_ARRAY is not defined.
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined BOOST_LEAF_USE_TLS_ARRAY
|
||||
# include <boost/leaf/config/tls_array.hpp>
|
||||
#elif defined(BOOST_LEAF_NO_THREADS)
|
||||
# include <boost/leaf/config/tls_globals.hpp>
|
||||
#else
|
||||
# include <boost/leaf/config/tls_cpp11.hpp>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
#ifndef BOOST_LEAF_CONFIG_TLS_ARRAY_HPP_INCLUDED
|
||||
#define BOOST_LEAF_CONFIG_TLS_ARRAY_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
|
||||
// Copyright (c) 2022 Khalil Estell
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// LEAF requires thread local storage support for pointers and for uin32_t values.
|
||||
|
||||
// This header implements thread local storage for pointers and for unsigned int
|
||||
// values for platforms that support thread local pointers by index.
|
||||
|
||||
namespace boost { namespace leaf {
|
||||
|
||||
namespace tls
|
||||
{
|
||||
// The TLS support defined in this header requires the following two
|
||||
// functions to be defined elsewhere:
|
||||
void * read_void_ptr( int tls_index ) noexcept;
|
||||
void write_void_ptr( int tls_index, void * ) noexcept;
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
#include <limits>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
#ifndef BOOST_LEAF_CFG_TLS_INDEX_TYPE
|
||||
# define BOOST_LEAF_CFG_TLS_INDEX_TYPE unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX
|
||||
# define BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX 0
|
||||
#endif
|
||||
|
||||
static_assert((BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX) >= 0,
|
||||
"Bad BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX");
|
||||
|
||||
#ifdef BOOST_LEAF_CFG_TLS_ARRAY_SIZE
|
||||
static_assert((BOOST_LEAF_CFG_TLS_ARRAY_SIZE) > (BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX),
|
||||
"Bad BOOST_LEAF_CFG_TLS_ARRAY_SIZE");
|
||||
static_assert((BOOST_LEAF_CFG_TLS_ARRAY_SIZE) - 1 <= std::numeric_limits<BOOST_LEAF_CFG_TLS_INDEX_TYPE>::max(),
|
||||
"Bad BOOST_LEAF_CFG_TLS_ARRAY_SIZE");
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
namespace boost { namespace leaf {
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
using atomic_unsigned_int = std::atomic<unsigned int>;
|
||||
}
|
||||
|
||||
namespace tls
|
||||
{
|
||||
template <class=void>
|
||||
class BOOST_LEAF_SYMBOL_VISIBLE index_counter
|
||||
{
|
||||
static int c_;
|
||||
|
||||
public:
|
||||
|
||||
static BOOST_LEAF_CFG_TLS_INDEX_TYPE next()
|
||||
{
|
||||
int idx = ++c_;
|
||||
BOOST_LEAF_ASSERT(idx > (BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX));
|
||||
BOOST_LEAF_ASSERT(idx < (BOOST_LEAF_CFG_TLS_ARRAY_SIZE));
|
||||
return idx;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE tls_index
|
||||
{
|
||||
static BOOST_LEAF_CFG_TLS_INDEX_TYPE idx;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE alloc_tls_index
|
||||
{
|
||||
static BOOST_LEAF_CFG_TLS_INDEX_TYPE const idx;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
int index_counter<T>::c_ = BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX;
|
||||
|
||||
template <class T>
|
||||
BOOST_LEAF_CFG_TLS_INDEX_TYPE tls_index<T>::idx = BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX;
|
||||
|
||||
template <class T>
|
||||
BOOST_LEAF_CFG_TLS_INDEX_TYPE const alloc_tls_index<T>::idx = tls_index<T>::idx = index_counter<>::next();
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
T * read_ptr() noexcept
|
||||
{
|
||||
int tls_idx = tls_index<T>::idx;
|
||||
if( tls_idx == (BOOST_LEAF_CFG_TLS_ARRAY_START_INDEX) )
|
||||
return nullptr;
|
||||
--tls_idx;
|
||||
return reinterpret_cast<T *>(read_void_ptr(tls_idx));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void write_ptr( T * p ) noexcept
|
||||
{
|
||||
int tls_idx = alloc_tls_index<T>::idx;
|
||||
--tls_idx;
|
||||
write_void_ptr(tls_idx, p);
|
||||
BOOST_LEAF_ASSERT(read_void_ptr(tls_idx) == p);
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class Tag>
|
||||
unsigned read_uint() noexcept
|
||||
{
|
||||
static_assert(sizeof(std::intptr_t) >= sizeof(unsigned), "Incompatible tls_array implementation");
|
||||
return (unsigned) (std::intptr_t) (void *) read_ptr<Tag>();
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void write_uint( unsigned x ) noexcept
|
||||
{
|
||||
static_assert(sizeof(std::intptr_t) >= sizeof(unsigned), "Incompatible tls_array implementation");
|
||||
write_ptr<Tag>((Tag *) (void *) (std::intptr_t) x);
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_increment() noexcept
|
||||
{
|
||||
write_uint<Tag>(read_uint<Tag>() + 1);
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_decrement() noexcept
|
||||
{
|
||||
write_uint<Tag>(read_uint<Tag>() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#ifndef BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED
|
||||
#define BOOST_LEAF_CONFIG_TLS_CPP11_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// LEAF requires thread local storage support for pointers and for uin32_t values.
|
||||
|
||||
// This header implements thread local storage for pointers and for unsigned int
|
||||
// values using the C++11 built-in thread_local storage class specifier.
|
||||
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
|
||||
namespace boost { namespace leaf {
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
using atomic_unsigned_int = std::atomic<unsigned int>;
|
||||
}
|
||||
|
||||
namespace tls
|
||||
{
|
||||
template <class T>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE ptr
|
||||
{
|
||||
static thread_local T * p;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
thread_local T * ptr<T>::p;
|
||||
|
||||
template <class T>
|
||||
T * read_ptr() noexcept
|
||||
{
|
||||
return ptr<T>::p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void write_ptr( T * p ) noexcept
|
||||
{
|
||||
ptr<T>::p = p;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class Tag>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE tagged_uint
|
||||
{
|
||||
static thread_local unsigned x;
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
thread_local unsigned tagged_uint<Tag>::x;
|
||||
|
||||
template <class Tag>
|
||||
unsigned read_uint() noexcept
|
||||
{
|
||||
return tagged_uint<Tag>::x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void write_uint( unsigned x ) noexcept
|
||||
{
|
||||
tagged_uint<Tag>::x = x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_increment() noexcept
|
||||
{
|
||||
++tagged_uint<Tag>::x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_decrement() noexcept
|
||||
{
|
||||
--tagged_uint<Tag>::x;
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#ifndef BOOST_LEAF_CONFIG_TLS_FREERTOS_HPP_INCLUDED
|
||||
#define BOOST_LEAF_CONFIG_TLS_FREERTOS_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
|
||||
// Copyright (c) 2022 Khalil Estell
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <task.h>
|
||||
|
||||
#ifndef BOOST_LEAF_USE_TLS_ARRAY
|
||||
# define BOOST_LEAF_USE_TLS_ARRAY
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_LEAF_CFG_TLS_ARRAY_SIZE
|
||||
# define BOOST_LEAF_CFG_TLS_ARRAY_SIZE configNUM_THREAD_LOCAL_STORAGE_POINTERS
|
||||
#endif
|
||||
|
||||
static_assert((BOOST_LEAF_CFG_TLS_ARRAY_SIZE) <= configNUM_THREAD_LOCAL_STORAGE_POINTERS,
|
||||
"Bad BOOST_LEAF_CFG_TLS_ARRAY_SIZE");
|
||||
|
||||
namespace boost { namespace leaf {
|
||||
|
||||
namespace tls
|
||||
{
|
||||
// See https://www.freertos.org/thread-local-storage-pointers.html.
|
||||
|
||||
inline void * read_void_ptr( int tls_index ) noexcept
|
||||
{
|
||||
return pvTaskGetThreadLocalStoragePointer(0, tls_index);
|
||||
}
|
||||
|
||||
inline void write_void_ptr( int tls_index, void * p ) noexcept
|
||||
{
|
||||
vTaskSetThreadLocalStoragePointer(0, tls_index, p);
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
#ifndef BOOST_LEAF_CONFIG_TLS_GLOBALS_HPP_INCLUDED
|
||||
#define BOOST_LEAF_CONFIG_TLS_GLOBALS_HPP_INCLUDED
|
||||
|
||||
// Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// LEAF requires thread local storage support for pointers and for uin32_t values.
|
||||
|
||||
// This header implements "thread local" storage for pointers and for unsigned int
|
||||
// values using globals, which is suitable for single thread environments.
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace boost { namespace leaf {
|
||||
|
||||
namespace leaf_detail
|
||||
{
|
||||
using atomic_unsigned_int = unsigned int;
|
||||
}
|
||||
|
||||
namespace tls
|
||||
{
|
||||
template <class T>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE ptr
|
||||
{
|
||||
static T * p;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
T * ptr<T>::p;
|
||||
|
||||
template <class T>
|
||||
T * read_ptr() noexcept
|
||||
{
|
||||
return ptr<T>::p;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void write_ptr( T * p ) noexcept
|
||||
{
|
||||
ptr<T>::p = p;
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
template <class Tag>
|
||||
struct BOOST_LEAF_SYMBOL_VISIBLE tagged_uint
|
||||
{
|
||||
static unsigned x;
|
||||
};
|
||||
|
||||
template <class Tag>
|
||||
unsigned tagged_uint<Tag>::x;
|
||||
|
||||
template <class Tag>
|
||||
unsigned read_uint() noexcept
|
||||
{
|
||||
return tagged_uint<Tag>::x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void write_uint( unsigned x ) noexcept
|
||||
{
|
||||
tagged_uint<Tag>::x = x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_increment() noexcept
|
||||
{
|
||||
++tagged_uint<Tag>::x;
|
||||
}
|
||||
|
||||
template <class Tag>
|
||||
void uint_decrement() noexcept
|
||||
{
|
||||
--tagged_uint<Tag>::x;
|
||||
}
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user