提交 cc7fa71b 编写于 作者: J Jesse Zhang

Make CMemo::OsPrint const by fixing CSyncList.

While working on extracting a common implementation of DbgPrint() into a
mixin (commit forthcoming), I ran into the curious phenomenon that is
the non-const CMemo::OsPrint. I almost dropped the requirement that
DbgPrint requires "OsPrint() const", before realizing that the root
cause is CSyncList has non-const Next() and friends. And that could be
easily fixed. Make it so.

While we're at it, also fixed a fairly obvious omission in
CMemo::OsPrint where the output stream parameter was unused. We output
to an unrelated "auto" stream instead. This was probably never noticed
because we were relying on the assumption that streams are always
connected to standard output.
上级 0158b5ce
......@@ -157,7 +157,7 @@ public:
void ResetStats();
// print driver
IOstream &OsPrint(IOstream &os);
IOstream &OsPrint(IOstream &os) const;
// derive stats when no stats not present for the group
void DeriveStatsIfAbsent(CMemoryPool *mp);
......
......@@ -621,20 +621,18 @@ CMemo::Trace()
//
//---------------------------------------------------------------------------
IOstream &
CMemo::OsPrint(IOstream &os)
CMemo::OsPrint(IOstream &os) const
{
CGroup *pgroup = m_listGroups.PtFirst();
while (NULL != pgroup)
{
CAutoTrace at(m_mp);
if (m_pgroupRoot == pgroup)
{
at.Os() << std::endl << "ROOT ";
os << std::endl << "ROOT ";
}
pgroup->OsPrint(at.Os());
pgroup->OsPrint(os);
pgroup = m_listGroups.Next(pgroup);
GPOS_CHECK_ABORT;
......
......@@ -60,70 +60,29 @@ public:
void
Push(T *elem)
{
GPOS_ASSERT(NULL != elem);
GPOS_ASSERT(m_list.First() != elem);
SLink &link = m_list.Link(elem);
#ifdef GPOS_DEBUG
void *next_head = link.m_next;
#endif // GPOS_DEBUG
GPOS_ASSERT(NULL == link.m_next);
T *head = m_list.First();
GPOS_ASSERT(elem != head && "Element is already inserted");
GPOS_ASSERT(next_head == link.m_next &&
"Element is concurrently accessed");
// set current head as next element
link.m_next = head;
#ifdef GPOS_DEBUG
next_head = link.m_next;
#endif // GPOS_DEBUG
// set element as head
GPOS_ASSERT(m_list.m_head == head);
m_list.m_head = elem;
m_list.Prepend(elem);
}
// remove element from the head of the list;
T *
Pop()
{
T *old_head = NULL;
// get current head
old_head = m_list.First();
if (NULL != old_head)
{
// second element becomes the new head
SLink &link = m_list.Link(old_head);
T *new_head = static_cast<T *>(link.m_next);
GPOS_ASSERT(m_list.m_head == old_head);
m_list.m_head = new_head;
// reset link
link.m_next = NULL;
}
return old_head;
if (!m_list.IsEmpty())
return m_list.RemoveHead();
return NULL;
}
// get first element
T *
PtFirst()
PtFirst() const
{
m_list.m_tail = m_list.m_head;
return m_list.First();
}
// get next element
T *
Next(T *elem)
Next(T *elem) const
{
m_list.m_tail = m_list.m_head;
return m_list.Next(elem);
}
......@@ -139,9 +98,8 @@ public:
// lookup a given element in the stack
// this works only when no elements are removed
GPOS_RESULT
Find(T *elem)
Find(T *elem) const
{
m_list.m_tail = m_list.m_head;
return m_list.Find(elem);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册