summaryrefslogtreecommitdiff
path: root/TAO/utils/logWalker/Thread.cpp
blob: cf15d84f9a22ab80f60963bcca46e6a65cbd0a7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// $Id$

#include "Thread.h"
#include "Invocation.h"
#include "PeerProcess.h"
#include "ace/OS_NS_stdio.h"

#include <stack>

Thread::Thread (long tid, const char *alias)
  : id_(tid),
    alias_ (alias),
    max_depth_ (0),
    encounters_ (0),
    nested_ (0),
    pending_(),
    incoming_(0),
    new_connection_(0),
    giop_target_(0),
    active_handle_ (0)
{
}

void
Thread::pending_peer (PeerProcess *pp)
{
  this->new_connection_ = pp;
}

PeerProcess *
Thread::pending_peer (void) const
{
  return this->new_connection_;
}

void 
Thread::enter_wait (PeerProcess *pp)
{
  this->pending_.push (pp);
  this->encounters_++;
  if (this->pending_.size() > this->max_depth_)
    this->max_depth_ = this->pending_.size();
  if (this->pending_.size() > 1)
    this->nested_++;
}

void 
Thread::exit_wait (PeerProcess *pp, size_t linenum)
{
  PeerProcess *old;
  if (this->pending_.pop(old) == -1)
    return;
  while (old != pp)
    {
      ACE_ERROR ((LM_ERROR, 
                  "Line %d, Ending an invocation to peer %s, but most recent started"
                  " is to peer %s\n", linenum, pp->id(), old->id()));
      //      this->pending_.push(old);
  if (this->pending_.pop(old) == -1)
    return;
    }
}

long 
Thread::max_depth (void) const
{
  return this->max_depth_;
}

long 
Thread::encounters (void) const
{
  return this->encounters_;
}

long 
Thread::id (void) const
{
  return this->id_;
}

const ACE_CString &
Thread::alias (void) const
{
  return this->alias_;
}

void
Thread::incoming_from (PeerProcess  *pp)
{
  this->incoming_ = pp;
}

PeerProcess *
Thread::incoming (void) const
{
  return this->incoming_;
}

void
Thread::active_handle (long handle)
{
  this->active_handle_ = handle;
}

long 
Thread::active_handle (void) const
{
  return this->active_handle_;
}

Invocation::GIOP_Buffer *
Thread::giop_target (void)
{
  return this->giop_target_;
}

void 
Thread::set_giop_target (Invocation::GIOP_Buffer *buffer)
{
  this->giop_target_ = buffer;
}

void
Thread::add_invocation (Invocation *inv)
{
  this->invocations_.insert_tail (inv);
}

void
Thread::dump_detail (ostream &strm)
{
  strm << "   " << this->alias_ << " tid = " << this->id_ 
       << "\t" << this->encounters_ << " encounters";
  if (nested_ > 0)
    strm <<", with " << this->nested_ << " nested upcalls, max depth " 
         << this->max_depth_;
  strm << endl; 
}

void
Thread::dump_invocations (ostream &strm)
{
  strm << "   " << this->alias_ << " handled " << this->invocations_.size() << " invocations" << endl;

  std::stack<Invocation *> nested;
  for (ACE_DLList_Iterator <Invocation> i(this->invocations_);
       !i.done();
       i.advance())
    {
      Invocation *inv;
      i.next(inv);
      int level = 0;
      while (!nested.empty())
        {
          if (nested.top()->contains(inv->req_line()))
            {
              level = nested.size();
              break;
            }
          nested.pop();
        }
      nested.push(inv);

      inv->dump_detail (strm, level, Invocation::Dump_Proc, false);
    }
}