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

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