tls_freertos.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <task.h>
  8. #ifndef BOOST_LEAF_USE_TLS_ARRAY
  9. # define BOOST_LEAF_USE_TLS_ARRAY
  10. #endif
  11. #ifndef BOOST_LEAF_CFG_TLS_ARRAY_SIZE
  12. # define BOOST_LEAF_CFG_TLS_ARRAY_SIZE configNUM_THREAD_LOCAL_STORAGE_POINTERS
  13. #endif
  14. static_assert((BOOST_LEAF_CFG_TLS_ARRAY_SIZE) <= configNUM_THREAD_LOCAL_STORAGE_POINTERS,
  15. "Bad BOOST_LEAF_CFG_TLS_ARRAY_SIZE");
  16. namespace boost { namespace leaf {
  17. namespace tls
  18. {
  19. // See https://www.freertos.org/thread-local-storage-pointers.html.
  20. inline void * read_void_ptr( int tls_index ) noexcept
  21. {
  22. return pvTaskGetThreadLocalStoragePointer(0, tls_index);
  23. }
  24. inline void write_void_ptr( int tls_index, void * p ) noexcept
  25. {
  26. vTaskSetThreadLocalStoragePointer(0, tls_index, p);
  27. }
  28. }
  29. } }
  30. #endif