File: tracedthread.h

package info (click to toggle)
omniorb-dfsg 4.3.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,172 kB
  • sloc: cpp: 115,843; python: 24,962; ansic: 13,414; sh: 2,665; makefile: 40
file content (354 lines) | stat: -rw-r--r-- 10,459 bytes parent folder | download | duplicates (2)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// -*- Mode: C++; -*-
//                            Package   : omniORB2
// tracedthread.h             Created on: 15/6/99
//                            Author    : David Riddoch (djr)
//
//    Copyright (C) 2010-2017 Apasphere Ltd
//    Copyright (C) 1996-1999 AT&T Research Cambridge
//
//    This file is part of the omniORB library.
//
//    The omniORB library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library. If not, see http://www.gnu.org/licenses/
//
//
// Description:
//    omni_thread style mutex and condition variables with checks.
//

#ifndef __OMNI_TRACEDTHREAD_H__
#define __OMNI_TRACEDTHREAD_H__


// Lock tracing is controlled by autoconf, or in the dummy
// omniconfig.h.  You can override it here if you wish.

//#define OMNI_ENABLE_LOCK_TRACES


//////////////////////////////////////////////////////////////////////
// omniORB locks and partial lock order
//
//
// BiDirClientRope::pd_lock
//   Protects bidir state in rope
//   Before omniTransportLock.
//   Before giopServer::pd_lock.
//
// corbaBoa boa_lock
//   Protects BOA refcount, state.
//   Before omni::internalLock.
//   Before omniObjAdapter oa_lock.
//
// corbaOrb orb_lock
//   Protects CORBA::ORB existence and state.
//   Synchronises ORB::run().
//   Held while calling module attach() and detach().
//   Before omniTransportLock.
//   Before omni::poRcLock.
//
// giopServer::pd_lock
//   Protects server state
//   Before omniTransportLock.
//   Before SocketCollection::pd_collection_lock.
//
// omni::internalLock
//   Protects many parts of omniORB internal state including object table.
//   Before omniServantActivatorTaskQueue::pd_queue_lock.
//   Before omni::objref_rc_lock.
//   Before omniIOR::lock
//
// omniServantActivatorTaskQueue::pd_task_lock
//   Serialises calls to ServantActivator methods.
//   Before omni::internalLock.
//   Before omniObjAdapter::sd_detachedObjectLock.
//   Calls into application-provided incarnate / etherealize.
//
// omniTransportLock
//   Protects connection state, ropes, strands.
//   Before SocketCollection::pd_collection_lock.
//
// omniObjAdapter oa_lock
//   Protects object adapters, incoming endpoints.
//   Before giopServer::pd_lock.
//
// omniObjAdapter::sd_detachedObjectLock
//   Handles count of detached objects in object adapter.
//   After all other locks, but caller should not hold omni::internalLock.
//
// omniOrbPOA::pd_lock
//   Protects POA's state.
//   Before omni::internalLock.
//   Before omni::poRcLock.
//
// poa poa_lock
//   Protects collection of POAs.
//   Before omniOrbPOA::pd_lock.
//   Before omniObjAdapter oa_lock.
//   Before poamanager pm_lock.
//   Before omni::poRcLock.
//
// poamanager pm_lock
//   Protects POAManager state.
//   Before omni::poRcLock.
//
// sslActiveCollection::pd_lock
//   Protects socket count in sslActiveCollection.
//   Before SocketCollection::pd_collection_lock
//
// tcpActiveCollection::pd_lock
//   Protects socket count in tcpActiveCollection.
//   Before SocketCollection::pd_collection_lock
//
// unixActiveCollection::pd_lock
//   Protects socket count in unixActiveCollection.
//   Before SocketCollection::pd_collection_lock
//
//   
//////////////////////////////////////////////////////////////////////
//
// Locks that are after all others in the partial order. No locks are
// acquired while holding these; lock ordering above does not
// necessarily list these.
//
// anyLock
//   Protects pointers inside Any.
//
// ContextImpl::pd_lock
//   Protects Context.
//
// DynAnyImplBase::refCountLock
//   Protects DynAny implementation ref count and existence.
//
// giopStream::dumpbuf::lock
//   Ensures only one thread is dumping a buffer at a time.
//
// httpCrypto::httpCryptoManager_AES_RSA_impl::pd_lock
//   Protects state of crypto manager.
//
// initRefs ba_lock
//   Protects bootstrap agent.
//
// initRefs sl_lock
//   Protects lists of initial reference services.
//
// libcWrapper rand_lock
//   Serialises call to rand() on platforms without rand_r().
//
// omni::objref_rc_lock
//   Protects normal object reference refcounts.
//
// omni::poRcLock
//   Pseudo object reference count lock.
//
// omniAsyncCallDescriptor::sd_lock
//   Protects state of async calls.
//
// omniAsyncInvoker::pd_lock
//   Protects invoker state.
//
// omniCompressionManager::pd_lock
//   Protects omniCompressionManager refcount.
//
// omniExHandlers::TableLock
//   Protects omniExHandlers::Table.
//
// omniInternal nil_ref_lock
//   Protects creation of nil objref singletons.
//
// omniIOR::lock
//   Protects omniIOR refcount and IORInfo pointer.
//
// omniOrbPOA::pd_main_thread_sync.mu
//   Used in Main Thread dispatch.
//
// omniServantActivatorTaskQueue::pd_queue_lock
//   Protects ServantActivator queue.
//
// orbMultiRequest::q_lock
//   Protects queue for multiple request handling.
//
// poa generateUniqueId lock
//   Protects id generation.
// 
// poa RemoveRefTask::pd_mu
//   Used to remove servant reference from separate thread in main thread POAs.
//
// proxyObjectFactory::ofl_mutex
//   Protects proxyObjectFactory table.
//
// Scavenger::mutex
//   Protects lifetime of the connection scavenger.
//
// SocketCollection::pd_collection_lock
//   Protects sets of sockets.
//
// TypeCode aliasExpandedTc_lock
//   Protects TypeCode's alias expanded version.
//
// TypeCode::refcount_lock
//   Protects reference count and internal structure of TypeCodes.
//
// valueFactoryTableTracker::vf_lock
//   Protects valuefactory table.
//
// zlibCompressorFactory::pd_lock
//   Protects zlibCompressorFactory refcount.
//
// zlibCompressor::pd_lock
//   Protects zlibCompressor refcount.
//


