Lucene++ - a full-featured, c++ search engine
API Documentation


 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CloseableThreadLocal.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2011 Alan Wright. All rights reserved.
3 // Distributable under the terms of either the Apache License (Version 2.0)
4 // or the GNU Lesser General Public License.
6 
7 #ifndef CLOSEABLETHREADLOCAL_H
8 #define CLOSEABLETHREADLOCAL_H
9 
10 #include "LuceneThread.h"
11 
12 namespace Lucene
13 {
15  template <typename TYPE>
17  {
18  public:
19  typedef boost::shared_ptr<TYPE> localDataPtr;
21 
23  {
25  }
26 
27  public:
29  {
30  SyncLock syncLock(this);
32  if (local != localData.end())
33  return local->second;
34  localDataPtr initial(initialValue());
35  if (initial)
37  return initial;
38  }
39 
40  void set(localDataPtr data)
41  {
42  SyncLock syncLock(this);
44  }
45 
46  void close()
47  {
48  SyncLock syncLock(this);
50  }
51 
52  protected:
54 
56  {
57  return localDataPtr(); // override
58  }
59  };
60 }
61 
62 #endif

clucene.sourceforge.net