tls_freertos.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef BOOST_LEAF_CONFIG_TLS_FREERTOS_HPP_INCLUDED
  2. #define BOOST_LEAF_CONFIG_TLS_FREERTOS_HPP_INCLUDED
  3. // Copyright 2018-2023 Emil Dotchevski and Reverge Studios, Inc.
  4. // Copyright (c) 2022 Khalil Estell
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. // LEAF requires thread local storage support for pointers and for uin32_t values.
  8. // This header implements "thread local" storage via FreeTOS functions
  9. // pvTaskGetThreadLocalStoragePointer / pvTaskSetThreadLocalStoragePointer
  10. #include <task.h>
  11. #ifndef BOOST_LEAF_USE_TLS_ARRAY
  12. # define BOOST_LEAF_USE_TLS_ARRAY
  13. #endif
  14. #ifndef BOOST_LEAF_CFG_TLS_ARRAY_SIZE
  15. # define BOOST_LEAF_CFG_TLS_ARRAY_SIZE configNUM_THREAD_LOCAL_STORAGE_POINTERS
  16. #endif
  17. static_assert((BOOST_LEAF_CFG_TLS_ARRAY_SIZE) <= configNUM_THREAD_LOCAL_STORAGE_POINTERS,
  18. "Bad BOOST_LEAF_CFG_TLS_ARRAY_SIZE");
  19. namespace boost { namespace leaf {
  20. namespace tls
  21. {
  22. // See https://www.freertos.org/thread-local-storage-pointers.html.
  23. inline void * read_void_ptr( int tls_index ) noexcept
  24. {
  25. return pvTaskGetThreadLocalStoragePointer(0, tls_index);
  26. }
  27. inline void write_void_ptr( int tls_index, void * p ) noexcept
  28. {
  29. vTaskSetThreadLocalStoragePointer(0, tls_index, p);
  30. }
  31. }
  32. } }
  33. #endif