llvm-capstone/lldb/source/Core/StreamCallback.cpp
Jason Molenda ccd41e55f1 Ran the sources through the compiler with -Wshadow warnings
enabled after we'd found a few bugs that were caused by shadowed
local variables; the most important issue this turned up was
a common mistake of trying to obtain a mutex lock for the scope
of a code block by doing

        Mutex::Locker(m_map_mutex);

This doesn't assign the lock object to a local variable; it is
a temporary that has its dtor called immediately.  Instead,

        Mutex::Locker locker(m_map_mutex);

does what is intended.  For some reason -Wshadow happened to
highlight these as shadowed variables.

I also fixed a few obivous and easy shadowed variable issues
across the code base but there are a couple dozen more that
should be fixed when someone has a free minute.
<rdar://problem/12437585>

llvm-svn: 165269
2012-10-04 22:47:07 +00:00

65 lines
1.7 KiB
C++

//===-- StreamCallback.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include "lldb/lldb-private.h"
#include "lldb/Core/Broadcaster.h"
#include "lldb/Core/Event.h"
#include "lldb/Core/StreamCallback.h"
#include "lldb/Host/Host.h"
using namespace lldb;
using namespace lldb_private;
StreamCallback::StreamCallback (lldb::LogOutputCallback callback, void *baton) :
Stream (0, 4, eByteOrderBig),
m_callback (callback),
m_baton (baton),
m_accumulated_data (),
m_collection_mutex ()
{
}
StreamCallback::~StreamCallback ()
{
}
StreamString &
StreamCallback::FindStreamForThread(lldb::tid_t cur_tid)
{
Mutex::Locker locker(m_collection_mutex);
collection::iterator iter = m_accumulated_data.find (cur_tid);
if (iter == m_accumulated_data.end())
{
std::pair<collection::iterator, bool> ret;
ret = m_accumulated_data.insert(std::pair<lldb::tid_t,StreamString>(cur_tid, StreamString()));
iter = ret.first;
}
return (*iter).second;
}
void
StreamCallback::Flush ()
{
lldb::tid_t cur_tid = Host::GetCurrentThreadID();
StreamString &out_stream = FindStreamForThread(cur_tid);
m_callback (out_stream.GetData(), m_baton);
out_stream.Clear();
}
int
StreamCallback::Write (const void *s, size_t length)
{
lldb::tid_t cur_tid = Host::GetCurrentThreadID();
FindStreamForThread(cur_tid).Write (s, length);
return length;
}