xref: /src/contrib/llvm-project/lldb/source/Target/JITLoaderList.cpp (revision cb14a3fe5122c879eae1fb480ed7ce82a699ddb6)
1cfca06d7SDimitry Andric //===-- JITLoaderList.cpp -------------------------------------------------===//
20cac4ca3SEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60cac4ca3SEd Maste //
70cac4ca3SEd Maste //===----------------------------------------------------------------------===//
80cac4ca3SEd Maste 
90cac4ca3SEd Maste #include "lldb/Target/JITLoader.h"
100cac4ca3SEd Maste #include "lldb/Target/JITLoaderList.h"
1114f1b3e8SDimitry Andric #include "lldb/lldb-private.h"
120cac4ca3SEd Maste 
130cac4ca3SEd Maste using namespace lldb;
140cac4ca3SEd Maste using namespace lldb_private;
150cac4ca3SEd Maste 
JITLoaderList()1614f1b3e8SDimitry Andric JITLoaderList::JITLoaderList() : m_jit_loaders_vec(), m_jit_loaders_mutex() {}
170cac4ca3SEd Maste 
18344a3780SDimitry Andric JITLoaderList::~JITLoaderList() = default;
190cac4ca3SEd Maste 
Append(const JITLoaderSP & jit_loader_sp)2014f1b3e8SDimitry Andric void JITLoaderList::Append(const JITLoaderSP &jit_loader_sp) {
21f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
220cac4ca3SEd Maste   m_jit_loaders_vec.push_back(jit_loader_sp);
230cac4ca3SEd Maste }
240cac4ca3SEd Maste 
Remove(const JITLoaderSP & jit_loader_sp)2514f1b3e8SDimitry Andric void JITLoaderList::Remove(const JITLoaderSP &jit_loader_sp) {
26f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
2799aabd70SDimitry Andric   llvm::erase(m_jit_loaders_vec, jit_loader_sp);
280cac4ca3SEd Maste }
290cac4ca3SEd Maste 
GetSize() const3014f1b3e8SDimitry Andric size_t JITLoaderList::GetSize() const { return m_jit_loaders_vec.size(); }
310cac4ca3SEd Maste 
GetLoaderAtIndex(size_t idx)3214f1b3e8SDimitry Andric JITLoaderSP JITLoaderList::GetLoaderAtIndex(size_t idx) {
33f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
340cac4ca3SEd Maste   return m_jit_loaders_vec[idx];
350cac4ca3SEd Maste }
360cac4ca3SEd Maste 
DidLaunch()3714f1b3e8SDimitry Andric void JITLoaderList::DidLaunch() {
38f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
390cac4ca3SEd Maste   for (auto const &jit_loader : m_jit_loaders_vec)
400cac4ca3SEd Maste     jit_loader->DidLaunch();
410cac4ca3SEd Maste }
420cac4ca3SEd Maste 
DidAttach()4314f1b3e8SDimitry Andric void JITLoaderList::DidAttach() {
44f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
450cac4ca3SEd Maste   for (auto const &jit_loader : m_jit_loaders_vec)
460cac4ca3SEd Maste     jit_loader->DidAttach();
470cac4ca3SEd Maste }
480cac4ca3SEd Maste 
ModulesDidLoad(ModuleList & module_list)4914f1b3e8SDimitry Andric void JITLoaderList::ModulesDidLoad(ModuleList &module_list) {
50f3fbd1c0SDimitry Andric   std::lock_guard<std::recursive_mutex> guard(m_jit_loaders_mutex);
510cac4ca3SEd Maste   for (auto const &jit_loader : m_jit_loaders_vec)
520cac4ca3SEd Maste     jit_loader->ModulesDidLoad(module_list);
530cac4ca3SEd Maste }
54