Improve static singleton memory safety (#316)
* Update GitHub links
* Update samples/api_buffered_tracing/client.cpp
- check if initialized before forcing initialization
* Add lib/common/static_object.*
- template class for creating a static allocation in the binary which has all the properties of a heap allocated singleton but does not trigger leak sanitizers
* Update include/rocprofiler-sdk/internal_threading.h
- document return values
* Update lib/rocprofiler-sdk/internal_threading.cpp
- return codes from rocprofiler_create_callback_thread and rocprofiler_assign_callback_thread
- use common::static_object for thread-pool object
* Update lib/rocprofiler-sdk/agent.cpp
- use common::static_object to store array of strings and their hashes
* Update lib/rocprofiler-sdk/hsa/code_object.cpp
- use common::static_object to store array of strings and their hashes to ensure strings exist until termination
* Update lib/rocprofiler-sdk/registration.cpp
- use common::static_object to store status and client libraries
- update return values for rocprofiler_set_api_table
* Update lib/rocprofiler-sdk/hsa/hsa.cpp
- check registration::get_fini_status() in hsa_api_impl::functor<Idx>(args...)
* Update lib/rocprofiler-sdk/context/context.cpp
- using common::static_object for correlation id map
[ROCm/rocprofiler-sdk commit: 6b374b8e68]
This commit is contained in:
committed by
GitHub
parent
946407623f
commit
1e675fceb5
@@ -25,6 +25,7 @@
|
||||
#include <rocprofiler-sdk/rocprofiler.h>
|
||||
|
||||
#include "lib/common/container/stable_vector.hpp"
|
||||
#include "lib/common/static_object.hpp"
|
||||
#include "lib/common/utility.hpp"
|
||||
#include "lib/rocprofiler-sdk/allocator.hpp"
|
||||
#include "lib/rocprofiler-sdk/buffer.hpp"
|
||||
@@ -32,6 +33,8 @@
|
||||
#include "lib/rocprofiler-sdk/internal_threading.hpp"
|
||||
#include "lib/rocprofiler-sdk/registration.hpp"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
@@ -162,10 +165,10 @@ execute_creation_notifiers(rocprofiler_runtime_library_t libs,
|
||||
// using thread_pool_vec_t = std::vector<std::unique_ptr<thread_pool_t>>;
|
||||
// using task_group_vec_t = std::vector<std::unique_ptr<task_group_t>>;
|
||||
|
||||
auto&
|
||||
auto*&
|
||||
get_thread_pools()
|
||||
{
|
||||
static auto _v = thread_pool_vec_t{};
|
||||
static auto* _v = common::static_object<thread_pool_vec_t>::construct();
|
||||
return _v;
|
||||
}
|
||||
|
||||
@@ -225,12 +228,13 @@ create_callback_thread()
|
||||
notify_pre_internal_thread_create(ROCPROFILER_LIBRARY);
|
||||
|
||||
// this will be index after emplace_back
|
||||
auto idx = get_thread_pools().size();
|
||||
auto idx = CHECK_NOTNULL(get_thread_pools())->size();
|
||||
|
||||
thread_pool_config_t pool_config = {};
|
||||
pool_config.pool_size = 1;
|
||||
|
||||
auto& thr_pool = get_thread_pools().emplace_back(std::make_shared<thread_pool_t>(pool_config));
|
||||
auto& thr_pool = CHECK_NOTNULL(get_thread_pools())
|
||||
->emplace_back(std::make_shared<thread_pool_t>(pool_config));
|
||||
|
||||
if(!get_task_groups()) get_task_groups() = new task_group_vec_t{};
|
||||
|
||||
@@ -272,6 +276,9 @@ rocprofiler_at_internal_thread_create(rocprofiler_internal_thread_library_cb_t p
|
||||
rocprofiler_status_t
|
||||
rocprofiler_create_callback_thread(rocprofiler_callback_thread_t* cb_thread_id)
|
||||
{
|
||||
if(rocprofiler::registration::get_init_status() > 0)
|
||||
return ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED;
|
||||
|
||||
rocprofiler::internal_threading::initialize();
|
||||
|
||||
auto cb_tid = rocprofiler::internal_threading::create_callback_thread();
|
||||
@@ -284,10 +291,13 @@ rocprofiler_create_callback_thread(rocprofiler_callback_thread_t* cb_thread_id)
|
||||
return ROCPROFILER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
rocprofiler_status_t ROCPROFILER_API
|
||||
rocprofiler_status_t
|
||||
rocprofiler_assign_callback_thread(rocprofiler_buffer_id_t buffer_id,
|
||||
rocprofiler_callback_thread_t cb_thread_id)
|
||||
{
|
||||
if(rocprofiler::registration::get_init_status() > 0)
|
||||
return ROCPROFILER_STATUS_ERROR_CONFIGURATION_LOCKED;
|
||||
|
||||
if(!rocprofiler::internal_threading::get_task_groups())
|
||||
return ROCPROFILER_STATUS_ERROR_THREAD_NOT_FOUND;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user