LLDB mainline
Iterable.h
Go to the documentation of this file.
1//===-- Iterable.h ----------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_UTILITY_ITERABLE_H
10#define LLDB_UTILITY_ITERABLE_H
11
12#include <utility>
13
14#include <llvm/ADT/iterator.h>
15
16namespace lldb_private {
17
18template <typename WrappedIteratorT,
19 typename T = typename std::iterator_traits<
20 WrappedIteratorT>::value_type::second_type>
22 : llvm::iterator_adaptor_base<
23 ValueMapIterator<WrappedIteratorT, T>, WrappedIteratorT,
24 typename std::iterator_traits<WrappedIteratorT>::iterator_category,
25 T> {
26 ValueMapIterator() = default;
27 explicit ValueMapIterator(WrappedIteratorT u)
28 : ValueMapIterator::iterator_adaptor_base(std::move(u)) {}
29
30 const T &operator*() { return (*this->I).second; }
31 const T &operator*() const { return (*this->I).second; }
32};
33
34template <typename MutexType, typename C,
35 typename IteratorT = typename C::const_iterator>
36class LockingAdaptedIterable : public llvm::iterator_range<IteratorT> {
37public:
38 LockingAdaptedIterable(const C &container, MutexType &mutex)
39 : llvm::iterator_range<IteratorT>(container), m_mutex(&mutex) {
40 m_mutex->lock();
41 }
42
44 : llvm::iterator_range<IteratorT>(rhs), m_mutex(rhs.m_mutex) {
45 rhs.m_mutex = nullptr;
46 }
47
49 if (m_mutex)
50 m_mutex->unlock();
51 }
52
53private:
54 MutexType *m_mutex = nullptr;
55
58};
59
60} // namespace lldb_private
61
62#endif // LLDB_UTILITY_ITERABLE_H
LockingAdaptedIterable(LockingAdaptedIterable &&rhs)
Definition Iterable.h:43
LockingAdaptedIterable & operator=(const LockingAdaptedIterable &)=delete
LockingAdaptedIterable(const C &container, MutexType &mutex)
Definition Iterable.h:38
LockingAdaptedIterable(const LockingAdaptedIterable &)=delete
A class that represents a running process on the host machine.
ValueMapIterator(WrappedIteratorT u)
Definition Iterable.h:27
const T & operator*() const
Definition Iterable.h:31