1  
//
1  
//
2  
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/cppalliance/capy
7  
// Official repository: https://github.com/cppalliance/capy
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_CAPY_FRAME_ALLOCATOR_HPP
10  
#ifndef BOOST_CAPY_FRAME_ALLOCATOR_HPP
11  
#define BOOST_CAPY_FRAME_ALLOCATOR_HPP
11  
#define BOOST_CAPY_FRAME_ALLOCATOR_HPP
12  

12  

13  
#include <boost/capy/detail/config.hpp>
13  
#include <boost/capy/detail/config.hpp>
14  
#include <boost/capy/detail/frame_memory_resource.hpp>
14  
#include <boost/capy/detail/frame_memory_resource.hpp>
15  

15  

16  
#include <memory_resource>
16  
#include <memory_resource>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace capy {
19  
namespace capy {
20  

20  

21  
/** Thread-local storage for the current frame allocator.
21  
/** Thread-local storage for the current frame allocator.
22  

22  

23  
    This function returns a reference to the thread-local pointer
23  
    This function returns a reference to the thread-local pointer
24  
    that holds the current memory_resource for frame allocation.
24  
    that holds the current memory_resource for frame allocation.
25  
    The pointer is set by run_async before creating any tasks.
25  
    The pointer is set by run_async before creating any tasks.
26  

26  

27  
    @return Reference to the thread-local memory_resource pointer.
27  
    @return Reference to the thread-local memory_resource pointer.
28  
*/
28  
*/
29  
inline std::pmr::memory_resource*&
29  
inline std::pmr::memory_resource*&
30  
current_frame_allocator() noexcept
30  
current_frame_allocator() noexcept
31  
{
31  
{
32  
    static thread_local std::pmr::memory_resource* mr = nullptr;
32  
    static thread_local std::pmr::memory_resource* mr = nullptr;
33  
    return mr;
33  
    return mr;
34  
}
34  
}
35  

35  

36  
// For backward compatibility
36  
// For backward compatibility
37  
using detail::frame_memory_resource;
37  
using detail::frame_memory_resource;
38  

38  

39  
} // namespace capy
39  
} // namespace capy
40  
} // namespace boost
40  
} // namespace boost
41  

41  

42  
#endif
42  
#endif