MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
trp_client.hpp
1 /*
2  Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef trp_client_hpp
19 #define trp_client_hpp
20 
21 #include <ndb_global.h>
22 #include <NdbCondition.h>
23 
24 struct trp_node;
25 class NdbApiSignal;
26 struct LinearSectionPtr;
27 struct GenericSectionPtr;
28 
30 {
31  friend class TransporterFacade;
32 public:
33  trp_client();
34  virtual ~trp_client();
35 
36  virtual void trp_deliver_signal(const NdbApiSignal *,
37  const LinearSectionPtr ptr[3]) = 0;
38 
39  Uint32 open(class TransporterFacade*, int blockNo = -1);
40  void close();
41 
42  void start_poll();
43  void do_poll(Uint32);
44  void complete_poll();
45  void wakeup();
46 
47  void do_forceSend(int val = 1);
48 
49  int raw_sendSignal(const NdbApiSignal*, Uint32 nodeId);
50  int raw_sendSignal(const NdbApiSignal*, Uint32 nodeId,
51  const LinearSectionPtr ptr[3], Uint32 secs);
52  int raw_sendSignal(const NdbApiSignal*, Uint32 nodeId,
53  const GenericSectionPtr ptr[3], Uint32 secs);
54  int raw_sendFragmentedSignal(const NdbApiSignal*, Uint32 nodeId,
55  const LinearSectionPtr ptr[3], Uint32 secs);
56  int raw_sendFragmentedSignal(const NdbApiSignal*, Uint32 nodeId,
57  const GenericSectionPtr ptr[3], Uint32 secs);
58 
59  const trp_node & getNodeInfo(Uint32 i) const;
60 
61  virtual void recordWaitTimeNanos(Uint64 nanos)
62  {};
63 
64  void lock();
65  void unlock();
66 
67  Uint32 getOwnNodeId() const;
68 
74  int safe_sendSignal(const NdbApiSignal*, Uint32 nodeId);
75 
76 private:
77  Uint32 m_blockNo;
78  TransporterFacade * m_facade;
79 
83  struct PollQueue
84  {
85  bool m_locked;
86  bool m_poll_owner;
87  bool m_waiting;
88  trp_client *m_prev;
89  trp_client *m_next;
90  NdbCondition * m_condition;
91  } m_poll;
92 };
93 
94 class PollGuard
95 {
96 public:
97  PollGuard(class NdbImpl&);
98  ~PollGuard() { unlock_and_signal(); }
99  int wait_n_unlock(int wait_time, Uint32 nodeId, Uint32 state,
100  bool forceSend= false);
101  int wait_for_input_in_loop(int wait_time, bool forceSend);
102  void wait_for_input(int wait_time);
103  int wait_scan(int wait_time, Uint32 nodeId, bool forceSend);
104  void unlock_and_signal();
105 private:
106  class trp_client* m_clnt;
107  class NdbWaiter *m_waiter;
108 };
109 
110 #include "TransporterFacade.hpp"
111 
112 inline
113 void
114 trp_client::lock()
115 {
116  NdbMutex_Lock(m_facade->theMutexPtr);
117  assert(m_poll.m_locked == false);
118  m_poll.m_locked = true;
119 }
120 
121 inline
122 void
123 trp_client::unlock()
124 {
125  assert(m_poll.m_locked == true);
126  m_poll.m_locked = false;
127  NdbMutex_Unlock(m_facade->theMutexPtr);
128 }
129 
130 inline
131 void
132 trp_client::wakeup()
133 {
134  m_facade->wakeup(this);
135 }
136 
137 inline
138 int
139 trp_client::raw_sendSignal(const NdbApiSignal * signal, Uint32 nodeId)
140 {
141  assert(m_poll.m_locked);
142  return m_facade->sendSignal(signal, nodeId);
143 }
144 
145 inline
146 int
147 trp_client::raw_sendSignal(const NdbApiSignal * signal, Uint32 nodeId,
148  const LinearSectionPtr ptr[3], Uint32 secs)
149 {
150  assert(m_poll.m_locked);
151  return m_facade->sendSignal(signal, nodeId, ptr, secs);
152 }
153 
154 inline
155 int
156 trp_client::raw_sendSignal(const NdbApiSignal * signal, Uint32 nodeId,
157  const GenericSectionPtr ptr[3], Uint32 secs)
158 {
159  assert(m_poll.m_locked);
160  return m_facade->sendSignal(signal, nodeId, ptr, secs);
161 }
162 
163 inline
164 int
165 trp_client::raw_sendFragmentedSignal(const NdbApiSignal * signal, Uint32 nodeId,
166  const LinearSectionPtr ptr[3], Uint32 secs)
167 {
168  assert(m_poll.m_locked);
169  return m_facade->sendFragmentedSignal(signal, nodeId, ptr, secs);
170 }
171 
172 inline
173 int
174 trp_client::raw_sendFragmentedSignal(const NdbApiSignal * signal, Uint32 nodeId,
175  const GenericSectionPtr ptr[3],
176  Uint32 secs)
177 {
178  assert(m_poll.m_locked);
179  return m_facade->sendFragmentedSignal(signal, nodeId, ptr, secs);
180 }
181 
182 #endif