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 
2 // Copyright (c) 2009-2014 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 public:
18  typedef boost::shared_ptr<TYPE> localDataPtr;
20 
23  }
24 
25 public:
26  localDataPtr get() {
27  SyncLock syncLock(this);
29  if (local != localData.end()) {
30  return local->second;
31  }
32  localDataPtr initial(initialValue());
33  if (initial) {
35  }
36  return initial;
37  }
38 
39  void set(const localDataPtr& data) {
40  SyncLock syncLock(this);
42  }
43 
44  void close() {
45  SyncLock syncLock(this);
47  }
48 
49 protected:
51 
53  return localDataPtr(); // override
54  }
55 };
56 
57 }
58 
59 #endif

clucene.sourceforge.net