//////////////////////////////////////////////////////////////////////
////////////////////////// omni_tracedmutex //////////////////////////
//////////////////////////////////////////////////////////////////////

#ifndef OMNI_ENABLE_LOCK_TRACES

#define ASSERT_OMNI_TRACEDMUTEX_HELD(m, yes)

class omni_tracedmutex : public omni_mutex {
public:
  inline omni_tracedmutex(const char* /*name*/=0) : omni_mutex() {}
};

typedef omni_mutex_lock omni_tracedmutex_lock;

class omni_tracedcondition : public omni_condition {
public:
  inline omni_tracedcondition(omni_tracedmutex* m, const char* /*name*/=0)
    : omni_condition(m) {}
};

#else

class omni_tracedcondition;


class omni_tracedmutex {
public:
  omni_tracedmutex(const char* name=0);
  ~omni_tracedmutex();

  void lock();
  void unlock();
  inline void acquire(void) { lock();   }
  inline void release(void) { unlock(); }

  void assert_held(const char* file, int line, int yes);

private:
  friend class omni_tracedcondition;

  omni_tracedmutex(const omni_tracedmutex&);
  omni_tracedmutex& operator=(const omni_tracedmutex&);

  omni_mutex     pd_lock;    // protects other members
  omni_condition pd_cond;    // so can wait for mutex to unlock
  omni_thread*   pd_holder;  // the thread holding pd_m, or 0
  int            pd_n_conds; // number of dependent condition vars
  int            pd_deleted; // set true on deletion, may catch later use
  char*          pd_logname; // name to use for logging
};

//////////////////////////////////////////////////////////////////////
//////////////////////// omni_tracedcondition ////////////////////////
//////////////////////////////////////////////////////////////////////

class omni_tracedcondition {
public:
  omni_tracedcondition(omni_tracedmutex* m, const char* name = 0);
  ~omni_tracedcondition();

  void wait();
  int timedwait(unsigned long secs, unsigned long nanosecs = 0);
  inline int timedwait(const omni_time_t& t) { return timedwait(t.s, t.ns); }
  void signal();
  void broadcast();

private:
  omni_tracedcondition(const omni_tracedcondition&);
  omni_tracedcondition& operator=(const omni_tracedcondition&);

  omni_tracedmutex& pd_mutex;
  omni_condition    pd_cond;
  int               pd_n_waiters;
  int               pd_deleted;
  char*             pd_logname;
};

//////////////////////////////////////////////////////////////////////
//////////////////////// omni_tracedmutex_lock ///////////////////////
//////////////////////////////////////////////////////////////////////

class omni_tracedmutex_lock {
public:
  inline omni_tracedmutex_lock(omni_tracedmutex& m) :pd_m(m) { m.lock(); }
  inline ~omni_tracedmutex_lock() { pd_m.unlock(); }

private:
  omni_tracedmutex_lock(const omni_tracedmutex_lock&);
  omni_tracedmutex_lock& operator = (const omni_tracedmutex_lock&);

  omni_tracedmutex& pd_m;
};


#define ASSERT_OMNI_TRACEDMUTEX_HELD(m, yes)  \
  (m).assert_held(__FILE__, __LINE__, (yes))

// #ifndef OMNI_ENABLE_LOCK_TRACES
#endif


//////////////////////////////////////////////////////////////////////
///////////////////////// omni_optional_lock /////////////////////////
//////////////////////////////////////////////////////////////////////

class omni_optional_lock {
public:
  inline omni_optional_lock(omni_tracedmutex& m, int locked,
			    int locked_on_exit)
    : pd_locked(locked_on_exit), pd_m(m)
    { if( !locked ) pd_m.lock(); }

  inline ~omni_optional_lock() { if( !pd_locked )  pd_m.unlock(); }

private:
  omni_optional_lock(const omni_optional_lock&);
  omni_optional_lock& operator = (const omni_optional_lock&);

  int               pd_locked;
  omni_tracedmutex& pd_m;
};


//////////////////////////////////////////////////////////////////////
//////////////////////// omni_tracedmutex_unlock /////////////////////
//////////////////////////////////////////////////////////////////////

class omni_tracedmutex_unlock {
public:
  inline omni_tracedmutex_unlock(omni_tracedmutex& m) : pd_m(m) { m.unlock(); }
  inline ~omni_tracedmutex_unlock() { pd_m.lock(); }

private:
  omni_tracedmutex_unlock(const omni_tracedmutex_unlock&);
  omni_tracedmutex_unlock& operator=(const omni_tracedmutex_unlock&);

  omni_tracedmutex& pd_m;
};


#endif  // __OMNITRACEDTHREAD_H__