OpendTect-6_4  6.4
perthreadrepos.h
Go to the documentation of this file.
1 #ifndef perthreadrepos_h
2 #define perthreadrepos_h
3 
4 /*@+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: K. Tingdahl
9  Date: Jan 2014
10  RCS: $Id$
11 ________________________________________________________________________
12 -*/
13 
14 
15 #include "basicmod.h"
16 
17 #include "manobjectset.h"
18 #include "threadlock.h"
19 #include "thread.h"
20 
27 template <class T>
29 {
30 public:
31  T& getObject();
32 
33 private:
37 
38 };
39 
41 
42 #define _mDeclStaticString(nm) \
43  mDefineStaticLocalObject( StaticStringManager, nm##_ssm, ); \
44  BufferString& nm = nm##_ssm.getObject()
45 
46 #ifdef __debug__
47 #define mDeclStaticString(nm) \
48  _mDeclStaticString(nm); \
49  addToStaticStringRepos( &nm )
50 #else
51 #define mDeclStaticString(nm) \
52  _mDeclStaticString(nm)
53 #endif
54 
58 mGlobal(Basic) void addToStaticStringRepos(const OD::String*);
59 mGlobal(Basic) bool isStaticString(const OD::String*);
60 
61 //Implementation
62 
63 template <class T>
64 T& PerThreadObjectRepository<T>::getObject()
65 {
66  const void* threadid = Threads::currentThread();
67  Threads::Locker lock( lock_ );
68  int idx = threadids_.indexOf( threadid );
69  if ( idx<0 )
70  {
71  idx = threadids_.size();
72  threadids_ += threadid;
73  objects_ += new T;
74  }
75 
76  return *objects_[idx];
77 }
78 
79 #endif
Locks the lock, shutting out access from other threads if needed.
Definition: threadlock.h:85
A lock of a type that (hopefully) suits your needs. To use it, you need the Locker class...
Definition: threadlock.h:53
#define mGlobal(module)
Definition: commondefs.h:163
Threads::Lock lock_
Definition: perthreadrepos.h:36
PerThreadObjectRepository< BufferString > StaticStringManager
Definition: perthreadrepos.h:40
bool isStaticString(const OD::String *)
Class that keeps one object per thread. This enables temporary passing of objects (such as strings) w...
Definition: perthreadrepos.h:28
ManagedObjectSet< T > objects_
Definition: perthreadrepos.h:34
void addToStaticStringRepos(const OD::String *)
OpendTect.
Definition: commontypes.h:29
ObjectSet< const void > threadids_
Definition: perthreadrepos.h:35
#define mClass(module)
Definition: commondefs.h:164
const void * currentThread()
ObjectSet where the objects contained are owned by this set.
Definition: manobjectset.h:23

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019