1//===-- InputReaderStack.cpp ------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Core/InputReaderStack.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16
17
18using namespace lldb;
19using namespace lldb_private;
20
21InputReaderStack::InputReaderStack () :
22    m_input_readers (),
23    m_input_readers_mutex (Mutex::eMutexTypeRecursive)
24{
25}
26
27InputReaderStack::~InputReaderStack ()
28{
29}
30
31size_t
32InputReaderStack::GetSize () const
33{
34    Mutex::Locker locker (m_input_readers_mutex);
35    return m_input_readers.size();
36}
37
38void
39InputReaderStack::Push (const lldb::InputReaderSP& reader_sp)
40{
41    if (reader_sp)
42    {
43        Mutex::Locker locker (m_input_readers_mutex);
44        m_input_readers.push (reader_sp);
45    }
46}
47
48bool
49InputReaderStack::IsEmpty () const
50{
51    Mutex::Locker locker (m_input_readers_mutex);
52    return m_input_readers.empty();
53}
54
55InputReaderSP
56InputReaderStack::Top ()
57{
58    InputReaderSP input_reader_sp;
59    {
60        Mutex::Locker locker (m_input_readers_mutex);
61        if (!m_input_readers.empty())
62            input_reader_sp = m_input_readers.top();
63    }
64
65    return input_reader_sp;
66}
67
68void
69InputReaderStack::Pop ()
70{
71    Mutex::Locker locker (m_input_readers_mutex);
72    if (!m_input_readers.empty())
73        m_input_readers.pop();
74}
75
76Mutex &
77InputReaderStack::GetStackMutex ()
78{
79    return m_input_readers_mutex;
80}
81